Add Template Selection, load templates from Database
This commit is contained in:
11
MultiTool.Shared/Helpers.vb
Normal file
11
MultiTool.Shared/Helpers.vb
Normal file
@@ -0,0 +1,11 @@
|
||||
Imports DigitalData.Modules.Language
|
||||
|
||||
Public Class Helpers
|
||||
Public Shared Function GetRowItem(Of T)(pRow As DataRow, pFieldName As String, Optional pDefaultValue As T = Nothing) As T
|
||||
Try
|
||||
Return Utils.NotNull(pRow.Item(pFieldName), pDefaultValue)
|
||||
Catch ex As Exception
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
@@ -104,6 +104,7 @@
|
||||
<Compile Include="Documents\DocumentType.vb" />
|
||||
<Compile Include="Documents\DocumentLoader.vb" />
|
||||
<Compile Include="Exceptions.vb" />
|
||||
<Compile Include="Helpers.vb" />
|
||||
<Compile Include="IDictionaryEx.vb" />
|
||||
<Compile Include="IEnumerableEx.vb" />
|
||||
<Compile Include="Mapper.vb" />
|
||||
@@ -134,14 +135,14 @@
|
||||
<Compile Include="Schemas\Schema.vb" />
|
||||
<Compile Include="Schemas\SchemaLoader.vb" />
|
||||
<Compile Include="Serializer.vb" />
|
||||
<Compile Include="Winline\Configuration.vb" />
|
||||
<Compile Include="Schemas\Configuration.vb" />
|
||||
<Compile Include="Winline\Entities\Account.vb" />
|
||||
<Compile Include="Winline\WinlineData.vb" />
|
||||
<Compile Include="Winline\Entities\Article.vb" />
|
||||
<Compile Include="Winline\Entities\Contact.vb" />
|
||||
<Compile Include="Winline\Entities\DocumentKind.vb" />
|
||||
<Compile Include="Winline\Entities\Mandator.vb" />
|
||||
<Compile Include="Winline\Entities\ColumnConfig.vb" />
|
||||
<Compile Include="Schemas\ColumnConfig.vb" />
|
||||
<Compile Include="Winline\WebService.vb" />
|
||||
<Compile Include="XmlData.vb" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Imports MultiTool.Shared.Constants
|
||||
|
||||
Namespace Winline
|
||||
Namespace Schemas
|
||||
Public Class ColumnConfig
|
||||
Public Property Name As String
|
||||
Public Property Table As String
|
||||
@@ -1,10 +1,12 @@
|
||||
|
||||
Namespace Winline
|
||||
Imports MultiTool.Shared.Winline
|
||||
|
||||
Namespace Schemas
|
||||
''' <summary>
|
||||
''' Class for loading column/field config from database
|
||||
''' </summary>
|
||||
Public Class Configuration
|
||||
Public Columns As List(Of Winline.ColumnConfig)
|
||||
Public Columns As List(Of ColumnConfig)
|
||||
|
||||
Public Function GetColumn(pName As String) As ColumnConfig
|
||||
Return Columns.
|
||||
@@ -1,9 +1,14 @@
|
||||
Imports MultiTool.Shared.Winline
|
||||
Imports System.IO
|
||||
Imports MultiTool.Shared.Winline
|
||||
|
||||
Namespace Schemas
|
||||
Public Class Schema
|
||||
Public Property Tables As New List(Of Table)
|
||||
Public Property Name As String
|
||||
Public Property FileName As String
|
||||
Public Property Description As String
|
||||
Public Property IsImport As Boolean
|
||||
|
||||
Public Property Tables As New List(Of Table)
|
||||
|
||||
Class Table
|
||||
Public Property Name As String
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
Imports System.IO
|
||||
Imports System.Xml
|
||||
Imports System.Xml.XPath
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports MultiTool.Shared.Winline
|
||||
Imports MultiTool.Shared.Helpers
|
||||
|
||||
Namespace Schemas
|
||||
Public Class SchemaLoader
|
||||
@@ -9,42 +10,95 @@ Namespace Schemas
|
||||
|
||||
Private ReadOnly ns As XNamespace = "http://www.w3.org/2001/XMLSchema"
|
||||
|
||||
Public SchemaList As List(Of FileInfo)
|
||||
Public SchemaList As List(Of Schema)
|
||||
Public TemplateConfiguration As New Configuration
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig)
|
||||
Private Database As MSSQLServer
|
||||
Private InputDirectory As String
|
||||
|
||||
Private Const VWEDI_XML_ITEMS = "VWEDI_XML_ITEMS"
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pMSSQL As MSSQLServer, pInputDirectory As String)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger)
|
||||
Database = pMSSQL
|
||||
InputDirectory = pInputDirectory
|
||||
End Sub
|
||||
|
||||
Public Function LoadFiles(pSchemaDirectory) As Boolean
|
||||
If pSchemaDirectory = String.Empty Then
|
||||
Throw New ArgumentNullException("SchemaDirectory")
|
||||
End If
|
||||
|
||||
Logger.Info("Loading files from directory [{0}]", pSchemaDirectory)
|
||||
|
||||
Public Async Function LoadTemplates() As Task(Of Boolean)
|
||||
Try
|
||||
Dim oDirectory As New DirectoryInfo(pSchemaDirectory)
|
||||
Dim oFiles = oDirectory.GetFiles()
|
||||
Dim oSql = $"SELECT * FROM [DD_ECM].[dbo].[TBEDI_XML_TEMPLATES]"
|
||||
Dim oTable As DataTable = Await Database.GetDatatableAsync(oSql)
|
||||
Dim oTemplates As New List(Of Schema)
|
||||
|
||||
Logger.Debug("Found [{0}] files in directory [{1}]", oFiles.Count, oDirectory)
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oTemplate As New Schema With {
|
||||
.Name = GetRowItem(oRow, "NAME", String.Empty),
|
||||
.Description = GetRowItem(oRow, "DESCRIPTION", String.Empty),
|
||||
.FileName = GetRowItem(oRow, "FILE_NAME", String.Empty),
|
||||
.IsImport = GetRowItem(oRow, "IS_IMPORT", True)
|
||||
}
|
||||
|
||||
SchemaList = oFiles.ToList()
|
||||
oTemplates.Add(oTemplate)
|
||||
Next
|
||||
|
||||
SchemaList = oTemplates
|
||||
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
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 oItems As New List(Of ColumnConfig)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oColumn As New ColumnConfig() With {
|
||||
.Template = GetRowItem(oRow, "TEMPLATE_NAME", String.Empty),
|
||||
.Table = GetRowItem(oRow, "XML_TABLE", String.Empty),
|
||||
.Name = GetRowItem(oRow, "XML_ITEM", String.Empty),
|
||||
.Type = ColumnConfig.ConvertType(GetRowItem(oRow, "DATA_TYPE", String.Empty)),
|
||||
.OrderKey = GetRowItem(oRow, "ORDER_KEY", 0),
|
||||
.IsReadOnly = GetRowItem(oRow, "IS_READ_ONLY", False),
|
||||
.IsVisible = GetRowItem(oRow, "IS_VISIBLE", True),
|
||||
.IsRequired = GetRowItem(oRow, "IS_REQUIRED", False),
|
||||
.IsHead = GetRowItem(oRow, "IS_HEAD", True),
|
||||
.[Function] = New ColumnConfig.ColumnFunction With {
|
||||
.Id = GetRowItem(oRow, "FUNCTION_ID", 0),
|
||||
.Name = GetRowItem(oRow, "FUNCTION_NAME", String.Empty),
|
||||
.Params = GetRowItem(oRow, "FUNCTION_PARAMETERS", String.Empty)
|
||||
}
|
||||
}
|
||||
|
||||
oItems.Add(oColumn)
|
||||
Next
|
||||
|
||||
TemplateConfiguration = New Configuration With {
|
||||
.Columns = oItems
|
||||
}
|
||||
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Throw New IO.IOException($"Could not load files from directory {pSchemaDirectory}", ex)
|
||||
Return False
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function GetSchemaFromFile(pSchemaFilePath As String) As Schema
|
||||
Dim oSchema As New Schema
|
||||
Dim oFileInfo As New FileInfo(pSchemaFilePath)
|
||||
Dim oElements = GetSchemaElements(pSchemaFilePath)
|
||||
Public Function UpdateSchemaFromFile(pSchema As Schema, pInputDirectory As String) As Schema
|
||||
Dim oFullPath = Path.Combine(pInputDirectory, pSchema.FileName)
|
||||
|
||||
oSchema.Name = oFileInfo.Name
|
||||
If Not IO.File.Exists(oFullPath) Then
|
||||
Throw New FileNotFoundException(oFullPath)
|
||||
End If
|
||||
|
||||
Dim oElements = GetSchemaElements(oFullPath)
|
||||
|
||||
For Each oElement In oElements
|
||||
Dim oColumns = GetElementColumns(oElement)
|
||||
@@ -69,17 +123,17 @@ Namespace Schemas
|
||||
oSchemaColumns.Add(oSchemaColumn)
|
||||
Next
|
||||
|
||||
oSchema.Tables.Add(New Schema.Table With {
|
||||
pSchema.Tables.Add(New Schema.Table With {
|
||||
.Name = XmlData.GetElementAttribute(oElement, "name"),
|
||||
.Columns = oSchemaColumns
|
||||
})
|
||||
|
||||
Next
|
||||
|
||||
Return oSchema
|
||||
Return pSchema
|
||||
End Function
|
||||
|
||||
Public Function UpdateSchemaWithDatabaseConfiguration(pSchema As Schema, pTemplateConfig As Winline.Configuration) As Schema
|
||||
Public Function UpdateSchemaFromDatabase(pSchema As Schema, pTemplateConfig As Configuration) As Schema
|
||||
If pTemplateConfig Is Nothing Then
|
||||
Return pSchema
|
||||
End If
|
||||
@@ -89,7 +143,7 @@ Namespace Schemas
|
||||
Dim oConfig = pTemplateConfig.GetColumn(oColumn.Name)
|
||||
|
||||
If oConfig Is Nothing Then
|
||||
oConfig = New Winline.ColumnConfig With {
|
||||
oConfig = New ColumnConfig With {
|
||||
.IsRequired = oColumn.IsRequired,
|
||||
.Name = oColumn.Name
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Language
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports MultiTool.Shared.Helpers
|
||||
Imports System.Text.RegularExpressions
|
||||
|
||||
Namespace Winline
|
||||
@@ -16,12 +17,9 @@ Namespace Winline
|
||||
Public DocumentKinds As New List(Of DocumentKind)
|
||||
|
||||
Public Years As List(Of Integer)
|
||||
Public TemplateConfiguration As New Configuration
|
||||
|
||||
Public Const ALL_MESOCOMP = "mesocomp"
|
||||
|
||||
Public Const VWEDI_XML_ITEMS = "VWEDI_XML_ITEMS"
|
||||
|
||||
Public Const V21_ARTICLENUMBER = "c002"
|
||||
Public Const V21_ARTICLEDESCRIPTION = "c003"
|
||||
Public Const V21_MAINARTICLENUMBER = "c011"
|
||||
@@ -487,47 +485,6 @@ Namespace Winline
|
||||
End If
|
||||
End Function
|
||||
|
||||
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 oItems As New List(Of ColumnConfig)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oColumn As New ColumnConfig() With {
|
||||
.Template = GetRowItem(oRow, "TEMPLATE_NAME", String.Empty),
|
||||
.Table = GetRowItem(oRow, "XML_TABLE", String.Empty),
|
||||
.Name = GetRowItem(oRow, "XML_ITEM", String.Empty),
|
||||
.Type = ColumnConfig.ConvertType(GetRowItem(oRow, "DATA_TYPE", String.Empty)),
|
||||
.OrderKey = GetRowItem(oRow, "ORDER_KEY", 0),
|
||||
.IsReadOnly = GetRowItem(oRow, "IS_READ_ONLY", False),
|
||||
.IsVisible = GetRowItem(oRow, "IS_VISIBLE", True),
|
||||
.IsRequired = GetRowItem(oRow, "IS_REQUIRED", False),
|
||||
.IsHead = GetRowItem(oRow, "IS_HEAD", True),
|
||||
.[Function] = New ColumnConfig.ColumnFunction With {
|
||||
.Id = GetRowItem(oRow, "FUNCTION_ID", 0),
|
||||
.Name = GetRowItem(oRow, "FUNCTION_NAME", String.Empty),
|
||||
.Params = GetRowItem(oRow, "FUNCTION_PARAMETERS", String.Empty)
|
||||
}
|
||||
}
|
||||
|
||||
oItems.Add(oColumn)
|
||||
Next
|
||||
|
||||
Dim oColumns = oItems
|
||||
TemplateConfiguration = New Configuration With {
|
||||
.Columns = oColumns
|
||||
}
|
||||
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Turns a database info like "SQLCWLDATEN on SERVER\INSTANCE" into a Tuple of two strings
|
||||
''' </summary>
|
||||
@@ -552,14 +509,5 @@ Namespace Winline
|
||||
Split(oDelimiter, StringSplitOptions.None).
|
||||
ToList()
|
||||
End Function
|
||||
|
||||
|
||||
Private Function GetRowItem(Of T)(pRow As DataRow, pFieldName As String, Optional pDefaultValue As T = Nothing) As T
|
||||
Try
|
||||
Return Utils.NotNull(pRow.Item(pFieldName), pDefaultValue)
|
||||
Catch ex As Exception
|
||||
Return Nothing
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
Reference in New Issue
Block a user