Modules.Interfaces & Modules.Jobs: Verarbeitung von XML-Belegen im ZUGFeRD Service implementiert

This commit is contained in:
2025-01-28 14:21:01 +01:00
parent 954df832ed
commit 3e2606a582
2 changed files with 165 additions and 46 deletions

View File

@@ -1,7 +1,9 @@
Imports System.IO
Imports System.Reflection
Imports System.Xml
Imports System.Xml.Serialization
Imports DigitalData.Modules.Interfaces.Exceptions
Imports DigitalData.Modules.Interfaces.PDFEmbeds
Imports DigitalData.Modules.Interfaces.Peppol
Imports DigitalData.Modules.Interfaces.ZUGFeRD
Imports DigitalData.Modules.Logging
@@ -138,6 +140,44 @@ Public Class ZUGFeRDInterface
End If
End Function
Public Function GetSerializedXMLContentFromFile(oFileInfo As FileInfo) As ZugferdResult
Dim oResult = New ZugferdResult()
Try
Dim oFileSize As Integer = oFileInfo.Length
Dim oFileData As Byte() = File.ReadAllBytes(oFileInfo.FullName)
Dim oXmlFile As EmbeddedFile = New EmbeddedFile() With {
.FileName = oFileInfo.Name,
.FileContents = oFileData
}
Using oStream As New MemoryStream(oXmlFile.FileContents)
oResult = New ZugferdResult With {
.DataFileName = oXmlFile.FileName,
.XElementObject = XElement.Load(oStream)
}
End Using
Catch ex As ZUGFeRDExecption
' Don't log ZUGFeRD Exceptions here, they should be handled by the calling code.
' It also produces misleading error messages when checking if an attachment is a zugferd file.
Throw ex
Catch ex As Exception
_logger.Error(ex)
Throw New ZUGFeRDExecption(ErrorType.NoValidZugferd, "Datei ist eine ungültige XML Datei.")
End Try
If oResult.ValidationErrors.Any() Then
Throw New ValidationException() With {
.ValidationErrors = oResult.ValidationErrors
}
End If
Return SerializeZUGFeRDDocument(oResult)
End Function
''' <summary>
''' Validates a ZUGFeRD File and extracts the XML Document from it
''' </summary>