directories per template, export tweaks
This commit is contained in:
@@ -4,6 +4,7 @@ Imports System.Xml
|
||||
Imports DigitalData.Modules.Filesystem
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports MultiTool.Shared.Documents
|
||||
Imports MultiTool.Shared.Templates
|
||||
Imports MultiTool.Shared.Templates.GeneralConfig
|
||||
Imports MultiTool.Shared.Winline.Entities
|
||||
|
||||
@@ -13,16 +14,16 @@ Namespace Winline
|
||||
|
||||
Private ReadOnly Config As WebServiceConfig
|
||||
Private ReadOnly Serializer As Serializer
|
||||
Private ReadOnly OutputDirectory As String
|
||||
Private ReadOnly GeneralConfig As GeneralConfig
|
||||
Private ReadOnly FileEx As File
|
||||
|
||||
Public Event WebServiceProgress As EventHandler(Of String)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pWebserviceConfig As WebServiceConfig, pOutputDirectoryPath As String)
|
||||
Public Sub New(pLogConfig As LogConfig, pWebserviceConfig As WebServiceConfig, pGeneralConfig As GeneralConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
Serializer = New Serializer(pLogConfig)
|
||||
Config = pWebserviceConfig
|
||||
OutputDirectory = pOutputDirectoryPath
|
||||
GeneralConfig = pGeneralConfig
|
||||
FileEx = New DigitalData.Modules.Filesystem.File(LogConfig)
|
||||
End Sub
|
||||
|
||||
@@ -30,13 +31,10 @@ Namespace Winline
|
||||
RaiseEvent WebServiceProgress(Me, pMessage)
|
||||
End Sub
|
||||
|
||||
Public Async Function TransferDocumentToWinline(pDocument As Documents.Document, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean)
|
||||
Public Async Function TransferDocumentToWinline(pDocument As Documents.Document, pTemplate As Template, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean)
|
||||
Dim oBytes As Byte() = GetBytesFromDocument(pDocument)
|
||||
Dim oWS = Config
|
||||
|
||||
' --- Get and create path for request/response files
|
||||
Dim oOutputDirectory = FileEx.GetDateDirectory(OutputDirectory)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Einstellungen laden")
|
||||
|
||||
' --- Build all teh filenamez and pathz
|
||||
@@ -44,22 +42,24 @@ Namespace Winline
|
||||
Dim oBaseFileName As String = FileEx.GetDateTimeString()
|
||||
Dim oFileName = FileEx.GetFilenameWithSuffix(oBaseFileName, "Request", "xml")
|
||||
|
||||
' --- Get and create path for request/response files
|
||||
Dim oOutputDirectory = FileEx.GetDateDirectory(pTemplate.OutputWebserviceDirectory)
|
||||
|
||||
' Relative Path for Webservice Call
|
||||
Dim oImportRelativeFilePath = IO.Path.Combine(FileEx.GetDateDirectory(oWS.ImportRelativePath), oFileName)
|
||||
|
||||
' Absolute Path to copy Request file
|
||||
Dim oImportAbsolutePath = IO.Path.Combine(oWS.ImportBasePath, oWS.ImportRelativePath)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(FileEx.GetDateDirectory(oImportAbsolutePath), oFileName)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(oWS.ImportBasePath, FileEx.GetDateDirectory(oWS.ImportRelativePath), oFileName)
|
||||
|
||||
' --- Serialize Data into XML string
|
||||
' Output path
|
||||
Dim oOutputFilePath = IO.Path.Combine(oOutputDirectory, oFileName)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Dateien schreiben")
|
||||
|
||||
Dim oOutputFilePath = IO.Path.Combine(oOutputDirectory, oFileName)
|
||||
' --- Serialize Data into XML string
|
||||
IO.File.WriteAllBytes(oOutputFilePath, oBytes)
|
||||
|
||||
' --- Copy file to Winline Import Directory
|
||||
|
||||
Try
|
||||
IO.File.Copy(oOutputFilePath, oImportAbsoluteFilePath, True)
|
||||
Catch ex As Exception
|
||||
@@ -94,7 +94,7 @@ Namespace Winline
|
||||
' --- Bring the action!
|
||||
Try
|
||||
Dim oResponse As HttpResponseMessage = Await oClient.GetAsync(oURL)
|
||||
Await HandleResponse(oResponse, oOutputDirectory, oBaseFileName)
|
||||
Await HandleImportResponse(oResponse, pTemplate, oBaseFileName)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
@@ -105,11 +105,60 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Async Function ExportDocumentFromWinline() As Task
|
||||
'TODO: Implement export call to winline
|
||||
Async Function ExportDocumentFromWinline(pDocument As Entities.Document, pTemplate As Template, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean)
|
||||
Dim oWS = Config
|
||||
|
||||
' --- Build all teh filenamez and pathz
|
||||
|
||||
Dim oBaseFileName As String = FileEx.GetDateTimeString()
|
||||
Dim oFileName = FileEx.GetFilenameWithSuffix(oBaseFileName, "Request", "xml")
|
||||
|
||||
' Absolute Path to copy Request file
|
||||
Dim oImportAbsolutePath = IO.Path.Combine(oWS.ImportBasePath, oWS.ImportRelativePath)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(FileEx.GetDateDirectory(oImportAbsolutePath), oFileName)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Dateien schreiben")
|
||||
|
||||
' --- Prepare URL and HTTP Client
|
||||
Dim oTemplateType = 30
|
||||
Dim oTemplateName = pDocument.Schema.Name
|
||||
Dim oKey = $"{pDocument.Account.Id}-{pDocument.RunningNumber}"
|
||||
|
||||
' ActionCode: Should this be a test or not?
|
||||
' 0 = Test call
|
||||
' 1 = Real call
|
||||
Dim oActionCode = 1
|
||||
If pIsTest = True Then
|
||||
oActionCode = 0
|
||||
End If
|
||||
|
||||
' Byref: Should data be supplied as file or as string?
|
||||
' 0 = As String
|
||||
' 1 = As File (relative to Winline Server directory)
|
||||
Dim oByref = 0
|
||||
|
||||
Dim oURL As String = $"{oWS.BaseUrl}/ewlservice/export?User={oWS.Username}&Password={oWS.Password}&Company={pMandator.Id}&Type={oTemplateType}&Vorlage={oTemplateName}&ActionCode={oActionCode}&Key={oKey}"
|
||||
Dim oClient As New HttpClient()
|
||||
|
||||
Logger.Info("Creating HTTP Request to [{0}]", oWS.BaseUrl)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Anfrage absenden")
|
||||
|
||||
' --- Bring the action!
|
||||
Try
|
||||
Dim oResponse As HttpResponseMessage = Await oClient.GetAsync(oURL)
|
||||
Await HandleExportResponse(oResponse, pTemplate, oBaseFileName)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
Finally
|
||||
oClient.Dispose()
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Async Function HandleResponse(pResponse As HttpResponseMessage, pOutputPath As String, pBaseFileNAme As String) As Task
|
||||
Private Async Function HandleExportResponse(pResponse As HttpResponseMessage, pTemplate As Template, pBaseFileNAme As String) As Task
|
||||
pResponse.EnsureSuccessStatusCode()
|
||||
Dim oResponseBody As String = Await pResponse.Content.ReadAsStringAsync()
|
||||
Dim oContentType = pResponse.Content.Headers.ContentType.MediaType
|
||||
@@ -119,7 +168,31 @@ Namespace Winline
|
||||
|
||||
Select Case oContentType
|
||||
Case "text/xml"
|
||||
WriteResponseFile(pOutputPath, pBaseFileNAme, oResponseBody, "xml")
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, pBaseFileNAme, oResponseBody, "xml")
|
||||
WriteResponseFile(pTemplate.OutputXmlFileDirectory, pBaseFileNAme, oResponseBody, "xml")
|
||||
WriteResponseFile(FileEx.GetDateDirectory(pTemplate.ArchiveDirectory), pBaseFileNAme, oResponseBody, "xml")
|
||||
|
||||
Case "text/html"
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, pBaseFileNAme, oResponseBody, "txt")
|
||||
|
||||
Throw New ApplicationException(oResponseBody)
|
||||
|
||||
Case Else
|
||||
Throw New ApplicationException(oResponseBody)
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Private Async Function HandleImportResponse(pResponse As HttpResponseMessage, pTemplate As Template, pBaseFileNAme As String) As Task
|
||||
pResponse.EnsureSuccessStatusCode()
|
||||
Dim oResponseBody As String = Await pResponse.Content.ReadAsStringAsync()
|
||||
Dim oContentType = pResponse.Content.Headers.ContentType.MediaType
|
||||
Dim oSerializer = Serializer.GetSerializer(GetType(Templates.Entities.MESOWebServiceResult))
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Antwort verarbeiten")
|
||||
|
||||
Select Case oContentType
|
||||
Case "text/xml"
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, pBaseFileNAme, oResponseBody, "xml")
|
||||
|
||||
Dim oBytes As Byte() = Encoding.UTF8.GetBytes(oResponseBody)
|
||||
Using oStream As New IO.MemoryStream(oBytes)
|
||||
@@ -148,7 +221,7 @@ Namespace Winline
|
||||
End Using
|
||||
|
||||
Case "text/html"
|
||||
WriteResponseFile(pOutputPath, pBaseFileNAme, oResponseBody, "txt")
|
||||
WriteResponseFile(pTemplate.OutputWebserviceDirectory, pBaseFileNAme, oResponseBody, "txt")
|
||||
|
||||
Throw New ApplicationException(oResponseBody)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user