diff --git a/Interfaces/ZUGFeRDInterface.vb b/Interfaces/ZUGFeRDInterface.vb
index f991b87d..344d4f01 100644
--- a/Interfaces/ZUGFeRDInterface.vb
+++ b/Interfaces/ZUGFeRDInterface.vb
@@ -89,10 +89,10 @@ Public Class ZUGFeRDInterface
'''
'''
'''
- 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
'''
'''
'''
- 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
'''
'''
''' The embedded xml data as an XPath document
- 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
'''
'''
''' The embedded xml data as an XPath document
- 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
diff --git a/Interfaces/ZUGFeRDInterface/Exceptions.vb b/Interfaces/ZUGFeRDInterface/Exceptions.vb
index db8a0a42..e7de05f0 100644
--- a/Interfaces/ZUGFeRDInterface/Exceptions.vb
+++ b/Interfaces/ZUGFeRDInterface/Exceptions.vb
@@ -4,10 +4,23 @@
Public ReadOnly Property ErrorType() As ZUGFeRDInterface.ErrorType
+ '''
+ ''' Contains the name of the extracted xml file if already extracted.
+ '''
+ ''' A filename like zugferd-invoice.xml
+ Public ReadOnly Property XmlFile As String = String.Empty
+
Public Sub New(ErrorType As ZUGFeRDInterface.ErrorType, Message As String)
MyBase.New(Message)
_ErrorType = ErrorType
End Sub
+
+ Public Sub New(ErrorType As ZUGFeRDInterface.ErrorType, Message As String, pXmlFileName As String)
+ MyBase.New(Message)
+
+ _ErrorType = ErrorType
+ _XmlFile = pXmlFileName
+ End Sub
End Class
End Class
diff --git a/Jobs/Exceptions.vb b/Jobs/Exceptions.vb
index bdd4c341..36400b9f 100644
--- a/Jobs/Exceptions.vb
+++ b/Jobs/Exceptions.vb
@@ -43,8 +43,11 @@ Public Class Exceptions
Public Class UnsupportedFerdException
Inherits ApplicationException
- Public Sub New()
+ Public ReadOnly Property XmlFile As String
+
+ Public Sub New(pXmlFile As String)
MyBase.New("ZUGFeRD document found but is not supported!")
+ _XmlFile = pXmlFile
End Sub
End Class
diff --git a/Jobs/ZUGFeRD/EmailStrings.vb b/Jobs/ZUGFeRD/EmailStrings.vb
index b29e11ea..ed3b1639 100644
--- a/Jobs/ZUGFeRD/EmailStrings.vb
+++ b/Jobs/ZUGFeRD/EmailStrings.vb
@@ -39,6 +39,6 @@
"
Public Const EMAIL_UNSUPPORTED_DOCUMENT = "
-
Ihre Email enthielt ein ZUGFeRD Dokument, welches aber zur Zeit noch nicht unsterstützt wird.
+ Ihre Email enthielt ein ZUGFeRD Dokument ({0}), welches zur Zeit noch nicht unsterstützt wird.
"
End Class
diff --git a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb
index cb09f2aa..54ede22e 100644
--- a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb
+++ b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb
@@ -204,8 +204,10 @@ Public Class ImportZUGFeRDFiles
Try
For Each oFile In oFileGroupFiles
' 09.12.2021: oDocument is now an Object, because have different classes corresponding to the
- ' different versions of ZUGFeRD and the type is unknown at compile-time.
- Dim oDocument As Object
+ ' different versions of ZUGFeRD and the type is unknown at compile-time.
+ ' 17.11.2022: oDocument is now a Tuple of (String, Object), to be able to return the filename
+ ' of the extracted xml file.
+ Dim oDocument As Tuple(Of String, Object)
' Start a global group counter for each file
Dim oGlobalGroupCounter = 0
@@ -245,8 +247,8 @@ Public Class ImportZUGFeRDFiles
Continue For
Case ZUGFeRDInterface.ErrorType.UnsupportedFormat
- _logger.Info("File [{0}] is an unsupported ZUFeRD document format!")
- Throw New UnsupportedFerdException()
+ _logger.Info("File [{0}/{1}] is an unsupported ZUFeRD document format!", oFile.Name, ex.XmlFile)
+ Throw New UnsupportedFerdException(ex.XmlFile)
Case ZUGFeRDInterface.ErrorType.NoValidZugferd
_logger.Warn("File [{0}] is an Incorrectly formatted ZUGFeRD document!", oFile.Name)
@@ -397,7 +399,7 @@ Public Class ImportZUGFeRDFiles
' That 's why we set it to String.Empty here.
Create_HistoryEntry(oMessageId, String.Empty, "REJECTED - ZUGFeRD yes but unsupported format", oFBTransaction)
- Dim oBody = EmailStrings.EMAIL_UNSUPPORTED_DOCUMENT
+ Dim oBody As String = String.Format(EmailStrings.EMAIL_UNSUPPORTED_DOCUMENT, ex.XmlFile)
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "UnsupportedFerdException", _EmailOutAccountId, oArgs.NamePortal)
AddRejectedState(oMessageId, "UnsupportedFerdException", "Nicht unterstütztes Datenformat", "", oSQLTransaction)