Update GetPropertyValue
This commit is contained in:
parent
809f8e2b43
commit
ce21ae5dab
14
GUIs.Test.ZUGFeRDTest/Form1.Designer.vb
generated
14
GUIs.Test.ZUGFeRDTest/Form1.Designer.vb
generated
@ -1,9 +1,9 @@
|
|||||||
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
|
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>
|
||||||
Partial Class Form1
|
Partial Class Form1
|
||||||
Inherits System.Windows.Forms.Form
|
Inherits System.Windows.Forms.Form
|
||||||
|
|
||||||
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
|
'Das Formular überschreibt den Löschvorgang, um die Komponentenliste zu bereinigen.
|
||||||
<System.Diagnostics.DebuggerNonUserCode()> _
|
<System.Diagnostics.DebuggerNonUserCode()>
|
||||||
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
|
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
|
||||||
Try
|
Try
|
||||||
If disposing AndAlso components IsNot Nothing Then
|
If disposing AndAlso components IsNot Nothing Then
|
||||||
@ -20,7 +20,7 @@ Partial Class Form1
|
|||||||
'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
|
'Hinweis: Die folgende Prozedur ist für den Windows Form-Designer erforderlich.
|
||||||
'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
|
'Das Bearbeiten ist mit dem Windows Form-Designer möglich.
|
||||||
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
|
'Das Bearbeiten mit dem Code-Editor ist nicht möglich.
|
||||||
<System.Diagnostics.DebuggerStepThrough()> _
|
<System.Diagnostics.DebuggerStepThrough()>
|
||||||
Private Sub InitializeComponent()
|
Private Sub InitializeComponent()
|
||||||
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
|
Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
|
||||||
Me.Button1 = New System.Windows.Forms.Button()
|
Me.Button1 = New System.Windows.Forms.Button()
|
||||||
@ -54,7 +54,7 @@ Partial Class Form1
|
|||||||
'
|
'
|
||||||
'Button2
|
'Button2
|
||||||
'
|
'
|
||||||
Me.Button2.Location = New System.Drawing.Point(12, 41)
|
Me.Button2.Location = New System.Drawing.Point(12, 122)
|
||||||
Me.Button2.Name = "Button2"
|
Me.Button2.Name = "Button2"
|
||||||
Me.Button2.Size = New System.Drawing.Size(221, 23)
|
Me.Button2.Size = New System.Drawing.Size(221, 23)
|
||||||
Me.Button2.TabIndex = 2
|
Me.Button2.TabIndex = 2
|
||||||
@ -63,7 +63,7 @@ Partial Class Form1
|
|||||||
'
|
'
|
||||||
'Button3
|
'Button3
|
||||||
'
|
'
|
||||||
Me.Button3.Location = New System.Drawing.Point(12, 70)
|
Me.Button3.Location = New System.Drawing.Point(12, 151)
|
||||||
Me.Button3.Name = "Button3"
|
Me.Button3.Name = "Button3"
|
||||||
Me.Button3.Size = New System.Drawing.Size(221, 23)
|
Me.Button3.Size = New System.Drawing.Size(221, 23)
|
||||||
Me.Button3.TabIndex = 3
|
Me.Button3.TabIndex = 3
|
||||||
@ -72,7 +72,7 @@ Partial Class Form1
|
|||||||
'
|
'
|
||||||
'Button4
|
'Button4
|
||||||
'
|
'
|
||||||
Me.Button4.Location = New System.Drawing.Point(12, 112)
|
Me.Button4.Location = New System.Drawing.Point(12, 193)
|
||||||
Me.Button4.Name = "Button4"
|
Me.Button4.Name = "Button4"
|
||||||
Me.Button4.Size = New System.Drawing.Size(221, 23)
|
Me.Button4.Size = New System.Drawing.Size(221, 23)
|
||||||
Me.Button4.TabIndex = 4
|
Me.Button4.TabIndex = 4
|
||||||
@ -82,7 +82,7 @@ Partial Class Form1
|
|||||||
'txtMD5Checksum
|
'txtMD5Checksum
|
||||||
'
|
'
|
||||||
Me.txtMD5Checksum.DataBindings.Add(New System.Windows.Forms.Binding("Text", Global.ZUGFeRDTest.My.MySettings.Default, "MD5Cheksum", True, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged))
|
Me.txtMD5Checksum.DataBindings.Add(New System.Windows.Forms.Binding("Text", Global.ZUGFeRDTest.My.MySettings.Default, "MD5Cheksum", True, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged))
|
||||||
Me.txtMD5Checksum.Location = New System.Drawing.Point(12, 141)
|
Me.txtMD5Checksum.Location = New System.Drawing.Point(12, 222)
|
||||||
Me.txtMD5Checksum.Name = "txtMD5Checksum"
|
Me.txtMD5Checksum.Name = "txtMD5Checksum"
|
||||||
Me.txtMD5Checksum.Size = New System.Drawing.Size(360, 20)
|
Me.txtMD5Checksum.Size = New System.Drawing.Size(360, 20)
|
||||||
Me.txtMD5Checksum.TabIndex = 5
|
Me.txtMD5Checksum.TabIndex = 5
|
||||||
|
|||||||
@ -54,24 +54,28 @@ Public Class Form1
|
|||||||
Return args
|
Return args
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function LoadPropertyMapFor(args As WorkerArgs, specification As String)
|
Private Function LoadPropertyMapFor(Args As WorkerArgs, Specification As String)
|
||||||
Dim oSQL As String = $"SELECT * FROM TBEDM_XML_ITEMS WHERE SPECIFICATION = '{specification}' AND ACTIVE = True"
|
Dim oSQL As String = $"SELECT * FROM TBEDM_XML_ITEMS WHERE SPECIFICATION = '{Specification}' AND ACTIVE = True"
|
||||||
Dim oResult As DataTable = _firebird.GetDatatable(oSQL)
|
Dim oResult As DataTable = _firebird.GetDatatable(oSQL)
|
||||||
|
|
||||||
For Each row As DataRow In oResult.Rows
|
For Each oRow As DataRow In oResult.Rows
|
||||||
Dim xmlPath = row.Item("XML_PATH")
|
Dim xmlPath = oRow.Item("XML_PATH")
|
||||||
Dim tableName = row.Item("TABLE_NAME")
|
Dim tableName = oRow.Item("TABLE_NAME")
|
||||||
Dim description = row.Item("DESCRIPTION")
|
Dim description = oRow.Item("DESCRIPTION")
|
||||||
Dim isRequired = row.Item("IS_REQUIRED")
|
Dim isRequired = oRow.Item("IS_REQUIRED")
|
||||||
|
Dim isGrouped = oRow.Item("IS_GROUPED")
|
||||||
|
Dim groupScope = oRow.Item("GROUP_SCOPE")
|
||||||
|
|
||||||
args.PropertyMap.Add(xmlPath, New XmlItemProperty() With {
|
Args.PropertyMap.Add(xmlPath, New XmlItemProperty() With {
|
||||||
.Description = description,
|
.Description = description,
|
||||||
.TableName = tableName,
|
.TableName = tableName,
|
||||||
.IsRequired = isRequired
|
.IsRequired = isRequired,
|
||||||
|
.IsGrouped = isGrouped,
|
||||||
|
.GroupScope = groupScope
|
||||||
})
|
})
|
||||||
Next
|
Next
|
||||||
|
|
||||||
Return args
|
Return Args
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
||||||
|
|||||||
@ -2,8 +2,10 @@
|
|||||||
Imports System.Data
|
Imports System.Data
|
||||||
Imports System.IO
|
Imports System.IO
|
||||||
Imports System.Linq
|
Imports System.Linq
|
||||||
|
Imports System.Reflection
|
||||||
Imports System.Security.Cryptography
|
Imports System.Security.Cryptography
|
||||||
Imports System.Text.RegularExpressions
|
Imports System.Text.RegularExpressions
|
||||||
|
Imports System.Xml
|
||||||
Imports DigitalData.Modules.Database
|
Imports DigitalData.Modules.Database
|
||||||
Imports DigitalData.Modules.Interfaces
|
Imports DigitalData.Modules.Interfaces
|
||||||
Imports DigitalData.Modules.Jobs.Exceptions
|
Imports DigitalData.Modules.Jobs.Exceptions
|
||||||
@ -226,7 +228,7 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Dim oFileGroupFiles As List(Of FileInfo) = oFileGroup.Value
|
Dim oFileGroupFiles As List(Of FileInfo) = oFileGroup.Value
|
||||||
Dim oFileGroupId As String = oFileGroup.Key
|
Dim oFileGroupId As String = oFileGroup.Key
|
||||||
Dim oMissingProperties As New List(Of String)
|
Dim oMissingProperties As New List(Of String)
|
||||||
Dim oMD5CheckSum As String
|
Dim oMD5CheckSum As String = String.Empty
|
||||||
|
|
||||||
_logger.NewBlock($"Message Id {oFileGroupId}")
|
_logger.NewBlock($"Message Id {oFileGroupId}")
|
||||||
_logger.Info("Start processing file group {0}", 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.")
|
_logger.Warn("File is not a valid ZUGFeRD document! Skipping.")
|
||||||
Continue For
|
Continue For
|
||||||
End Try
|
End Try
|
||||||
oMD5CheckSum = checkMD5(oFile.FullName)
|
oMD5CheckSum = CreateMD5(oFile.FullName)
|
||||||
If oMD5CheckSum <> "" Then
|
If oMD5CheckSum <> String.Empty Then
|
||||||
Dim oCheckCommand = $"SELECT * FROM TBEDM_ZUGFERD_HISTORY_IN WHERE UPPER(MD5HASH) = UPPER('{oMD5CheckSum}')"
|
Dim oCheckCommand = $"SELECT * FROM TBEDM_ZUGFERD_HISTORY_IN WHERE UPPER(MD5HASH) = UPPER('{oMD5CheckSum}')"
|
||||||
Dim oMD5DT As DataTable = _firebird.GetDatatable(oCheckCommand, Firebird.TransactionMode.ExternalTransaction)
|
Dim oMD5DT As DataTable = _firebird.GetDatatable(oCheckCommand, Firebird.TransactionMode.ExternalTransaction)
|
||||||
If Not IsNothing(oMD5DT) Then
|
If Not IsNothing(oMD5DT) Then
|
||||||
@ -269,8 +271,6 @@ Public Class ImportZUGFeRDFiles
|
|||||||
_logger.Info("Be careful: oMD5CheckSum is nothing!")
|
_logger.Info("Be careful: oMD5CheckSum is nothing!")
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
' Check if there are more than one ZUGFeRD files
|
' Check if there are more than one ZUGFeRD files
|
||||||
If oZUGFeRDCount = 1 Then
|
If oZUGFeRDCount = 1 Then
|
||||||
Throw New TooMuchFerdsException()
|
Throw New TooMuchFerdsException()
|
||||||
@ -279,7 +279,34 @@ Public Class ImportZUGFeRDFiles
|
|||||||
' Since extraction went well, increase the amount of ZUGFeRD files
|
' Since extraction went well, increase the amount of ZUGFeRD files
|
||||||
oZUGFeRDCount += 1
|
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 propertyValue As String = PropertyValues.GetPropValue(oDocument, Item.Key)
|
||||||
Dim propertyDescripton As String = Item.Value.Description
|
Dim propertyDescripton As String = Item.Value.Description
|
||||||
|
|
||||||
@ -322,10 +349,11 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
'If no errors occurred...
|
'If no errors occurred...
|
||||||
'Log the History
|
'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}')"
|
Dim oInsertCommand = $"INSERT INTO TBEDM_ZUGFERD_HISTORY_IN (MESSAGE_ID, MD5HASH) VALUES ('{oFileGroupId}', '{oMD5CheckSum}')"
|
||||||
_firebird.ExecuteNonQueryWithConnection(oInsertCommand, oConnection, Firebird.TransactionMode.ExternalTransaction, oTransaction)
|
_firebird.ExecuteNonQueryWithConnection(oInsertCommand, oConnection, Firebird.TransactionMode.ExternalTransaction, oTransaction)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
'commit the transaction
|
'commit the transaction
|
||||||
oTransaction.Commit()
|
oTransaction.Commit()
|
||||||
Catch ex As MD5HashException
|
Catch ex As MD5HashException
|
||||||
@ -360,6 +388,11 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties)
|
Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties)
|
||||||
Dim oEmailData = MoveAndRenameEmailToRejected(args, oFileGroupId)
|
Dim oEmailData = MoveAndRenameEmailToRejected(args, oFileGroupId)
|
||||||
AddToEmailQueue(oFileGroupId, oBody, oEmailData)
|
AddToEmailQueue(oFileGroupId, oBody, oEmailData)
|
||||||
|
Catch ex As Exception
|
||||||
|
_logger.Warn("Unknown Error occurred: {0}", ex.Message)
|
||||||
|
_logger.Error(ex)
|
||||||
|
|
||||||
|
oMoveDirectory = args.ErrorDirectory
|
||||||
Finally
|
Finally
|
||||||
oConnection.Close()
|
oConnection.Close()
|
||||||
|
|
||||||
@ -400,24 +433,23 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
Return oBody
|
Return oBody
|
||||||
End Function
|
End Function
|
||||||
Private Function checkMD5(ByVal filename As String) As String
|
Private Function CreateMD5(ByVal Filename As String) As String
|
||||||
Try
|
Try
|
||||||
Dim MD5 As New MD5CryptoServiceProvider
|
Dim oMD5 As New MD5CryptoServiceProvider
|
||||||
Dim Hash As Byte()
|
Dim oHash As Byte()
|
||||||
Dim Result As String = ""
|
Dim oHashString As String
|
||||||
Dim Tmp As String = ""
|
Dim oResult As String = ""
|
||||||
|
|
||||||
Dim FN As New FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
|
Using oFileStream As New FileStream(Filename, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
|
||||||
MD5.ComputeHash(FN)
|
oHash = oMD5.ComputeHash(oFileStream)
|
||||||
FN.Close()
|
oHashString = BitConverter.ToString(oHash)
|
||||||
|
End Using
|
||||||
|
|
||||||
Hash = MD5.Hash
|
oResult = oHashString.Replace("-", "")
|
||||||
Result = Strings.Replace(BitConverter.ToString(Hash), "-", "")
|
Return oResult
|
||||||
Return Result
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
_logger.Error(ex)
|
_logger.Error(ex)
|
||||||
Return ""
|
Return ""
|
||||||
End Try
|
End Try
|
||||||
|
|
||||||
End Function
|
End Function
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@ -1,13 +1,17 @@
|
|||||||
Imports System.Reflection
|
Imports System.Collections.Generic
|
||||||
|
Imports System.Reflection
|
||||||
Imports System.Text.RegularExpressions
|
Imports System.Text.RegularExpressions
|
||||||
|
|
||||||
Public Class PropertyValues
|
Public Class PropertyValues
|
||||||
Private Shared _indexPattern = "\((\d+)\)"
|
Private Shared _indexPattern = "\((\d+)\)"
|
||||||
Private Shared _indexRegex As Regex = New Regex(_indexPattern)
|
Private Shared _indexRegex As New Regex(_indexPattern)
|
||||||
|
|
||||||
Public Shared Function GetPropValue(Obj As Object, PropertyName As String)
|
Public Shared Function GetPropValues(Obj As Object, PropertyName As String)
|
||||||
|
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Shared Function GetPropValue(Obj As Object, PropertyName As String, Optional ReturnWhenEmpty As Boolean = True)
|
||||||
Dim oNameParts As String() = PropertyName.Split("."c)
|
Dim oNameParts As String() = PropertyName.Split("."c)
|
||||||
Dim oIndexReplaceRegex = "\(\d+\)"
|
|
||||||
|
|
||||||
If IsNothing(Obj) Then
|
If IsNothing(Obj) Then
|
||||||
Return Nothing
|
Return Nothing
|
||||||
@ -34,15 +38,33 @@ Public Class PropertyValues
|
|||||||
Return Nothing
|
Return Nothing
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Obj = oInfo.GetValue(Obj, Nothing)
|
If IsNothing(oInfo.GetValue(Obj, Nothing)) Then
|
||||||
|
|
||||||
If IsNothing(Obj) Then
|
|
||||||
Return Nothing
|
Return Nothing
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
Obj = oInfo.GetValue(Obj, Nothing)
|
||||||
|
|
||||||
If oHasIndex Then
|
If oHasIndex Then
|
||||||
Obj = Obj(0)
|
Obj = Obj(0)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
If IsArray(Obj) And Not oHasIndex Then
|
||||||
|
Dim oCurrentPart = oPart
|
||||||
|
Dim oPathFragment = PropertyName.
|
||||||
|
Split(New String() {"." & oCurrentPart & "."}, StringSplitOptions.None)
|
||||||
|
|
||||||
|
Dim oResults As New List(Of Object)
|
||||||
|
|
||||||
|
For Each oArrayItem In Obj
|
||||||
|
Dim oResult = GetPropValue(oArrayItem, oPathFragment(1), ReturnWhenEmpty:=False)
|
||||||
|
|
||||||
|
If Not IsNothing(oResult) Then
|
||||||
|
oResults.Add(oResult)
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
|
||||||
|
Return oResults
|
||||||
|
End If
|
||||||
Next
|
Next
|
||||||
|
|
||||||
Return Obj
|
Return Obj
|
||||||
@ -67,6 +89,4 @@ Public Class PropertyValues
|
|||||||
Private Shared Function HasIndex(Prop As String) As Boolean
|
Private Shared Function HasIndex(Prop As String) As Boolean
|
||||||
Return Regex.IsMatch(Prop, _indexPattern)
|
Return Regex.IsMatch(Prop, _indexPattern)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
|
|
||||||
End Class
|
End Class
|
||||||
|
|||||||
@ -2,4 +2,6 @@
|
|||||||
Public TableName As String
|
Public TableName As String
|
||||||
Public Description As String
|
Public Description As String
|
||||||
Public IsRequired As Boolean
|
Public IsRequired As Boolean
|
||||||
|
Public IsGrouped As Boolean
|
||||||
|
Public GroupScope As String
|
||||||
End Class
|
End Class
|
||||||
@ -118,6 +118,7 @@
|
|||||||
<Reference Include="System.ServiceModel" />
|
<Reference Include="System.ServiceModel" />
|
||||||
<Reference Include="System.Transactions" />
|
<Reference Include="System.Transactions" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
|
<Reference Include="System.XML.Linq" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
Loading…
x
Reference in New Issue
Block a user