Jobs: Add exception for unsupported zugferd documents
This commit is contained in:
@@ -89,10 +89,10 @@ Public Class ZUGFeRDInterface
|
||||
''' </summary>
|
||||
''' <param name="Path"></param>
|
||||
''' <exception cref="ZUGFeRDExecption"></exception>
|
||||
Public Function ExtractZUGFeRDFileWithGDPicture(Path As String) As Object
|
||||
Public Function ExtractZUGFeRDFileWithGDPicture(Path As String) As Tuple(Of String, Object)
|
||||
Dim oXmlDocument = ValidateZUGFeRDFileWithGDPicture(Path)
|
||||
|
||||
If IsNothing(oXmlDocument) Then
|
||||
If IsNothing(oXmlDocument.Item2) Then
|
||||
Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.")
|
||||
End If
|
||||
|
||||
@@ -104,10 +104,10 @@ Public Class ZUGFeRDInterface
|
||||
''' </summary>
|
||||
''' <param name="Stream"></param>
|
||||
''' <exception cref="ZUGFeRDExecption"></exception>
|
||||
Public Function ExtractZUGFeRDFileWithGDPicture(Stream As Stream) As Object
|
||||
Public Function ExtractZUGFeRDFileWithGDPicture(Stream As Stream) As Tuple(Of String, Object)
|
||||
Dim oXmlDocument = ValidateZUGFeRDFileWithGDPicture(Stream)
|
||||
|
||||
If IsNothing(oXmlDocument) Then
|
||||
If IsNothing(oXmlDocument.Item2) Then
|
||||
Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei.")
|
||||
End If
|
||||
|
||||
@@ -120,7 +120,7 @@ Public Class ZUGFeRDInterface
|
||||
''' <param name="pStream"></param>
|
||||
''' <exception cref="ZUGFeRDExecption"></exception>
|
||||
''' <returns>The embedded xml data as an XPath document</returns>
|
||||
Public Function ValidateZUGFeRDFileWithGDPicture(pStream As Stream) As XPathDocument
|
||||
Public Function ValidateZUGFeRDFileWithGDPicture(pStream As Stream) As Tuple(Of String, XPathDocument)
|
||||
Dim oEmbedExtractor = New PDFEmbeds(_logConfig)
|
||||
|
||||
Try
|
||||
@@ -148,7 +148,7 @@ Public Class ZUGFeRDInterface
|
||||
''' <param name="pPath"></param>
|
||||
''' <exception cref="ZUGFeRDExecption"></exception>
|
||||
''' <returns>The embedded xml data as an XPath document</returns>
|
||||
Public Function ValidateZUGFeRDFileWithGDPicture(pPath As String) As XPathDocument
|
||||
Public Function ValidateZUGFeRDFileWithGDPicture(pPath As String) As Tuple(Of String, XPathDocument)
|
||||
Dim oEmbedExtractor = New PDFEmbeds(_logConfig)
|
||||
|
||||
Try
|
||||
@@ -170,9 +170,7 @@ Public Class ZUGFeRDInterface
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Private Function HandleEmbeddedFiles(pResults As List(Of PDFEmbeds.EmbeddedFile)) As XPathDocument
|
||||
Dim oXmlDocument As XPathDocument
|
||||
|
||||
Private Function HandleEmbeddedFiles(pResults As List(Of PDFEmbeds.EmbeddedFile)) As Tuple(Of String, XPathDocument)
|
||||
If pResults Is Nothing Then
|
||||
Throw New ZUGFeRDExecption(ErrorType.NoZugferd, "Datei ist keine ZUGFeRD Datei, weil die Attachments nicht gelesen werden konnten.")
|
||||
End If
|
||||
@@ -183,7 +181,7 @@ Public Class ZUGFeRDInterface
|
||||
|
||||
' Find the first file which filename matches the valid filenames for embedded invoice files
|
||||
Dim oValidResult As PDFEmbeds.EmbeddedFile = pResults.
|
||||
Where(Function(result) ValidFilenames.Contains(result.FileName.ToUpper)).
|
||||
Where(Function(f) ValidFilenames.Contains(f.FileName.ToUpper)).
|
||||
FirstOrDefault()
|
||||
|
||||
If oValidResult Is Nothing Then
|
||||
@@ -193,19 +191,18 @@ Public Class ZUGFeRDInterface
|
||||
' Search the embedded files for the ones which are allowed as per the configuration.
|
||||
' The config might say, allow ZUGFeRD but not Factur-X.
|
||||
Dim oAllowedResult As PDFEmbeds.EmbeddedFile = pResults.
|
||||
Where(Function(result) AllowedFilenames.Contains(result.FileName.ToUpper)).
|
||||
Where(Function(f) AllowedFilenames.Contains(f.FileName.ToUpper)).
|
||||
FirstOrDefault()
|
||||
|
||||
If oAllowedResult Is Nothing Then
|
||||
Throw New ZUGFeRDExecption(ErrorType.UnsupportedFormat, "Datei ist eine ZUGFeRD Datei, aber das Format wird nicht unterstützt.")
|
||||
Throw New ZUGFeRDExecption(ErrorType.UnsupportedFormat, "Datei ist eine ZUGFeRD Datei, aber das Format wird nicht unterstützt.", oAllowedResult.FileName)
|
||||
End If
|
||||
|
||||
Try
|
||||
Using oStream As New MemoryStream(oAllowedResult.FileContents)
|
||||
oXmlDocument = New XPathDocument(oStream)
|
||||
Return New Tuple(Of String, XPathDocument)(oAllowedResult.FileName, New XPathDocument(oStream))
|
||||
End Using
|
||||
|
||||
Return oXmlDocument
|
||||
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.
|
||||
@@ -217,9 +214,9 @@ Public Class ZUGFeRDInterface
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Public Function SerializeZUGFeRDDocument(pDocument As XPathDocument) As Object
|
||||
Public Function SerializeZUGFeRDDocument(pDocument As Tuple(Of String, XPathDocument)) As Tuple(Of String, Object)
|
||||
Try
|
||||
Dim oNavigator As XPathNavigator = pDocument.CreateNavigator()
|
||||
Dim oNavigator As XPathNavigator = pDocument.Item2.CreateNavigator()
|
||||
Dim oReader As XmlReader
|
||||
Dim oResult = Nothing
|
||||
|
||||
|
||||
Reference in New Issue
Block a user