Migrate configuration from UserConfig to database
This commit is contained in:
@@ -3,36 +3,4 @@
|
||||
Public Class Config
|
||||
<ConnectionString>
|
||||
Public Property ConnectionString As String = ""
|
||||
|
||||
Public Property Mandators As New List(Of MandatorConfig)
|
||||
|
||||
Public Property InputDirectory As String = ""
|
||||
Public Property OutputDirectory As String = ""
|
||||
Public Property SchemaDirectory As String = ""
|
||||
|
||||
Public Property Webservice As New WebServiceConfig()
|
||||
Public Property DefaultYearOverride As Integer = 0
|
||||
|
||||
Public Class WebServiceConfig
|
||||
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
|
||||
Public Property Order As Integer
|
||||
Public Property Name As String
|
||||
Public Property ArticleRegex As String
|
||||
End Class
|
||||
|
||||
<DebuggerStepThrough>
|
||||
Public Function GetYear() As Integer
|
||||
If DefaultYearOverride > 0 Then
|
||||
Return DefaultYearOverride
|
||||
End If
|
||||
|
||||
Return Now.Year
|
||||
End Function
|
||||
End Class
|
||||
|
||||
@@ -306,48 +306,25 @@ Namespace Documents
|
||||
End If
|
||||
|
||||
If oFunctionName = "EAN" Then
|
||||
Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(oField.Key)
|
||||
Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator)
|
||||
If oArticleNumber IsNot Nothing Then
|
||||
oNumberItem.External = oArticleNumber
|
||||
oNumberItem.Final = oArticleNumber
|
||||
Else
|
||||
oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound
|
||||
End If
|
||||
SetArticleByEAN(oRow, pMandator, oField.Key)
|
||||
End If
|
||||
Next
|
||||
Next
|
||||
|
||||
'Dim oHead As DocumentRow = pDocument.Rows.
|
||||
' Where(Function(r) r.Name.ToUpper.EndsWith("T025")).
|
||||
' SetValue(Sub(r As DocumentRow) SetAccountByGLN(r, pMandator, "Fakt_Kontonummer", "Fakt_Name")).
|
||||
' SetValue(Sub(r As DocumentRow) SetAccountByGLN(r, pMandator, "Lief_Kontonummer", "Lief_Name")).
|
||||
' FirstOrDefault()
|
||||
|
||||
'Dim oPositions As List(Of DocumentRow) = pDocument.Rows.
|
||||
' Where(Function(r) r.Name.ToUpper.EndsWith("T026")).
|
||||
' SetValue(Sub(oRow As DocumentRow)
|
||||
' Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault("Artikelnummer")
|
||||
' If oNumberItem Is Nothing Then
|
||||
' Exit Sub
|
||||
' End If
|
||||
|
||||
' Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator)
|
||||
' If oArticleNumber IsNot Nothing Then
|
||||
' oNumberItem.External = oArticleNumber
|
||||
' oNumberItem.Final = oArticleNumber
|
||||
' Else
|
||||
' oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound
|
||||
' End If
|
||||
' End Sub).
|
||||
' ToList()
|
||||
|
||||
'Dim oList As New List(Of DocumentRow) From {oHead}
|
||||
'pDocument.Rows = oList.Concat(oPositions).ToList()
|
||||
|
||||
Return pDocument
|
||||
End Function
|
||||
|
||||
Private Sub SetArticleByEAN(pRow As DocumentRow, pMandator As Mandator, pArticleField As String)
|
||||
Dim oNumberItem As DocumentRow.FieldValue = pRow.Fields.GetOrDefault(pArticleField)
|
||||
Dim oArticleNumber = Winline.TryGetArticleNumber(oNumberItem.Original, pMandator)
|
||||
If oArticleNumber IsNot Nothing Then
|
||||
oNumberItem.External = oArticleNumber
|
||||
oNumberItem.Final = oArticleNumber
|
||||
Else
|
||||
oNumberItem.Error = DocumentRow.FieldError.ArticleNotFound
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub SetAccountByGLN(oRow As DocumentRow, pMandator As Mandator, pNumberField As String, pNameField As String)
|
||||
' Try to read the Account number (which is a GLN really) and account Name
|
||||
Dim oNumberItem As DocumentRow.FieldValue = oRow.Fields.GetOrDefault(pNumberField)
|
||||
|
||||
@@ -124,6 +124,7 @@
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="Templates\GeneralConfig.vb" />
|
||||
<Compile Include="Templates\MandatorConfig.vb" />
|
||||
<Compile Include="Templates\MandatorConfigItem.vb" />
|
||||
<Compile Include="Templates\MappingConfig.vb" />
|
||||
|
||||
27
MultiTool.Shared/Templates/GeneralConfig.vb
Normal file
27
MultiTool.Shared/Templates/GeneralConfig.vb
Normal file
@@ -0,0 +1,27 @@
|
||||
Namespace Templates
|
||||
Public Class GeneralConfig
|
||||
Public Property InputDirectory As String = ""
|
||||
Public Property OutputDirectory As String = ""
|
||||
Public Property TemplateDirectory As String = ""
|
||||
|
||||
Public Property Webservice As New WebServiceConfig()
|
||||
Public Property DefaultYearOverride As Integer = 0
|
||||
|
||||
Public Class WebServiceConfig
|
||||
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
|
||||
|
||||
<DebuggerStepThrough>
|
||||
Public Function GetYear() As Integer
|
||||
If DefaultYearOverride > 0 Then
|
||||
Return DefaultYearOverride
|
||||
End If
|
||||
|
||||
Return Now.Year
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
@@ -12,13 +12,15 @@ Namespace Templates
|
||||
Public Property TemplateConfiguration As New TemplateConfig
|
||||
Public Property MappingConfiguration As New MappingConfig
|
||||
Public Property MandatorConfiguration As New MandatorConfig
|
||||
Public Property GeneralConfiguration As New GeneralConfig
|
||||
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
|
||||
Private Const VWEDI_XML_ITEMS = "VWEDI_XML_ITEMS"
|
||||
Private Const VWEDI_XML_MAPPING = "VWEDI_XML_MAPPING"
|
||||
Private Const TBEDI_XML_MANDATORS = "TBEDI_XML_MANDATORS"
|
||||
Private Const TBEDI_XML_TEMPLATES = "TBEDI_XML_TEMPLATES"
|
||||
Private Const SQL_VWEDI_XML_ITEMS = "SELECT * FROM [DD_ECM].[dbo].[VWEDI_XML_ITEMS]"
|
||||
Private Const SQL_VWEDI_XML_MAPPING = "SELECT * FROM [DD_ECM].[dbo].[VWEDI_XML_MAPPING]"
|
||||
Private Const SQL_TBEDI_XML_MANDATORS = "SELECT * FROM [DD_ECM].[dbo].[TBEDI_XML_MANDATORS] ORDER BY ORDER_KEY"
|
||||
Private Const SQL_TBEDI_XML_CONFIG = "SELECT * FROM [DD_ECM].[dbo].[TBEDI_XML_CONFIG]"
|
||||
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)
|
||||
@@ -27,8 +29,7 @@ Namespace Templates
|
||||
|
||||
Public Async Function LoadTemplates() As Task(Of Boolean)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{TBEDI_XML_TEMPLATES}]"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_TBEDI_XML_TEMPLATES)
|
||||
Dim oTemplates As New List(Of Template)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
@@ -52,10 +53,58 @@ Namespace Templates
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function LoadGeneralConfiguration() As Task(Of Boolean)
|
||||
Try
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_TBEDI_XML_CONFIG)
|
||||
Dim oGeneralConfig As New GeneralConfig
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oValue As String = oRow.ItemEx("VALUE", String.Empty)
|
||||
|
||||
Select Case oRow.Item("KEY")
|
||||
Case "YEAR_OVERRIDE"
|
||||
oGeneralConfig.DefaultYearOverride = oRow.ItemEx("VALUE", 0)
|
||||
|
||||
Case "WEBSERVICE_BASEURL"
|
||||
oGeneralConfig.Webservice.BaseUrl = oValue
|
||||
|
||||
Case "WEBSERVICE_USERNAME"
|
||||
oGeneralConfig.Webservice.Username = oValue
|
||||
|
||||
Case "WEBSERIVCE_PASSWORD"
|
||||
oGeneralConfig.Webservice.Password = oValue
|
||||
|
||||
Case "WEBSERVICE_IMPORT_BASE_PATH"
|
||||
oGeneralConfig.Webservice.ImportBasePath = oValue
|
||||
|
||||
Case "WEBSERVICE_IMPORT_RELATIVE_PATH"
|
||||
oGeneralConfig.Webservice.ImportRelativePath = oValue
|
||||
|
||||
Case "INPUT_DIRECTORY"
|
||||
oGeneralConfig.InputDirectory = oValue
|
||||
|
||||
Case "OUTPUT_DIRECTORY"
|
||||
oGeneralConfig.OutputDirectory = oValue
|
||||
|
||||
Case "TEMPLATE_DIRECTORY"
|
||||
oGeneralConfig.TemplateDirectory = oValue
|
||||
|
||||
End Select
|
||||
Next
|
||||
|
||||
GeneralConfiguration = oGeneralConfig
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Async Function LoadMappingConfiguration() As Task(Of Boolean)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{VWEDI_XML_MAPPING}]"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_VWEDI_XML_MAPPING)
|
||||
Dim oMappingConfig As New MappingConfig
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
@@ -84,8 +133,7 @@ Namespace Templates
|
||||
|
||||
Public Async Function LoadMandatorConfiguration() As Task(Of Boolean)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{TBEDI_XML_MANDATORS}] ORDER BY ORDER_KEY"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_TBEDI_XML_MANDATORS)
|
||||
Dim oMandatorConfig As New MandatorConfig
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
@@ -109,8 +157,7 @@ Namespace Templates
|
||||
|
||||
Public Async Function LoadTemplateConfiguration() As Task(Of Boolean)
|
||||
Try
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[{VWEDI_XML_ITEMS}]"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(SQL_VWEDI_XML_ITEMS)
|
||||
Dim oItems As New List(Of TemplateConfigItem)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
|
||||
@@ -3,28 +3,29 @@ Imports System.Text
|
||||
Imports System.Net.Http
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports MultiTool.Shared.Documents
|
||||
Imports MultiTool.Shared.Templates.GeneralConfig
|
||||
Imports MultiTool.Shared.Winline.Entities
|
||||
|
||||
Namespace Winline
|
||||
Public Class WebServiceData
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly Config As Config
|
||||
Private ReadOnly Config As WebServiceConfig
|
||||
Private ReadOnly Serializer As Serializer
|
||||
Private ReadOnly AppDataPath As String
|
||||
|
||||
Public Event WebServiceProgress As EventHandler(Of String)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pConfig As Config, pAppDataPath As String)
|
||||
Public Sub New(pLogConfig As LogConfig, pWebserviceConfig As WebServiceConfig, pAppDataPath As String)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger())
|
||||
Serializer = New Serializer(pLogConfig)
|
||||
Config = pConfig
|
||||
Config = pWebserviceConfig
|
||||
AppDataPath = pAppDataPath
|
||||
End Sub
|
||||
|
||||
Public Async Function TransferDocumentToWinline(pDocument As Document, pMandator As Mandator, Optional pIsTest As Boolean = False) As Task(Of Boolean)
|
||||
Dim oBytes As Byte() = GetBytesFromDocument(pDocument)
|
||||
Dim oWS As Config.WebServiceConfig = Config.Webservice
|
||||
Dim oWS = Config
|
||||
|
||||
' --- Get and create path for request/response files
|
||||
|
||||
@@ -41,10 +42,10 @@ Namespace Winline
|
||||
Dim oFileName = GetXmlFilenameWithSuffix(oBaseFileName, "Request", "xml")
|
||||
|
||||
' Relative Path for Webservice Call
|
||||
Dim oImportRelativeFilePath = IO.Path.Combine(GetDateSubDirectoryPath(Config.Webservice.ImportRelativePath), oFileName)
|
||||
Dim oImportRelativeFilePath = IO.Path.Combine(GetDateSubDirectoryPath(oWS.ImportRelativePath), oFileName)
|
||||
|
||||
' Absolute Path to copy Request file
|
||||
Dim oImportAbsolutePath = IO.Path.Combine(Config.Webservice.ImportBasePath, Config.Webservice.ImportRelativePath)
|
||||
Dim oImportAbsolutePath = IO.Path.Combine(oWS.ImportBasePath, oWS.ImportRelativePath)
|
||||
Dim oImportAbsoluteFilePath = IO.Path.Combine(GetDateSubDirectoryPath(oImportAbsolutePath), oFileName)
|
||||
|
||||
' --- Serialize Data into XML string
|
||||
|
||||
@@ -9,19 +9,19 @@ Namespace Winline
|
||||
Public Class WinlineData
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
Private ReadOnly Config As Config
|
||||
Private ReadOnly MandatorConfig As MandatorConfig
|
||||
Private ReadOnly MappingConfig As MappingConfig
|
||||
Private ReadOnly Property Database As MSSQLServer
|
||||
Private ReadOnly Property Config As GeneralConfig
|
||||
Private ReadOnly Property MandatorConfig As MandatorConfig
|
||||
Private ReadOnly Property MappingConfig As MappingConfig
|
||||
|
||||
Public Articles As New List(Of Article)
|
||||
Public Accounts As New List(Of Account)
|
||||
Public Mandators As New List(Of Mandator)
|
||||
Public DocumentKinds As New List(Of DocumentKind)
|
||||
Public Property Articles As New List(Of Article)
|
||||
Public Property Accounts As New List(Of Account)
|
||||
Public Property Mandators As New List(Of Mandator)
|
||||
Public Property DocumentKinds As New List(Of DocumentKind)
|
||||
|
||||
Public Years As List(Of Integer)
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As Config, pMappingConfig As MappingConfig, pMandatorConfig As MandatorConfig)
|
||||
Public Sub New(pLogConfig As LogConfig, pDatabase As MSSQLServer, pConfig As GeneralConfig, pMappingConfig As MappingConfig, pMandatorConfig As MandatorConfig)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger())
|
||||
Database = pDatabase
|
||||
Config = pConfig
|
||||
|
||||
Reference in New Issue
Block a user