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

@@ -10,6 +10,8 @@
Public Property BaseUrl As String = "http://127.0.0.1/EWL"
Public Property Username As String = "Username"
Public Property Password As String = "Password"
Public Property ImportBasePath As String = ""
Public Property ImportRelativePath As String = ""
End Class
Public Class MandatorConfig

View File

@@ -121,6 +121,7 @@
<Compile Include="Serializer.vb" />
<Compile Include="Winline\Entities\Account.vb" />
<Compile Include="Winline\Data.vb" />
<Compile Include="Winline\Entities\Contact.vb" />
<Compile Include="Winline\Entities\DocumentKind.vb" />
<Compile Include="Winline\Entities\Mandator.vb" />
<Compile Include="Winline\WebService.vb" />

View File

@@ -1,16 +1,26 @@
Namespace Schemas.Orders
Public Class Helpers
Public Shared Function GetOrderHead(pData As Input.MESOWebService) As Input.MESOWebServiceEXIMVRG_ordersT025
Dim oHead As Input.MESOWebServiceEXIMVRG_ordersT025 = pData.Items.
Where(Function(i) TypeOf i Is Input.MESOWebServiceEXIMVRG_ordersT025).
Public Shared Function GetOrderHead(Of T)(pData As IMesoWebservice) As T
Dim oHead As T = pData.Items.
Where(Function(i) TypeOf i Is T).
FirstOrDefault()
Return oHead
End Function
Public Shared Function GetOrderPositions(pData As Input.MESOWebService) As List(Of Input.MESOWebServiceEXIMVRG_ordersT026)
Dim oPositions As List(Of Input.MESOWebServiceEXIMVRG_ordersT026) = pData.Items.
Where(Function(i) TypeOf i Is Input.MESOWebServiceEXIMVRG_ordersT026).
Select(Of Input.MESOWebServiceEXIMVRG_ordersT026)(Function(i) i).
Public Shared Sub SetOrderHead(Of T)(pData As IMesoWebservice, pUpdateFunction As Action(Of T))
Dim oHead As T = pData.Items.
Where(Function(i) TypeOf i Is T).
SetValue(Sub(pObject As T)
pUpdateFunction(pObject)
End Sub).
FirstOrDefault()
End Sub
Public Shared Function GetOrderPositions(Of T)(pData As IMesoWebservice) As List(Of T)
Dim oPositions As List(Of T) = pData.Items.
Where(Function(i) TypeOf i Is T).
Select(Of T)(Function(i) i).
ToList()
Return oPositions
End Function

View File

@@ -29,7 +29,7 @@ Namespace Schemas
Private overallSuccessField As Boolean
Private resultDetailsField As MESOWebServiceResultResultDetails
Private resultDetailsField As MESOWebServiceResultResultDetails()
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
@@ -44,7 +44,7 @@ Namespace Schemas
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute("ResultDetails", Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
Public Property ResultDetails() As MESOWebServiceResultResultDetails
Public Property ResultDetails() As MESOWebServiceResultResultDetails()
Get
Return Me.resultDetailsField
End Get
@@ -68,6 +68,10 @@ Namespace Schemas
Private errorTextField As String
Private keyValueField As String
Private voucherNumberField As String
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
Public Property Success() As Boolean
@@ -100,5 +104,27 @@ Namespace Schemas
Me.errorTextField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
Public Property KeyValue() As String
Get
Return Me.keyValueField
End Get
Set
Me.keyValueField = Value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlElementAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified)>
Public Property VoucherNumber() As String
Get
Return Me.voucherNumberField
End Get
Set
Me.voucherNumberField = Value
End Set
End Property
End Class
End Namespace

View File

@@ -25,6 +25,10 @@ Namespace Winline
Public Const V50_ACCOUNTNUMBER = "c002"
Public Const V50_ACCOUNTNAME = "c003"
Public Const T45_KEY = "c000"
Public Const T45_NAME = "c001"
Public Const T45_CONTACTNUMBER = "c063"
Public Const V05_ACCOUNTID = "c002"
Public Const V05_ACCOUNTNAME = "c003"
@@ -258,6 +262,42 @@ Namespace Winline
End Try
End Function
Public Function GetContacts(pAccountNumber As String, pMandator As Mandator) As List(Of Contact)
Try
Dim oContacts As New List(Of Contact)
Dim oYear As Integer = GetWinLineYear()
Dim oSQL As String = $"
SELECT
[c000], -- Key
[c001], -- Name
[c063] -- Kontaktnummer
FROM [{pMandator.Database}].[dbo].[t045]
WHERE [c063] LIKE '{pAccountNumber}-%'
AND [mesocomp] = '{pMandator.Id}' AND [mesoyear] = {oYear}"
Dim oTable As DataTable = Database.GetDatatable(oSQL)
' Contact not found in this Mandator, continue to next one
If oTable.Rows.Count = 0 Then
Logger.Debug("Contact for Account [{0}] was not found in Mandator: [{1}]", pAccountNumber, pMandator.Id)
Return Nothing
End If
For Each oRow In oTable.Rows
oContacts.Add(New Contact With {
.Id = Utils.NotNull(oRow.Item(T45_KEY), Nothing),
.Name = Utils.NotNull(oRow.Item(T45_NAME), Nothing),
.Number = Utils.NotNull(oRow.Item(T45_CONTACTNUMBER), Nothing)
})
Next
Return oContacts
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function
Public Function GetReplacementArticleNumber(pArticleNumber As String, pMandator As Mandator)
Try
Dim oYear As Integer = GetWinLineYear()
@@ -295,6 +335,7 @@ Namespace Winline
Return GetReplacementArticleNumber(oReplacementArticleNumber, pMandator)
Catch ex As Exception
Logger.Error(ex)
Return Nothing
End Try
End Function

View File

@@ -0,0 +1,12 @@
Namespace Winline
Public Class Contact
Public Property Id As Integer
Public Property Number As String
Public Property Name As String
Public Overrides Function ToString() As String
Return Name
End Function
End Class
End Namespace

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("&amp;", "").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