Interfaces: Support ZUGFeRD 1.0 - 2.1.1
This commit is contained in:
@@ -11,9 +11,6 @@ Public Class ZUGFeRDInterface
|
||||
Private _logConfig As LogConfig
|
||||
Private _logger As Logger
|
||||
|
||||
Private Const ZUGFERD_CONVERTER_EXE = "ZUGFeRDInterface\pdf_zugferd_test.exe" 'ZUGFeRDInterface\pdf_zugferd_lib\pdf_zugferd_test.exe
|
||||
Private Const ZUGFERD_CONVERTER_SUCCESS_MESSAGE = "Document contains ZUGFeRD data."
|
||||
|
||||
Public Enum ErrorType
|
||||
NoValidFile
|
||||
NoZugferd
|
||||
@@ -46,7 +43,7 @@ Public Class ZUGFeRDInterface
|
||||
''' <param name="Path"></param>
|
||||
''' <exception cref="ZUGFeRDExecption"></exception>
|
||||
''' <returns></returns>
|
||||
Public Function ExtractZUGFeRDFileWithGDPicture(Path As String) As CrossIndustryDocumentType
|
||||
Public Function ExtractZUGFeRDFileWithGDPicture(Path As String) As Object
|
||||
Dim oXmlDocument = ValidateZUGFeRDFileWithGDPicture(Path)
|
||||
|
||||
If IsNothing(oXmlDocument) Then
|
||||
@@ -62,7 +59,7 @@ Public Class ZUGFeRDInterface
|
||||
''' <param name="Stream"></param>
|
||||
''' <exception cref="ZUGFeRDExecption"></exception>
|
||||
''' <returns></returns>
|
||||
Public Function ExtractZUGFeRDFileWithGDPicture(Stream As Stream) As CrossIndustryDocumentType
|
||||
Public Function ExtractZUGFeRDFileWithGDPicture(Stream As Stream) As Object
|
||||
Dim oXmlDocument = ValidateZUGFeRDFileWithGDPicture(Stream)
|
||||
|
||||
If IsNothing(oXmlDocument) Then
|
||||
@@ -164,16 +161,45 @@ Public Class ZUGFeRDInterface
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function SerializeZUGFeRDDocument(Document As XPathDocument) As CrossIndustryDocumentType
|
||||
Public Function SerializeZUGFeRDDocument(Document As XPathDocument) As Object
|
||||
Try
|
||||
Dim oNavigator As XPathNavigator = Document.CreateNavigator()
|
||||
Dim oReader = oNavigator.ReadSubtree()
|
||||
Dim oSerializer As New XmlSerializer(GetType(CrossIndustryDocumentType))
|
||||
Dim oReader As XmlReader
|
||||
Dim oResult = Nothing
|
||||
|
||||
Dim oTypes As New List(Of Type) From {
|
||||
GetType(ZUGFeRD.Version1_0.CrossIndustryDocumentType),
|
||||
GetType(ZUGFeRD.Version2_0.CrossIndustryInvoiceType),
|
||||
GetType(ZUGFeRD.Version2_1_1.CrossIndustryInvoiceType)
|
||||
}
|
||||
|
||||
For Each oType In oTypes
|
||||
_logger.Debug("Trying Type [{0}]", oType.FullName)
|
||||
Dim oSerializer As New XmlSerializer(oType)
|
||||
|
||||
Try
|
||||
oReader = oNavigator.ReadSubtree()
|
||||
oResult = oSerializer.Deserialize(oReader)
|
||||
_logger.Debug("Serializing with type [{0}] succeeded", oType.FullName)
|
||||
Exit For
|
||||
Catch ex As Exception
|
||||
_logger.Debug("Serializing with type [{0}] failed", oType.FullName)
|
||||
_logger.Debug(ex.Message)
|
||||
_logger.Error(ex.InnerException?.Message)
|
||||
End Try
|
||||
Next
|
||||
|
||||
If oResult Is Nothing Then
|
||||
Throw New ApplicationException("No Types matched the given document. Document could not be serialized.")
|
||||
End If
|
||||
|
||||
Return oResult
|
||||
|
||||
Return oSerializer.Deserialize(oReader)
|
||||
Catch ex As Exception
|
||||
_logger.Error(ex)
|
||||
Throw New ZUGFeRDExecption(ErrorType.NoValidZugferd, "Datei ist eine ungültige ZUGFeRD Datei.")
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user