Update GetPropertyValue
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
Imports System.Data
|
||||
Imports System.IO
|
||||
Imports System.Linq
|
||||
Imports System.Reflection
|
||||
Imports System.Security.Cryptography
|
||||
Imports System.Text.RegularExpressions
|
||||
Imports System.Xml
|
||||
Imports DigitalData.Modules.Database
|
||||
Imports DigitalData.Modules.Interfaces
|
||||
Imports DigitalData.Modules.Jobs.Exceptions
|
||||
@@ -226,7 +228,7 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oFileGroupFiles As List(Of FileInfo) = oFileGroup.Value
|
||||
Dim oFileGroupId As String = oFileGroup.Key
|
||||
Dim oMissingProperties As New List(Of String)
|
||||
Dim oMD5CheckSum As String
|
||||
Dim oMD5CheckSum As String = String.Empty
|
||||
|
||||
_logger.NewBlock($"Message Id {oFileGroupId}")
|
||||
_logger.Info("Start processing file group {0}", oFileGroupId)
|
||||
@@ -253,8 +255,8 @@ Public Class ImportZUGFeRDFiles
|
||||
_logger.Warn("File is not a valid ZUGFeRD document! Skipping.")
|
||||
Continue For
|
||||
End Try
|
||||
oMD5CheckSum = checkMD5(oFile.FullName)
|
||||
If oMD5CheckSum <> "" Then
|
||||
oMD5CheckSum = CreateMD5(oFile.FullName)
|
||||
If oMD5CheckSum <> String.Empty Then
|
||||
Dim oCheckCommand = $"SELECT * FROM TBEDM_ZUGFERD_HISTORY_IN WHERE UPPER(MD5HASH) = UPPER('{oMD5CheckSum}')"
|
||||
Dim oMD5DT As DataTable = _firebird.GetDatatable(oCheckCommand, Firebird.TransactionMode.ExternalTransaction)
|
||||
If Not IsNothing(oMD5DT) Then
|
||||
@@ -269,8 +271,6 @@ Public Class ImportZUGFeRDFiles
|
||||
_logger.Info("Be careful: oMD5CheckSum is nothing!")
|
||||
End If
|
||||
|
||||
|
||||
|
||||
' Check if there are more than one ZUGFeRD files
|
||||
If oZUGFeRDCount = 1 Then
|
||||
Throw New TooMuchFerdsException()
|
||||
@@ -279,7 +279,34 @@ Public Class ImportZUGFeRDFiles
|
||||
' Since extraction went well, increase the amount of ZUGFeRD files
|
||||
oZUGFeRDCount += 1
|
||||
|
||||
For Each Item As KeyValuePair(Of String, XmlItemProperty) In args.PropertyMap
|
||||
' PropertyMap items with `IsGrouped = False` are handled normally
|
||||
Dim oDefaultProperties As Dictionary(Of String, XmlItemProperty) = args.PropertyMap.
|
||||
Where(Function(Item As KeyValuePair(Of String, XmlItemProperty))
|
||||
Return Item.Value.IsGrouped = False
|
||||
End Function).
|
||||
ToDictionary(Function(Item) Item.Key,
|
||||
Function(Item) Item.Value)
|
||||
|
||||
' PropertyMap items with `IsGrouped = True` are grouped by group scope
|
||||
Dim oGroupedProperties = args.PropertyMap.
|
||||
Where(Function(Item) Item.Value.IsGrouped = True).
|
||||
ToLookup(Function(Item) Item.Value.GroupScope, ' Lookup key is group scope
|
||||
Function(Item) Item)
|
||||
|
||||
' Iterate through groups to get group scope and group items
|
||||
For Each oGroup In oGroupedProperties
|
||||
Dim oGroupScope = oGroup.Key
|
||||
|
||||
For Each oProperty As KeyValuePair(Of String, XmlItemProperty) In oGroup
|
||||
' TODO: Fetching duplicate props works,
|
||||
' now create the Pos Line array with all props of a line/group
|
||||
Dim oPropertyValues As List(Of Object) = PropertyValues.GetPropValue(oDocument, oProperty.Key)
|
||||
|
||||
Console.Write("")
|
||||
Next
|
||||
Next
|
||||
|
||||
For Each Item As KeyValuePair(Of String, XmlItemProperty) In oDefaultProperties
|
||||
Dim propertyValue As String = PropertyValues.GetPropValue(oDocument, Item.Key)
|
||||
Dim propertyDescripton As String = Item.Value.Description
|
||||
|
||||
@@ -322,10 +349,11 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
'If no errors occurred...
|
||||
'Log the History
|
||||
If oMD5CheckSum <> "" Then
|
||||
If oMD5CheckSum <> String.Empty Then
|
||||
Dim oInsertCommand = $"INSERT INTO TBEDM_ZUGFERD_HISTORY_IN (MESSAGE_ID, MD5HASH) VALUES ('{oFileGroupId}', '{oMD5CheckSum}')"
|
||||
_firebird.ExecuteNonQueryWithConnection(oInsertCommand, oConnection, Firebird.TransactionMode.ExternalTransaction, oTransaction)
|
||||
End If
|
||||
|
||||
'commit the transaction
|
||||
oTransaction.Commit()
|
||||
Catch ex As MD5HashException
|
||||
@@ -360,6 +388,11 @@ Public Class ImportZUGFeRDFiles
|
||||
Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties)
|
||||
Dim oEmailData = MoveAndRenameEmailToRejected(args, oFileGroupId)
|
||||
AddToEmailQueue(oFileGroupId, oBody, oEmailData)
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Unknown Error occurred: {0}", ex.Message)
|
||||
_logger.Error(ex)
|
||||
|
||||
oMoveDirectory = args.ErrorDirectory
|
||||
Finally
|
||||
oConnection.Close()
|
||||
|
||||
@@ -400,24 +433,23 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Return oBody
|
||||
End Function
|
||||
Private Function checkMD5(ByVal filename As String) As String
|
||||
Private Function CreateMD5(ByVal Filename As String) As String
|
||||
Try
|
||||
Dim MD5 As New MD5CryptoServiceProvider
|
||||
Dim Hash As Byte()
|
||||
Dim Result As String = ""
|
||||
Dim Tmp As String = ""
|
||||
Dim oMD5 As New MD5CryptoServiceProvider
|
||||
Dim oHash As Byte()
|
||||
Dim oHashString As String
|
||||
Dim oResult As String = ""
|
||||
|
||||
Dim FN As New FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
|
||||
MD5.ComputeHash(FN)
|
||||
FN.Close()
|
||||
Using oFileStream As New FileStream(Filename, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
|
||||
oHash = oMD5.ComputeHash(oFileStream)
|
||||
oHashString = BitConverter.ToString(oHash)
|
||||
End Using
|
||||
|
||||
Hash = MD5.Hash
|
||||
Result = Strings.Replace(BitConverter.ToString(Hash), "-", "")
|
||||
Return Result
|
||||
oResult = oHashString.Replace("-", "")
|
||||
Return oResult
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Return ""
|
||||
End Try
|
||||
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user