First Testable Version

This commit is contained in:
Jonathan Jenne
2021-08-27 15:20:35 +02:00
parent b99627359a
commit f45540a283
14 changed files with 612 additions and 141 deletions

View File

@@ -38,26 +38,59 @@ Namespace Winline
Dim oWS As Config.WebServiceConfig = Config.Webservice
' --- Get and create path for request/response files
Dim oBaseFileName As String = GetBaseFilenameForRequest()
Dim oPath As String = GetBaseWebServicePath()
If IO.Directory.Exists(oPath) = False Then
IO.Directory.CreateDirectory(oPath)
End If
' --- Build all teh filenamez and pathz
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)
' 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
Dim oXmlString = SerializeOrder(oOrderOutput, oBaseFileName)
Dim oReplacedXmlString = oXmlString.Replace("&", "").Replace("ß", "ss")
'Dim oEscapedString = Uri.EscapeUriString(oXmlString)
Dim oOutputFilePath = SerializeOrder(oOrderOutput, oFileName)
' --- Copy file to Winline Import Directory
Try
IO.File.Copy(oOutputFilePath, oImportAbsoluteFilePath, True)
Catch ex As Exception
Logger.Error(ex)
Throw ex
End Try
' --- Prepare URL and HTTP Client
Dim oURL As String = $"{oWS.BaseUrl}/ewlservice/import?User={oWS.Username}&Password={oWS.Password}&Company={pDocument.Mandator}&Type=30&Vorlage=EXIM-VRG_orders&ActionCode=1&Byref=0&Data={oXmlString}"
Dim oTemplateType = 30
Dim oTemplateName = "EXIM-VRG_orders"
' 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
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)
' --- Bring the action!
Try
Dim oResponse As HttpResponseMessage = Await oClient.PostAsync(New Uri(oURL), New StringContent(String.Empty))
Dim oResponse As HttpResponseMessage = Await oClient.GetAsync(oURL)
Await HandleResponse(oResponse, oPath, oBaseFileName)
Return True
@@ -83,12 +116,23 @@ Namespace Winline
Using oStream As New IO.MemoryStream(oBytes)
Dim oResponseObject As Schemas.MESOWebServiceResult = oSerializer.Deserialize(oStream)
For Each oDetails As Schemas.MESOWebServiceResultResultDetails In oResponseObject.ResultDetails
If oDetails.Success = True Then
Logger.Info("KeyValue: [{0}]", oDetails.KeyValue)
Logger.Info("VoucherNumber: [{0}]", oDetails.VoucherNumber)
Else
Logger.Warn("ErrorCode: [{0}]", oDetails.ErrorCode)
Logger.Warn("ErrorText: [{0}]", oDetails.ErrorText)
End If
Next
If oResponseObject.OverallSuccess = False Then
Throw New ApplicationException(oResponseObject.ResultDetails.ErrorText)
Throw New ApplicationException("Request to Webservice was unsuccessful. Please check the logs.")
End If
End Using
Case "text/plain"
Case "text/html"
WriteResponseFile(pPath, pBaseFileNAme, oResponseBody, "txt")
Throw New ApplicationException(oResponseBody)
@@ -129,23 +173,16 @@ Namespace Winline
Return oResult
End Function
Private Function SerializeOrder(pData As Schemas.Orders.Output.MESOWebService, pBaseFileName As String) As String
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 oRequestFileName As String = GetXmlFilenameWithSuffix(pBaseFileName, "Request", "xml")
Dim oFilePath As String = IO.Path.Combine(oPath, oRequestFileName)
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 oStringWriter As New IO.StringWriter()
Using oXmlWriter = XmlWriter.Create(oStringWriter, New XmlWriterSettings With {.Indent = False})
oSerializer.Serialize(oXmlWriter, pData)
Return oStringWriter.ToString()
End Using
End Using
Return oFilePath
End Function
Private Function GetBaseWebServicePath() As String
@@ -160,6 +197,23 @@ Namespace Winline
Return $"{pBaseString}-{pSuffix}.{pExtension}"
End Function
Private Function GetDateSubDirectoryPath(pBasePath As String)
Dim oDirectoryPath As String = Now.ToString("yyyy\\MM\\dd")
Dim oFullPath As String = IO.Path.Combine(pBasePath, oDirectoryPath)
If IO.Directory.Exists(oFullPath) = False Then
Try
IO.Directory.CreateDirectory(oFullPath)
Return oFullPath
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
Else
Return oFullPath
End If
End Function
End Class
End Namespace