jj firebird
This commit is contained in:
@@ -9,6 +9,10 @@ Imports DigitalData.Modules.Filesystem
|
||||
Public Class ImportZUGFeRDFiles
|
||||
Implements IJob
|
||||
|
||||
Public Const ZUGFERD_IN = "ZUGFeRD in"
|
||||
Public Const ZUGFERD_ERROR = "ZUGFeRD Error"
|
||||
Public Const ZUGFERD_SUCCESS = "ZUGFeRD Success"
|
||||
|
||||
Private _logger As Logger
|
||||
Private _logConfig As LogConfig
|
||||
Private _zugferd As ZUGFeRDInterface
|
||||
@@ -19,16 +23,22 @@ Public Class ImportZUGFeRDFiles
|
||||
Public WatchDirectories As List(Of String)
|
||||
Public SuccessDirectory As String
|
||||
Public ErrorDirectory As String
|
||||
Public PropertyMap As Dictionary(Of String, String)
|
||||
Public PropertyMap As Dictionary(Of String, XmlItemProperty)
|
||||
|
||||
Public Sub New()
|
||||
WatchDirectories = New List(Of String)
|
||||
SuccessDirectory = Nothing
|
||||
ErrorDirectory = Nothing
|
||||
PropertyMap = New Dictionary(Of String, String)
|
||||
PropertyMap = New Dictionary(Of String, XmlItemProperty)
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
Public Class XmlItemProperty
|
||||
Public TableName As String
|
||||
Public Description As String
|
||||
Public IsRequired As Boolean
|
||||
End Class
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, Firebird As Firebird)
|
||||
_logConfig = LogConfig
|
||||
_logger = LogConfig.GetLogger()
|
||||
@@ -69,24 +79,27 @@ Public Class ImportZUGFeRDFiles
|
||||
oDocument = _zugferd.ExtractZUGFeRDFile(oFile.FullName)
|
||||
|
||||
For Each mapping In args.PropertyMap
|
||||
Dim propertyValue As String = PropertyValues.GetPropValue(oDocument, mapping.Value)
|
||||
Dim propertyValue As String = PropertyValues.GetPropValue(oDocument, mapping.Key)
|
||||
Dim propertyDescripton As String = mapping.Value.Description
|
||||
|
||||
' TODO: Check for missing values
|
||||
'If String.IsNullOrEmpty(propertyValue) Then
|
||||
' Throw New Exception($"Property {mapping.Value} not found or empty.")
|
||||
'End If
|
||||
If String.IsNullOrEmpty(propertyValue) Then
|
||||
_logger.Warn("Property {0} is empty or not found", propertyDescripton)
|
||||
End If
|
||||
|
||||
Console.WriteLine("{0} => {1}", mapping.Key, propertyValue)
|
||||
oValues.Add(mapping.Key, propertyValue)
|
||||
If String.IsNullOrEmpty(propertyValue) And mapping.Value.IsRequired Then
|
||||
_logger.Error("Property {0} is empty but required!", propertyDescripton)
|
||||
Throw New ApplicationException($"Property {propertyDescripton} is empty but required!")
|
||||
End If
|
||||
|
||||
' TODO: Insert into scheise
|
||||
Dim oTableColumnArray = mapping.Key.Split(".")
|
||||
Dim oTableName = oTableColumnArray.First()
|
||||
Dim oColumnName = oTableColumnArray.Last()
|
||||
Console.WriteLine("{0} => {1}", propertyDescripton, propertyValue)
|
||||
oValues.Add(propertyDescripton, propertyValue)
|
||||
|
||||
_logger.Info("Mapping Property {0} to value {1}. Will be inserted into column {2} on table {3}", mapping.Value, propertyValue, oTableName, oColumnName)
|
||||
Dim oTableName = mapping.Value.TableName
|
||||
Dim oCommand = $"INSERT INTO {oTableName} (REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE) VALUES ('{oGuid}', '{propertyDescripton}', '{propertyValue}')"
|
||||
|
||||
_logger.Info("Mapping Property {0} to value {1}. Will be inserted into table {2}", propertyDescripton, propertyValue, oTableName)
|
||||
|
||||
Dim oCommand = $"INSERT INTO {oTableName} (FILEID, ""NAME"", ""VALUE"") VALUES ('{oGuid}', '{oColumnName}', '{propertyValue}')"
|
||||
_firebird.ExecuteNonQueryWithConnection(oCommand, oConnection, Firebird.TransactionMode.ExternalTransaction, oTransaction)
|
||||
Next
|
||||
|
||||
@@ -97,11 +110,12 @@ Public Class ImportZUGFeRDFiles
|
||||
_logger.Error(ex, "File {0} was not processesd. Transaction rolled back.")
|
||||
Finally
|
||||
oConnection.Close()
|
||||
'_filesystem.MoveTo(oFile.FullName, oMoveDirectory)
|
||||
_filesystem.MoveTo(oFile.FullName, oMoveDirectory)
|
||||
_logger.Info("Finished processing file {0}", oFile.Name)
|
||||
|
||||
End Try
|
||||
Next
|
||||
Else
|
||||
_logger.Debug("Directory {0} does not exist", oPath)
|
||||
End If
|
||||
|
||||
_logger.Info("Finished processing directory {0}", oPath)
|
||||
|
||||
Reference in New Issue
Block a user