From c1018d176eaee06c18daaa71aa04b41326c73e29 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 12 Jan 2023 14:33:54 +0100 Subject: [PATCH] ZUGFeRD: Update for new version --- Interfaces/My Project/Settings.Designer.vb | 2 +- Interfaces/ZUGFeRDInterface.vb | 48 +++++++++++++------ Interfaces/ZUGFeRDInterface/PropertyValues.vb | 21 ++++---- Jobs/My Project/Settings.Designer.vb | 38 ++++++++------- Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb | 2 +- 5 files changed, 66 insertions(+), 45 deletions(-) diff --git a/Interfaces/My Project/Settings.Designer.vb b/Interfaces/My Project/Settings.Designer.vb index e383b12a..2264521b 100644 --- a/Interfaces/My Project/Settings.Designer.vb +++ b/Interfaces/My Project/Settings.Designer.vb @@ -15,7 +15,7 @@ Option Explicit On Namespace My _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase diff --git a/Interfaces/ZUGFeRDInterface.vb b/Interfaces/ZUGFeRDInterface.vb index 4c10aa50..ff2a22b6 100644 --- a/Interfaces/ZUGFeRDInterface.vb +++ b/Interfaces/ZUGFeRDInterface.vb @@ -4,6 +4,7 @@ Imports System.Xml.Serialization Imports System.Xml.XPath Imports System.Xml.Xsl Imports DigitalData.Modules.Interfaces.Exceptions +Imports DigitalData.Modules.Interfaces.ZUGFeRD Imports DigitalData.Modules.Logging Imports GdPicture14 @@ -108,9 +109,9 @@ Public Class ZUGFeRDInterface Public Function ExtractZUGFeRDFileWithGDPicture(Path As String) As ZugferdResult Dim oResult = ValidateZUGFeRDFileWithGDPicture(Path) - If IsNothing(oResult.SchemaObject) Then - Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.") - End If + 'If IsNothing(oResult.SchemaObject) Then + ' Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.") + 'End If Return SerializeZUGFeRDDocument(oResult) End Function @@ -123,9 +124,9 @@ Public Class ZUGFeRDInterface Public Function ExtractZUGFeRDFileWithGDPicture(Stream As Stream) As ZugferdResult Dim oResult = ValidateZUGFeRDFileWithGDPicture(Stream) - If IsNothing(oResult.SchemaObject) Then - Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.") - End If + 'If IsNothing(oResult.SchemaObject) Then + ' Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.") + 'End If Return SerializeZUGFeRDDocument(oResult) End Function @@ -233,6 +234,11 @@ Public Class ZUGFeRDInterface End Try End Function + Private Class AllowedType + Public SchemaType As Type + Public Specification As String + End Class + Public Function SerializeZUGFeRDDocument(pResult As ZugferdResult) As ZugferdResult Try Dim oNavigator As XPathNavigator = pResult.XPathObject.CreateNavigator() @@ -241,28 +247,42 @@ Public Class ZUGFeRDInterface Dim oObject As Object = Nothing Dim oSpecification As String = Nothing - Dim oAllowedTypes As New Dictionary(Of String, Type) + Dim oAllowedTypes As New List(Of AllowedType) If _Options.AllowZugferd_1_0_Schema Then - oAllowedTypes.Add(ZUGFERD_SPEC_10, GetType(ZUGFeRD.Version1_0.CrossIndustryDocumentType)) + oAllowedTypes.Add(New AllowedType With { + .SchemaType = GetType(Version1_0.CrossIndustryDocumentType), + .Specification = ZUGFERD_SPEC_10 + }) End If If _Options.AllowZugferd_2_x_Schema Then - oAllowedTypes.Add(ZUGFERD_SPEC_2x, GetType(ZUGFeRD.Version2_0.CrossIndustryInvoiceType)) - oAllowedTypes.Add(ZUGFERD_SPEC_2x, GetType(ZUGFeRD.Version2_1_1.CrossIndustryInvoiceType)) - oAllowedTypes.Add(ZUGFERD_SPEC_2x, GetType(ZUGFeRD.Version2_2_FacturX.CrossIndustryInvoiceType)) + oAllowedTypes.AddRange(New List(Of AllowedType) From { + New AllowedType With { + .SchemaType = GetType(Version2_0.CrossIndustryInvoiceType), + .Specification = ZUGFERD_SPEC_2x + }, + New AllowedType With { + .SchemaType = GetType(Version2_1_1.CrossIndustryInvoiceType), + .Specification = ZUGFERD_SPEC_2x + }, + New AllowedType With { + .SchemaType = GetType(Version2_2_FacturX.CrossIndustryInvoiceType), + .Specification = ZUGFERD_SPEC_2x + } + }) End If For Each oType In oAllowedTypes - Dim oTypeName As String = oType.Value.FullName - Dim oSerializer As New XmlSerializer(oType.Value) + Dim oTypeName As String = oType.SchemaType.FullName + Dim oSerializer As New XmlSerializer(oType.SchemaType) _logger.Debug("Trying Type [{0}]", oTypeName) Try oReader = oNavigator.ReadSubtree() oObject = oSerializer.Deserialize(oReader) - oSpecification = oType.Key + oSpecification = oType.Specification _logger.Debug("Serializing with type [{0}] succeeded", oTypeName) Exit For diff --git a/Interfaces/ZUGFeRDInterface/PropertyValues.vb b/Interfaces/ZUGFeRDInterface/PropertyValues.vb index 110baacd..2cff2ca6 100644 --- a/Interfaces/ZUGFeRDInterface/PropertyValues.vb +++ b/Interfaces/ZUGFeRDInterface/PropertyValues.vb @@ -24,7 +24,7 @@ Public Class PropertyValues Public TableName As String Public TableColumn As String - Public ISRequired As Boolean + Public IsRequired As Boolean Public GroupCounter As Integer = -1 Public Description As String @@ -99,9 +99,7 @@ Public Class PropertyValues Dim oIsRequired As Boolean = oColumn.Key.IsRequired Dim oPropertyDescription As String = oColumn.Key.Description Dim oRowCounter = oRowIndex + oGlobalGroupCounter + 1 - If IsNothing(oRowCounter) Then - End If ' Returns nothing if oColumn.Value contains an empty list Dim oPropertyValue = oColumn.Value.ElementAtOrDefault(oRowIndex) @@ -127,7 +125,7 @@ Public Class PropertyValues .GroupCounter = oRowCounter, .TableName = oTableName, .TableColumn = oTableColumn, - .ISRequired = oIsRequired + .IsRequired = oIsRequired }) Next Next @@ -139,6 +137,7 @@ Public Class PropertyValues For Each oItem As KeyValuePair(Of String, XmlItemProperty) In oDefaultProperties Dim oPropertyValueList As List(Of Object) Dim oTableColumn As String = oItem.Value.TableColumn + Dim oPropertyDescription As String = oItem.Value.Description Dim oPropertyValue As Object = Nothing Dim oTableName = oItem.Value.TableName Dim oIsRequired = oItem.Value.IsRequired @@ -146,7 +145,7 @@ Public Class PropertyValues Try oPropertyValueList = GetPropValue(Document, oItem.Key) Catch ex As Exception - _logger.Warn("{2} # Unknown error occurred while fetching specification [{0}] in group [{1}]:", oTableColumn, oItem.Value.GroupScope, MessageId) + _logger.Warn("{2} # Unknown error occurred while fetching specification [{0}] in group [{1}]:", oPropertyDescription, oItem.Value.GroupScope, MessageId) _logger.Error(ex) oPropertyValueList = New List(Of Object) End Try @@ -164,24 +163,24 @@ Public Class PropertyValues ' This should hopefully show config errors If TypeOf oPropertyValue Is List(Of Object) Then - _logger.Warn("Item with TableColumn [{0}] may be configured incorrectly", oTableColumn) + _logger.Warn("Item with specification [{0}] may be configured incorrectly", oPropertyDescription) oPropertyValue = Nothing End If End Select End If Catch ex As Exception - _logger.Warn("Unknown error occurred while processing specification [{0}]:", oTableColumn) + _logger.Warn("Unknown error occurred while processing specification [{0}]:", oPropertyDescription) _logger.Error(ex) oPropertyValue = Nothing End Try If IsNothing(oPropertyValue) OrElse String.IsNullOrEmpty(oPropertyValue) Then If oItem.Value.IsRequired Then - _logger.Warn("{0} # Specification [{1}] is empty, but marked as required! Skipping.", MessageId, oTableColumn) - oResult.MissingProperties.Add(oTableColumn) + _logger.Warn("{0} # Specification [{1}] is empty, but marked as required! Skipping.", MessageId, oPropertyDescription) + oResult.MissingProperties.Add(oPropertyDescription) Continue For Else - _logger.Debug("{0} # oPropertyValue for specification [{1}] is empty or not found. Skipping.", MessageId, oTableColumn) + _logger.Debug("{0} # oPropertyValue for specification [{1}] is empty or not found. Skipping.", MessageId, oPropertyDescription) Continue For End If @@ -193,7 +192,7 @@ Public Class PropertyValues .Value = oPropertyValue, .TableName = oTableName, .TableColumn = oTableColumn, - .ISRequired = oIsRequired + .IsRequired = oIsRequired }) Next diff --git a/Jobs/My Project/Settings.Designer.vb b/Jobs/My Project/Settings.Designer.vb index 0d240d08..17aa9d5d 100644 --- a/Jobs/My Project/Settings.Designer.vb +++ b/Jobs/My Project/Settings.Designer.vb @@ -12,15 +12,16 @@ Option Strict On Option Explicit On - - _ -Partial Friend NotInheritable Class Settings - Inherits Global.System.Configuration.ApplicationSettingsBase - - Private Shared defaultInstance As Settings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()),Settings) +Namespace My + _ + Partial Friend NotInheritable Class Settings + Inherits Global.System.Configuration.ApplicationSettingsBase + + Private Shared defaultInstance As Settings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New Settings()),Settings) + #Region "Automatische My.Settings-Speicherfunktion" #If _MyType = "WindowsForms" Then Private Shared addedHandler As Boolean @@ -35,10 +36,10 @@ Partial Friend NotInheritable Class Settings End Sub #End If #End Region - - Public Shared ReadOnly Property [Default]() As Settings - Get - + + Public Shared ReadOnly Property [Default]() As Settings + Get + #If _MyType = "WindowsForms" Then If Not addedHandler Then SyncLock addedHandlerLockObject @@ -49,10 +50,11 @@ Partial Friend NotInheritable Class Settings End SyncLock End If #End If - Return defaultInstance - End Get - End Property -End Class + Return defaultInstance + End Get + End Property + End Class +End Namespace Namespace My @@ -62,9 +64,9 @@ Namespace My Friend Module MySettingsProperty _ - Friend ReadOnly Property Settings() As Global.DigitalData.Modules.Jobs.Settings + Friend ReadOnly Property Settings() As Global.DigitalData.Modules.Jobs.My.Settings Get - Return Global.DigitalData.Modules.Jobs.Settings.Default + Return Global.DigitalData.Modules.Jobs.My.Settings.Default End Get End Property End Module diff --git a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb index 88b98b26..00fd4714 100644 --- a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -328,7 +328,7 @@ Public Class ImportZUGFeRDFiles End If Dim oCommand = $"INSERT INTO {oProperty.TableName} (REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, GROUP_COUNTER,SPEC_NAME,IS_REQUIRED) VALUES - ('{oMessageId}', '{oProperty.Description}', '{oProperty.Value.Replace("'", "''")}', {oGroupCounterValue},'{oProperty.TableColumn}','{oProperty.ISRequired}')" + ('{oMessageId}', '{oProperty.Description}', '{oProperty.Value.Replace("'", "''")}', {oGroupCounterValue},'{oProperty.TableColumn}','{oProperty.IsRequired}')" _logger.Debug("Mapping Property [{0}] with value [{1}], Will be inserted into table [{2}]", oProperty.TableColumn, oProperty.Value.Replace("'", "''"), oProperty.TableName) ' Insert into SQL Server If oArgs.InsertIntoSQLServer = True Then