First Working Version with New parser
This commit is contained in:
@@ -22,85 +22,85 @@ Namespace Winline
|
||||
FileEx = New File(pLogConfig)
|
||||
Serializer = New Serializer(pLogConfig)
|
||||
Config = pConfig
|
||||
Mapper = MapperFactory.GetMapper()
|
||||
'Mapper = MapperFactory.GetMapper()
|
||||
End Sub
|
||||
|
||||
Public Async Function TransferDocumentToWinLine(pDocument As Document) As Task(Of Boolean)
|
||||
If TypeOf pDocument.Data Is Schemas.Orders.Input.MESOWebService Then
|
||||
Return Await TransferOrderToWinline(pDocument)
|
||||
Else
|
||||
Return False
|
||||
End If
|
||||
End Function
|
||||
'Public Async Function TransferDocumentToWinLine(pDocument As Document) As Task(Of Boolean)
|
||||
' If TypeOf pDocument.Data Is Schemas.Orders.Input.MESOWebService Then
|
||||
' Return Await TransferOrderToWinline(pDocument)
|
||||
' Else
|
||||
' Return False
|
||||
' End If
|
||||
'End Function
|
||||
|
||||
Private Async Function TransferOrderToWinline(pDocument As Document) As Task(Of Boolean)
|
||||
Dim oOrderOutput = TransformOrderToOutput(pDocument.Data)
|
||||
Dim oWS As Config.WebServiceConfig = Config.Webservice
|
||||
'Private Async Function TransferOrderToWinline(pDocument As Document) As Task(Of Boolean)
|
||||
' Dim oOrderOutput = TransformOrderToOutput(pDocument.Data)
|
||||
' Dim oWS As Config.WebServiceConfig = Config.Webservice
|
||||
|
||||
' --- Get and create path for request/response files
|
||||
' ' --- Get and create path for request/response files
|
||||
|
||||
Dim oPath As String = GetBaseWebServicePath()
|
||||
If IO.Directory.Exists(oPath) = False Then
|
||||
IO.Directory.CreateDirectory(oPath)
|
||||
End If
|
||||
' Dim oPath As String = GetBaseWebServicePath()
|
||||
' If IO.Directory.Exists(oPath) = False Then
|
||||
' IO.Directory.CreateDirectory(oPath)
|
||||
' End If
|
||||
|
||||
' --- Build all teh filenamez and pathz
|
||||
' ' --- Build all teh filenamez and pathz
|
||||
|
||||
Dim oBaseFileName As String = GetBaseFilenameForRequest()
|
||||
Dim oFileName = GetXmlFilenameWithSuffix(oBaseFileName, "Request", "xml")
|
||||
' Dim oBaseFileName As String = GetBaseFilenameForRequest()
|
||||
' Dim oFileName = GetXmlFilenameWithSuffix(oBaseFileName, "Request", "xml")
|
||||
|
||||
' Relative Path for Webservice Call
|
||||
Dim oImportRelativeFilePath = IO.Path.Combine(GetDateSubDirectoryPath(Config.Webservice.ImportRelativePath), oFileName)
|
||||
' ' Relative Path for Webservice Call
|
||||
' Dim oImportRelativeFilePath = IO.Path.Combine(GetDateSubDirectoryPath(Config.Webservice.ImportRelativePath), oFileName)
|
||||
|
||||
' Absolute Path to copy Request file
|
||||
Dim oImportAbsolutePath = IO.Path.Combine(Config.Webservice.ImportBasePath, Config.Webservice.ImportRelativePath)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(GetDateSubDirectoryPath(oImportAbsolutePath), oFileName)
|
||||
' ' Absolute Path to copy Request file
|
||||
' Dim oImportAbsolutePath = IO.Path.Combine(Config.Webservice.ImportBasePath, Config.Webservice.ImportRelativePath)
|
||||
' Dim oImportAbsoluteFilePath = IO.Path.Combine(GetDateSubDirectoryPath(oImportAbsolutePath), oFileName)
|
||||
|
||||
' --- Serialize Data into XML string
|
||||
' ' --- Serialize Data into XML string
|
||||
|
||||
Dim oOutputFilePath = SerializeOrder(oOrderOutput, oFileName)
|
||||
' Dim oOutputFilePath = SerializeOrder(oOrderOutput, oFileName)
|
||||
|
||||
' --- Copy file to Winline Import Directory
|
||||
' ' --- Copy file to Winline Import Directory
|
||||
|
||||
Try
|
||||
IO.File.Copy(oOutputFilePath, oImportAbsoluteFilePath, True)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
End Try
|
||||
' Try
|
||||
' IO.File.Copy(oOutputFilePath, oImportAbsoluteFilePath, True)
|
||||
' Catch ex As Exception
|
||||
' Logger.Error(ex)
|
||||
' Throw ex
|
||||
' End Try
|
||||
|
||||
' --- Prepare URL and HTTP Client
|
||||
Dim oTemplateType = 30
|
||||
Dim oTemplateName = "EXIM-VRG_orders"
|
||||
' ' --- Prepare URL and HTTP Client
|
||||
' Dim oTemplateType = 30
|
||||
' Dim oTemplateName = "EXIM-VRG_orders"
|
||||
|
||||
' ActionCode: Should this be a test or not?
|
||||
' 0 = Testcall
|
||||
' 1 = Real call
|
||||
Dim oActionCode = 1
|
||||
' ' ActionCode: Should this be a test or not?
|
||||
' ' 0 = Testcall
|
||||
' ' 1 = Real call
|
||||
' Dim oActionCode = 1
|
||||
|
||||
' Byref: Should data be supplied as file or as string?
|
||||
' 0 = As String
|
||||
' 1 = As File (relative to Winline Server directory)
|
||||
Dim oByref = 1
|
||||
' ' Byref: Should data be supplied as file or as string?
|
||||
' ' 0 = As String
|
||||
' ' 1 = As File (relative to Winline Server directory)
|
||||
' Dim oByref = 1
|
||||
|
||||
Dim oURL As String = $"{oWS.BaseUrl}/ewlservice/import?User={oWS.Username}&Password={oWS.Password}&Company={pDocument.Mandator}&Type={oTemplateType}&Vorlage={oTemplateName}&ActionCode={oActionCode}&Byref={oByref}&Data={oImportRelativeFilePath}"
|
||||
Dim oClient As New HttpClient()
|
||||
' Dim oURL As String = $"{oWS.BaseUrl}/ewlservice/import?User={oWS.Username}&Password={oWS.Password}&Company={pDocument.Mandator}&Type={oTemplateType}&Vorlage={oTemplateName}&ActionCode={oActionCode}&Byref={oByref}&Data={oImportRelativeFilePath}"
|
||||
' Dim oClient As New HttpClient()
|
||||
|
||||
Logger.Info("Creating HTTP Request to [{0}]", oWS.BaseUrl)
|
||||
' Logger.Info("Creating HTTP Request to [{0}]", oWS.BaseUrl)
|
||||
|
||||
' --- Bring the action!
|
||||
Try
|
||||
Dim oResponse As HttpResponseMessage = Await oClient.GetAsync(oURL)
|
||||
Await HandleResponse(oResponse, oPath, oBaseFileName)
|
||||
' ' --- Bring the action!
|
||||
' Try
|
||||
' Dim oResponse As HttpResponseMessage = Await oClient.GetAsync(oURL)
|
||||
' Await HandleResponse(oResponse, oPath, oBaseFileName)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw ex
|
||||
Finally
|
||||
oClient.Dispose()
|
||||
End Try
|
||||
End Function
|
||||
' 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, pPath As String, pBaseFileNAme As String) As Task
|
||||
pResponse.EnsureSuccessStatusCode()
|
||||
@@ -155,35 +155,35 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function TransformOrderToOutput(pData As Schemas.Orders.Input.MESOWebService) As Schemas.Orders.Output.MESOWebService
|
||||
Dim oData As Schemas.Orders.Input.MESOWebService = pData
|
||||
Dim oResult As Schemas.Orders.Output.MESOWebService = Mapper.Map(Of Schemas.Orders.Output.MESOWebService)(oData)
|
||||
'Private Function TransformOrderToOutput(pData As Schemas.Orders.Input.MESOWebService) As Schemas.Orders.Output.MESOWebService
|
||||
' Dim oData As Schemas.Orders.Input.MESOWebService = pData
|
||||
' Dim oResult As Schemas.Orders.Output.MESOWebService = Mapper.Map(Of Schemas.Orders.Output.MESOWebService)(oData)
|
||||
|
||||
Dim oItems = oData.Items.
|
||||
Select(Function(i)
|
||||
If TypeOf i Is Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT025 Then
|
||||
Return Mapper.Map(Of Schemas.Orders.Output.MESOWebServiceEXIMVRG_ordersT025)(i)
|
||||
Else
|
||||
Return Mapper.Map(Of Schemas.Orders.Output.MESOWebServiceEXIMVRG_ordersT026)(i)
|
||||
End If
|
||||
End Function).
|
||||
ToList()
|
||||
' Dim oItems = oData.Items.
|
||||
' Select(Function(i)
|
||||
' If TypeOf i Is Schemas.Orders.Input.MESOWebServiceEXIMVRG_ordersT025 Then
|
||||
' Return Mapper.Map(Of Schemas.Orders.Output.MESOWebServiceEXIMVRG_ordersT025)(i)
|
||||
' Else
|
||||
' Return Mapper.Map(Of Schemas.Orders.Output.MESOWebServiceEXIMVRG_ordersT026)(i)
|
||||
' End If
|
||||
' End Function).
|
||||
' ToList()
|
||||
|
||||
oResult.Items = oItems.ToArray()
|
||||
Return oResult
|
||||
End Function
|
||||
' oResult.Items = oItems.ToArray()
|
||||
' Return oResult
|
||||
'End Function
|
||||
|
||||
Private Function SerializeOrder(pData As Schemas.Orders.Output.MESOWebService, pFileName As String) As String
|
||||
Dim oSerializer = Serializer.GetSerializer(GetType(Schemas.Orders.Output.MESOWebService))
|
||||
Dim oPath As String = GetBaseWebServicePath()
|
||||
Dim oFilePath As String = IO.Path.Combine(oPath, pFileName)
|
||||
'Private Function SerializeOrder(pData As Schemas.Orders.Output.MESOWebService, pFileName As String) As String
|
||||
' Dim oSerializer = Serializer.GetSerializer(GetType(Schemas.Orders.Output.MESOWebService))
|
||||
' Dim oPath As String = GetBaseWebServicePath()
|
||||
' Dim oFilePath As String = IO.Path.Combine(oPath, pFileName)
|
||||
|
||||
Using oWriter = XmlWriter.Create(oFilePath, New XmlWriterSettings With {.Indent = True})
|
||||
oSerializer.Serialize(oWriter, pData)
|
||||
End Using
|
||||
' Using oWriter = XmlWriter.Create(oFilePath, New XmlWriterSettings With {.Indent = True})
|
||||
' oSerializer.Serialize(oWriter, pData)
|
||||
' End Using
|
||||
|
||||
Return oFilePath
|
||||
End Function
|
||||
' Return oFilePath
|
||||
'End Function
|
||||
|
||||
Private Function GetBaseWebServicePath() As String
|
||||
Return IO.Path.Combine(FileEx.GetAppDataPath("Digital Data", "EDI Document Importer"), "WebService")
|
||||
|
||||
Reference in New Issue
Block a user