Export report to Directory
This commit is contained in:
@@ -4,8 +4,8 @@ Public Class BaseClass
|
||||
Public ReadOnly LogConfig As LogConfig
|
||||
Public ReadOnly Logger As Logger
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pLogger As Logger)
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
LogConfig = pLogConfig
|
||||
Logger = pLogger
|
||||
Logger = LogConfig.GetLogger()
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
@@ -23,7 +23,7 @@ Namespace Documents
|
||||
End Structure
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pWinline As WinlineData, pMappingConfig As MappingConfig, pTemplateConfig As TemplateConfig)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger())
|
||||
MyBase.New(pLogConfig)
|
||||
Winline = pWinline
|
||||
MappingConfig = pMappingConfig
|
||||
TemplateConfig = pTemplateConfig
|
||||
@@ -203,7 +203,8 @@ Namespace Documents
|
||||
oFields.Add(oColumn.Name, New DocumentRow.FieldValue With {
|
||||
.DataType = oColumn.Type,
|
||||
.IsRequired = oColumn.IsRequired,
|
||||
.SortKey = oColumn.OrderKey
|
||||
.SortKey = oColumn.OrderKey,
|
||||
.IsVirtual = True
|
||||
})
|
||||
Next
|
||||
|
||||
|
||||
@@ -1,2 +1,36 @@
|
||||
Friend Class Helpers
|
||||
Imports DigitalData.Modules.Logging
|
||||
|
||||
Public Class Helpers
|
||||
Inherits BaseClass
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
MyBase.New(pLogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function GetDateDirectory(pBaseDirectory As String)
|
||||
Dim oDateDirectory = GetDateString()
|
||||
Dim oFinalDirectory As String = IO.Path.Combine(pBaseDirectory, oDateDirectory)
|
||||
|
||||
If IO.Directory.Exists(oFinalDirectory) = False Then
|
||||
Try
|
||||
IO.Directory.CreateDirectory(oFinalDirectory)
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
End Try
|
||||
End If
|
||||
|
||||
Return oFinalDirectory
|
||||
End Function
|
||||
|
||||
Public Function GetDateString() As String
|
||||
Return $"{Now:yyyy\\MM\\dd}"
|
||||
End Function
|
||||
|
||||
Public Function GetDateTimeString() As String
|
||||
Return $"{Now:yyyy-MM-dd_hh-mm-ffff}"
|
||||
End Function
|
||||
|
||||
Public Function GetFilenameWithSuffix(pBaseString As String, pSuffix As String, pExtension As String)
|
||||
Return $"{pBaseString}-{pSuffix}.{pExtension}"
|
||||
End Function
|
||||
End Class
|
||||
|
||||
@@ -4,7 +4,7 @@ Imports DigitalData.Modules.Logging
|
||||
Public Class Serializer
|
||||
Inherits BaseClass
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger())
|
||||
MyBase.New(pLogConfig)
|
||||
End Sub
|
||||
|
||||
Public Function GetSerializer(pSchemaType As Type) As XmlSerializer
|
||||
|
||||
@@ -4,6 +4,18 @@
|
||||
Public Property OutputDirectory As String = ""
|
||||
Public Property TemplateDirectory As String = ""
|
||||
|
||||
Public ReadOnly Property OutputReportDirectory
|
||||
Get
|
||||
Return IO.Path.Combine(OutputDirectory, "Reports")
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public ReadOnly Property OutputWebserviceDirectory
|
||||
Get
|
||||
Return IO.Path.Combine(OutputDirectory, "WebService")
|
||||
End Get
|
||||
End Property
|
||||
|
||||
Public Property Webservice As New WebServiceConfig()
|
||||
Public Property DefaultYearOverride As Integer = 0
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ Namespace Templates
|
||||
Private Const SQL_TBEDI_XML_TEMPLATES = "SELECT * FROM [DD_ECM].[dbo].[TBEDI_XML_TEMPLATES]"
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pMSSQL As MSSQLServer)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger)
|
||||
MyBase.New(pLogConfig)
|
||||
Database = pMSSQL
|
||||
End Sub
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Imports System.Xml
|
||||
Imports System.Net.Http
|
||||
Imports System.Text
|
||||
Imports System.Net.Http
|
||||
Imports System.Xml
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports MultiTool.Shared.Documents
|
||||
Imports MultiTool.Shared.Templates.GeneralConfig
|
||||
@@ -12,15 +12,17 @@ Namespace Winline
|
||||
|
||||
Private ReadOnly Config As WebServiceConfig
|
||||
Private ReadOnly Serializer As Serializer
|
||||
Private ReadOnly AppDataPath As String
|
||||
Private ReadOnly OutputDirectory As String
|
||||
Private ReadOnly Helpers As Helpers
|
||||
|
||||
Public Event WebServiceProgress As EventHandler(Of String)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pWebserviceConfig As WebServiceConfig, pAppDataPath As String)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger())
|
||||
Public Sub New(pLogConfig As LogConfig, pWebserviceConfig As WebServiceConfig, pOutputDirectoryPath As String)
|
||||
MyBase.New(pLogConfig)
|
||||
Helpers = New Helpers(pLogConfig)
|
||||
Serializer = New Serializer(pLogConfig)
|
||||
Config = pWebserviceConfig
|
||||
AppDataPath = pAppDataPath
|
||||
OutputDirectory = pOutputDirectoryPath
|
||||
End Sub
|
||||
|
||||
Public Async Function TransferDocumentToWinline(pDocument As Document, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean)
|
||||
@@ -28,31 +30,27 @@ Namespace Winline
|
||||
Dim oWS = Config
|
||||
|
||||
' --- 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 oOutputDirectory = Helpers.GetDateDirectory(OutputDirectory)
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Einstellungen laden")
|
||||
|
||||
' --- Build all teh filenamez and pathz
|
||||
|
||||
Dim oBaseFileName As String = GetBaseFilenameForRequest()
|
||||
Dim oFileName = GetXmlFilenameWithSuffix(oBaseFileName, "Request", "xml")
|
||||
Dim oBaseFileName As String = Helpers.GetDateTimeString()
|
||||
Dim oFileName = Helpers.GetFilenameWithSuffix(oBaseFileName, "Request", "xml")
|
||||
|
||||
' Relative Path for Webservice Call
|
||||
Dim oImportRelativeFilePath = IO.Path.Combine(GetDateSubDirectoryPath(oWS.ImportRelativePath), oFileName)
|
||||
Dim oImportRelativeFilePath = IO.Path.Combine(Helpers.GetDateDirectory(oWS.ImportRelativePath), oFileName)
|
||||
|
||||
' Absolute Path to copy Request file
|
||||
Dim oImportAbsolutePath = IO.Path.Combine(oWS.ImportBasePath, oWS.ImportRelativePath)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(GetDateSubDirectoryPath(oImportAbsolutePath), oFileName)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(Helpers.GetDateDirectory(oImportAbsolutePath), oFileName)
|
||||
|
||||
' --- Serialize Data into XML string
|
||||
|
||||
RaiseEvent WebServiceProgress(Me, "Dateien schreiben")
|
||||
|
||||
Dim oOutputFilePath = IO.Path.Combine(GetBaseWebServicePath(), oFileName)
|
||||
Dim oOutputFilePath = IO.Path.Combine(oOutputDirectory, oFileName)
|
||||
IO.File.WriteAllBytes(oOutputFilePath, oBytes)
|
||||
|
||||
' --- Copy file to Winline Import Directory
|
||||
@@ -91,7 +89,7 @@ Namespace Winline
|
||||
' --- Bring the action!
|
||||
Try
|
||||
Dim oResponse As HttpResponseMessage = Await oClient.GetAsync(oURL)
|
||||
Await HandleResponse(oResponse, oPath, oBaseFileName)
|
||||
Await HandleResponse(oResponse, oOutputDirectory, oBaseFileName)
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
@@ -102,7 +100,7 @@ Namespace Winline
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Async Function HandleResponse(pResponse As HttpResponseMessage, pPath As String, pBaseFileNAme As String) As Task
|
||||
Private Async Function HandleResponse(pResponse As HttpResponseMessage, pOutputPath As String, pBaseFileNAme As String) As Task
|
||||
pResponse.EnsureSuccessStatusCode()
|
||||
Dim oResponseBody As String = Await pResponse.Content.ReadAsStringAsync()
|
||||
Dim oContentType = pResponse.Content.Headers.ContentType.MediaType
|
||||
@@ -112,7 +110,7 @@ Namespace Winline
|
||||
|
||||
Select Case oContentType
|
||||
Case "text/xml"
|
||||
WriteResponseFile(pPath, pBaseFileNAme, oResponseBody, "xml")
|
||||
WriteResponseFile(pOutputPath, pBaseFileNAme, oResponseBody, "xml")
|
||||
|
||||
Dim oBytes As Byte() = Encoding.UTF8.GetBytes(oResponseBody)
|
||||
Using oStream As New IO.MemoryStream(oBytes)
|
||||
@@ -139,7 +137,7 @@ Namespace Winline
|
||||
End Using
|
||||
|
||||
Case "text/html"
|
||||
WriteResponseFile(pPath, pBaseFileNAme, oResponseBody, "txt")
|
||||
WriteResponseFile(pOutputPath, pBaseFileNAme, oResponseBody, "txt")
|
||||
|
||||
Throw New ApplicationException(oResponseBody)
|
||||
|
||||
@@ -150,7 +148,7 @@ Namespace Winline
|
||||
|
||||
Private Function WriteResponseFile(pPath As String, pBaseFileName As String, pResponseBody As String, pExtension As String)
|
||||
Try
|
||||
Dim oRequestFileName As String = GetXmlFilenameWithSuffix(pBaseFileName, "Response", pExtension)
|
||||
Dim oRequestFileName As String = Helpers.GetFilenameWithSuffix(pBaseFileName, "Response", pExtension)
|
||||
Dim oFilePath As String = IO.Path.Combine(pPath, oRequestFileName)
|
||||
IO.File.WriteAllText(oFilePath, pResponseBody)
|
||||
|
||||
@@ -200,36 +198,6 @@ Namespace Winline
|
||||
Return oStream.ToArray()
|
||||
End Using
|
||||
End Function
|
||||
|
||||
Private Function GetBaseWebServicePath() As String
|
||||
Return IO.Path.Combine(AppDataPath, "WebService")
|
||||
End Function
|
||||
|
||||
Private Function GetBaseFilenameForRequest() As String
|
||||
Return $"{Now:yyyy-MM-dd_hh-mm-ffff}"
|
||||
End Function
|
||||
|
||||
Private Function GetXmlFilenameWithSuffix(pBaseString As String, pSuffix As String, pExtension As String)
|
||||
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
|
||||
@@ -22,7 +22,7 @@ Namespace Winline
|
||||
Public Years As List(Of Integer)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As GeneralConfig, pMappingConfig As MappingConfig, pMandatorConfig As MandatorConfig)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger())
|
||||
MyBase.New(pLogConfig)
|
||||
Database = pDatabase
|
||||
Config = pConfig
|
||||
MandatorConfig = pMandatorConfig
|
||||
@@ -419,14 +419,15 @@ Namespace Winline
|
||||
Dim oArticleNumber As String = ItemEx(oRow, V21_MAINARTICLENUMBER, String.Empty)
|
||||
|
||||
' EAN was found, now we need to check it against the Regex of the current Mandantor, if one exists
|
||||
Dim oMappingConfigItem = MappingConfig.Items.
|
||||
Dim oMappingConfigItems = MappingConfig.Items.
|
||||
Where(Function(item) item.DestinationName = "MANDATOR" And item.DestinationValue = oMandator.Id And item.SourceName = "ARTICLE").
|
||||
SingleOrDefault()
|
||||
|
||||
If oMappingConfigItem IsNot Nothing Then
|
||||
ToList()
|
||||
|
||||
' If not match was found, continune to next mandator.
|
||||
' For a catch all mandator, a regex like ".+" is needed.
|
||||
For Each oItem In oMappingConfigItems
|
||||
Try
|
||||
Dim oRegex As New Regex(oMappingConfigItem.SourceRegex)
|
||||
Dim oRegex As New Regex(oItem.SourceRegex)
|
||||
Dim oMatch = oRegex.Match(oArticleNumber)
|
||||
|
||||
' If ArticleNumber matches the regex, we assign it and exit
|
||||
@@ -439,13 +440,9 @@ Namespace Winline
|
||||
Logger.Error(ex)
|
||||
Logger.Warn("Regex [{0}] could not be parsed. Skipping.", oMandator.Regex)
|
||||
End Try
|
||||
|
||||
Else
|
||||
Continue For
|
||||
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
Next ' CONFIG ITEM
|
||||
Next ' MANDATOR
|
||||
Next ' EAN
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Reference in New Issue
Block a user