Rename Schema to Template , Clean up obsolete files
This commit is contained in:
45
MultiTool.Shared/Templates/ColumnConfig.vb
Normal file
45
MultiTool.Shared/Templates/ColumnConfig.vb
Normal file
@@ -0,0 +1,45 @@
|
||||
Imports MultiTool.Shared.Constants
|
||||
|
||||
Namespace Templates
|
||||
Public Class ColumnConfig
|
||||
Public Property Name As String
|
||||
Public Property Table As String
|
||||
Public Property Type As ColumnType
|
||||
Public Property Template As String
|
||||
Public Property OrderKey As Integer
|
||||
|
||||
Public Property IsHead As Boolean
|
||||
Public Property IsReadOnly As Boolean
|
||||
Public Property IsVisible As Boolean
|
||||
Public Property IsRequired As Boolean
|
||||
|
||||
Public Property [Function] As ColumnFunction
|
||||
|
||||
Public Class ColumnFunction
|
||||
Public Id As XmlFunction
|
||||
Public Name As String
|
||||
Public Params As String
|
||||
End Class
|
||||
|
||||
Public Shared Function ConvertType(pType As String) As ColumnType
|
||||
Select Case pType
|
||||
Case DB_TYPE_DATE
|
||||
Return ColumnType.Date
|
||||
|
||||
Case DB_TYPE_DECIMAL
|
||||
Return ColumnType.Date
|
||||
|
||||
Case DB_TYPE_BOOLEAN
|
||||
Return ColumnType.Boolean
|
||||
|
||||
Case DB_TYPE_INTEGER
|
||||
Return ColumnType.Integer
|
||||
|
||||
Case Else
|
||||
Return ColumnType.String
|
||||
End Select
|
||||
End Function
|
||||
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
12
MultiTool.Shared/Templates/MappingConfig.vb
Normal file
12
MultiTool.Shared/Templates/MappingConfig.vb
Normal file
@@ -0,0 +1,12 @@
|
||||
Namespace Templates
|
||||
Public Class MappingConfig
|
||||
Public Property OrderKey As Integer
|
||||
Public Property SourceName As String
|
||||
Public Property SourceItem As String
|
||||
Public Property SourceRegex As String
|
||||
Public Property DestinationName As String
|
||||
Public Property DestinationItem As String
|
||||
Public Property DestinationValue As String
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
26
MultiTool.Shared/Templates/Template.vb
Normal file
26
MultiTool.Shared/Templates/Template.vb
Normal file
@@ -0,0 +1,26 @@
|
||||
Namespace Templates
|
||||
Public Class Template
|
||||
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
|
||||
Public Property Columns As New List(Of Column)
|
||||
End Class
|
||||
|
||||
Class Column
|
||||
Public Property Name As String
|
||||
Public Property DataType As Constants.ColumnType
|
||||
''' <summary>
|
||||
''' Required value from Schema. This value will be written in the ColumnConfig and is not relevant from that point on.
|
||||
''' </summary>
|
||||
Public Property IsRequired As Boolean
|
||||
Public Property Config As ColumnConfig
|
||||
End Class
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
17
MultiTool.Shared/Templates/TemplateConfig.vb
Normal file
17
MultiTool.Shared/Templates/TemplateConfig.vb
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
Imports MultiTool.Shared.Winline
|
||||
|
||||
Namespace Templates
|
||||
''' <summary>
|
||||
''' Class for loading column/field config from database
|
||||
''' </summary>
|
||||
Public Class TemplateConfig
|
||||
Public Columns As List(Of ColumnConfig)
|
||||
|
||||
Public Function GetColumn(pName As String) As ColumnConfig
|
||||
Return Columns.
|
||||
Where(Function(c) c.Name = pName).
|
||||
FirstOrDefault()
|
||||
End Function
|
||||
End Class
|
||||
End Namespace
|
||||
226
MultiTool.Shared/Templates/TemplateLoader.vb
Normal file
226
MultiTool.Shared/Templates/TemplateLoader.vb
Normal file
@@ -0,0 +1,226 @@
|
||||
Imports System.IO
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports MultiTool.Shared.Winline
|
||||
Imports MultiTool.Shared.Helpers
|
||||
|
||||
Namespace Templates
|
||||
Public Class TemplateLoader
|
||||
Inherits BaseClass
|
||||
|
||||
Private ReadOnly ns As XNamespace = "http://www.w3.org/2001/XMLSchema"
|
||||
|
||||
Public Property TemplateList As List(Of Template)
|
||||
Public Property TemplateConfiguration As New TemplateConfig
|
||||
Public Property MappingConfiguration As New List(Of MappingConfig)
|
||||
|
||||
Private ReadOnly Database As MSSQLServer
|
||||
|
||||
Private Const VWEDI_XML_ITEMS = "VWEDI_XML_ITEMS"
|
||||
Private Const VWEDI_XML_MAPPING = "VWEDI_XML_MAPPING"
|
||||
|
||||
Public Sub New(pLogConfig As LogConfig, pMSSQL As MSSQLServer)
|
||||
MyBase.New(pLogConfig, pLogConfig.GetLogger)
|
||||
Database = pMSSQL
|
||||
End Sub
|
||||
|
||||
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 oTemplates As New List(Of Template)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oTemplate As New Template 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)
|
||||
}
|
||||
|
||||
oTemplates.Add(oTemplate)
|
||||
Next
|
||||
|
||||
TemplateList = oTemplates
|
||||
|
||||
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 oMappingConfigList As New List(Of MappingConfig)
|
||||
|
||||
For Each oRow As DataRow In oTable.Rows
|
||||
Dim oTemplate As New MappingConfig With {
|
||||
.OrderKey = GetRowItem(oRow, "ORDER_KEY", String.Empty),
|
||||
.SourceName = GetRowItem(oRow, "SOURCE_NAME", String.Empty),
|
||||
.SourceItem = GetRowItem(oRow, "SOURCE_ITEM", String.Empty),
|
||||
.SourceRegex = GetRowItem(oRow, "SOURCE_REGEX", String.Empty),
|
||||
.DestinationName = GetRowItem(oRow, "DESTINATION_NAME", String.Empty),
|
||||
.DestinationItem = GetRowItem(oRow, "DESTINATION_ITEM", String.Empty),
|
||||
.DestinationValue = GetRowItem(oRow, "DESTINATION_VALUE", String.Empty)
|
||||
}
|
||||
|
||||
oMappingConfigList.Add(oTemplate)
|
||||
Next
|
||||
|
||||
MappingConfiguration = oMappingConfigList
|
||||
|
||||
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 TemplateConfig With {
|
||||
.Columns = oItems
|
||||
}
|
||||
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function UpdateTemplateFromFile(pTemplate As Template, pInputDirectory As String) As Template
|
||||
Dim oFullPath = Path.Combine(pInputDirectory, pTemplate.FileName)
|
||||
|
||||
If Not IO.File.Exists(oFullPath) Then
|
||||
Throw New FileNotFoundException(oFullPath)
|
||||
End If
|
||||
|
||||
Dim oElements = GetTemplateElements(oFullPath)
|
||||
|
||||
For Each oElement In oElements
|
||||
Dim oColumns = GetElementColumns(oElement)
|
||||
Dim oTemplateColumns As New List(Of Template.Column)
|
||||
|
||||
For Each oColumn As XElement In oColumns
|
||||
Dim oName = XmlData.GetElementAttribute(oColumn, "name")
|
||||
Dim oMinOccurs = XmlData.GetElementAttribute(oColumn, "minOccurs")
|
||||
Dim oMaxOccurs = XmlData.GetElementAttribute(oColumn, "maxOccurs")
|
||||
Dim oType = GetElementType(oColumn)
|
||||
Dim oRequired = False
|
||||
|
||||
If oMinOccurs = 1 And oMaxOccurs = 1 Then
|
||||
oRequired = True
|
||||
End If
|
||||
|
||||
Dim oTemplateColumn As New Template.Column With {
|
||||
.Name = oName,
|
||||
.DataType = oType,
|
||||
.IsRequired = oRequired
|
||||
}
|
||||
oTemplateColumns.Add(oTemplateColumn)
|
||||
Next
|
||||
|
||||
pTemplate.Tables.Add(New Template.Table With {
|
||||
.Name = XmlData.GetElementAttribute(oElement, "name"),
|
||||
.Columns = oTemplateColumns
|
||||
})
|
||||
|
||||
Next
|
||||
|
||||
Return pTemplate
|
||||
End Function
|
||||
|
||||
Public Function UpdateTemplateFromDatabase(pTemplate As Template, pTemplateConfig As TemplateConfig) As Template
|
||||
If pTemplateConfig Is Nothing Then
|
||||
Return pTemplate
|
||||
End If
|
||||
|
||||
For Each oTable In pTemplate.Tables
|
||||
For Each oColumn As Template.Column In oTable.Columns
|
||||
Dim oConfig = pTemplateConfig.GetColumn(oColumn.Name)
|
||||
|
||||
If oConfig Is Nothing Then
|
||||
oConfig = New ColumnConfig With {
|
||||
.IsRequired = oColumn.IsRequired,
|
||||
.Name = oColumn.Name
|
||||
}
|
||||
End If
|
||||
|
||||
oColumn.Config = oConfig
|
||||
Next
|
||||
Next
|
||||
|
||||
Return pTemplate
|
||||
End Function
|
||||
|
||||
Public Function GetElementType(pElement As XElement) As Constants.ColumnType
|
||||
Dim oTypeString = XmlData.GetElementAttribute(pElement, "type")
|
||||
|
||||
If oTypeString Is Nothing Then
|
||||
Dim oRestrictionElement As XElement = pElement.
|
||||
Descendants(ns + "restriction").
|
||||
FirstOrDefault()
|
||||
|
||||
oTypeString = XmlData.GetElementAttribute(oRestrictionElement, "base")
|
||||
End If
|
||||
|
||||
Select Case oTypeString
|
||||
Case Constants.TEMPLATE_TYPE_DATE
|
||||
Return Constants.ColumnType.Date
|
||||
Case Constants.TEMPLATE_TYPE_INTEGER
|
||||
Return Constants.ColumnType.Integer
|
||||
Case Constants.TEMPLATE_TYPE_DECIMAL
|
||||
Return Constants.ColumnType.Decimal
|
||||
Case Constants.TEMPLATE_TYPE_BOOLEAN
|
||||
Return Constants.ColumnType.Boolean
|
||||
Case Else
|
||||
Return Constants.ColumnType.String
|
||||
End Select
|
||||
End Function
|
||||
|
||||
Public Function GetTemplateElements(pTemplateFilePath As String) As List(Of XElement)
|
||||
Dim oText As String = IO.File.ReadAllText(pTemplateFilePath)
|
||||
Dim oDoc = XDocument.Parse(oText)
|
||||
|
||||
Return XmlData.GetElementsFromElement(oDoc, "choice", ns)
|
||||
End Function
|
||||
|
||||
Public Function GetElementColumns(pElement As XElement) As List(Of XElement)
|
||||
Return XmlData.GetElementsFromElement(pElement, "sequence", ns)
|
||||
End Function
|
||||
End Class
|
||||
|
||||
End Namespace
|
||||
Reference in New Issue
Block a user