diff --git a/GUIs.Test.ZUGFeRDTest/Form1.vb b/GUIs.Test.ZUGFeRDTest/Form1.vb
index f1e33f84..00691c15 100644
--- a/GUIs.Test.ZUGFeRDTest/Form1.vb
+++ b/GUIs.Test.ZUGFeRDTest/Form1.vb
@@ -167,7 +167,7 @@ Public Class Form1
End Sub
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
- Dim oExtractor = New PDFAttachments(_logConfig)
+ Dim oExtractor = New PDFEmbeds(_logConfig)
Dim oResult = OpenFileDialog1.ShowDialog()
If oResult = DialogResult.OK Then
diff --git a/Modules.Interfaces/Interfaces.vbproj b/Modules.Interfaces/Interfaces.vbproj
index 4865f507..179500e7 100644
--- a/Modules.Interfaces/Interfaces.vbproj
+++ b/Modules.Interfaces/Interfaces.vbproj
@@ -112,7 +112,7 @@
-
+
diff --git a/Modules.Interfaces/ZUGFeRDInterface.vb b/Modules.Interfaces/ZUGFeRDInterface.vb
index fa0df194..56297e10 100644
--- a/Modules.Interfaces/ZUGFeRDInterface.vb
+++ b/Modules.Interfaces/ZUGFeRDInterface.vb
@@ -122,12 +122,21 @@ Public Class ZUGFeRDInterface
End Function
Public Function ValidateZUGFeRDFileWithGDPicture(Stream As Stream) As XPathDocument
- Dim oAttachmentExtractor = New PDFAttachments(_logConfig)
+ Dim oEmbedExtractor = New PDFEmbeds(_logConfig)
Dim oAllowedExtensions = New List(Of String) From {"xml"}
Try
- Dim oResults = oAttachmentExtractor.Extract(Stream, oAllowedExtensions)
- Return HandleAttachments(oResults)
+ Dim oFiles = oEmbedExtractor.Extract(Stream, oAllowedExtensions)
+
+ ' Attachments are in this case the files that are embedded into a pdf file,
+ ' like for example the zugferd-invoice.xml file
+ Return HandleEmbeddedFiles(oFiles)
+
+ 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 ex
@@ -135,23 +144,28 @@ Public Class ZUGFeRDInterface
End Function
Public Function ValidateZUGFeRDFileWithGDPicture(Path As String) As XPathDocument
- Dim oAttachmentExtractor = New PDFAttachments(_logConfig)
+ Dim oEmbedExtractor = New PDFEmbeds(_logConfig)
Dim oAllowedExtensions = New List(Of String) From {"xml"}
Try
- Dim oResults = oAttachmentExtractor.Extract(Path, oAllowedExtensions)
- Return HandleAttachments(oResults)
+ Dim oFiles = oEmbedExtractor.Extract(Path, oAllowedExtensions)
+
+ ' Attachments are in this case the files that are embedded into a pdf file,
+ ' like for example the zugferd-invoice.xml file
+ Return HandleEmbeddedFiles(oFiles)
+
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 ex
End Try
End Function
- Private Function HandleAttachments(Results As List(Of PDFAttachments.AttachmentResult)) As XPathDocument
+ Private Function HandleEmbeddedFiles(Results As List(Of PDFEmbeds.EmbeddedFile)) As XPathDocument
Dim oXmlDocument As XPathDocument
If Results Is Nothing Then
@@ -163,10 +177,10 @@ Public Class ZUGFeRDInterface
End If
Dim oFound As Boolean = False
- Dim oFoundResult As PDFAttachments.AttachmentResult = Nothing
+ Dim oFoundResult As PDFEmbeds.EmbeddedFile = Nothing
For Each oResult In Results
- If oResult.FileName.ToUpper() = PDFAttachments.ZUGFERD_XML_FILENAME.ToUpper() Then
+ If oResult.FileName.ToUpper() = PDFEmbeds.ZUGFERD_XML_FILENAME.ToUpper() Then
oFound = True
oFoundResult = oResult
End If
@@ -186,9 +200,10 @@ Public Class ZUGFeRDInterface
' 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 ex
+ Throw New ZUGFeRDExecption(ErrorType.NoValidZugferd, "Datei ist eine ungültige ZUGFeRD Datei.")
End Try
End Function
diff --git a/Modules.Interfaces/ZUGFeRDInterface/PDFAttachments.vb b/Modules.Interfaces/ZUGFeRDInterface/PDFEmbeds.vb
similarity index 91%
rename from Modules.Interfaces/ZUGFeRDInterface/PDFAttachments.vb
rename to Modules.Interfaces/ZUGFeRDInterface/PDFEmbeds.vb
index 0e81c1c8..9e82e5ac 100644
--- a/Modules.Interfaces/ZUGFeRDInterface/PDFAttachments.vb
+++ b/Modules.Interfaces/ZUGFeRDInterface/PDFEmbeds.vb
@@ -3,12 +3,12 @@ Imports System.IO
Imports DigitalData.Modules.Logging
Imports GdPicture14
-Public Class PDFAttachments
+Public Class PDFEmbeds
Private ReadOnly Logger As Logger
Public Const ZUGFERD_XML_FILENAME = "ZUGFeRD-invoice.xml"
- Public Class AttachmentResult
+ Public Class EmbeddedFile
Public FileName As String
Public FileContents As Byte()
End Class
@@ -23,8 +23,8 @@ Public Class PDFAttachments
'''
''' Filepath of the pdf
''' List of allowed extensions to be extracted
- Public Function Extract(FilePath As String, AllowedExtensions As List(Of String)) As List(Of AttachmentResult)
- Dim oResults As New List(Of AttachmentResult)
+ Public Function Extract(FilePath As String, AllowedExtensions As List(Of String)) As List(Of EmbeddedFile)
+ Dim oFile As New List(Of EmbeddedFile)
Dim oExtensions = AllowedExtensions.ConvertAll(New Converter(Of String, String)(Function(ext) ext.ToUpper))
Logger.Debug("Extracting embedded files from [{0}]", FilePath)
@@ -32,14 +32,14 @@ Public Class PDFAttachments
Try
Using oGDPicturePDF As New GdPicturePDF()
If oGDPicturePDF.LoadFromFile(FilePath, False) = GdPictureStatus.OK Then
- oResults = DoExtract(oGDPicturePDF, oExtensions)
+ oFile = DoExtract(oGDPicturePDF, oExtensions)
Else
Dim oMessage = String.Format("The file [{0}] can't be loaded. Status: [{1}]", FilePath, oGDPicturePDF.GetStat().ToString())
Throw New ApplicationException(oMessage)
End If
End Using
- Return oResults
+ Return oFile
Catch ex As Exception
Logger.Warn("Unexpected Error while Extracting attachments from File [{0}]", FilePath)
Logger.Error(ex)
@@ -53,8 +53,8 @@ Public Class PDFAttachments
'''
''' Filestream of the pdf
''' List of allowed extensions to be extracted
- Public Function Extract(Stream As Stream, AllowedExtensions As List(Of String)) As List(Of AttachmentResult)
- Dim oResults As New List(Of AttachmentResult)
+ Public Function Extract(Stream As Stream, AllowedExtensions As List(Of String)) As List(Of EmbeddedFile)
+ Dim oResults As New List(Of EmbeddedFile)
Dim oExtensions = AllowedExtensions.ConvertAll(New Converter(Of String, String)(Function(ext) ext.ToUpper))
Logger.Debug("Extracting embedded files from stream")
@@ -77,8 +77,8 @@ Public Class PDFAttachments
End Try
End Function
- Private Function DoExtract(GDPicturePDF As GdPicturePDF, pExtensions As List(Of String)) As List(Of AttachmentResult)
- Dim oResults As New List(Of AttachmentResult)
+ Private Function DoExtract(GDPicturePDF As GdPicturePDF, pExtensions As List(Of String)) As List(Of EmbeddedFile)
+ Dim oResults As New List(Of EmbeddedFile)
Dim oEmbeddedFileCount As Integer = GDPicturePDF.GetEmbeddedFileCount()
If GDPicturePDF.GetStat() = GdPictureStatus.OK Then
@@ -104,7 +104,7 @@ Public Class PDFAttachments
If oStatus = GdPictureStatus.OK Then
Logger.Debug("Embedded file [{0}] extracted sucessfully!", oFileName)
- oResults.Add(New AttachmentResult() With {
+ oResults.Add(New EmbeddedFile() With {
.FileContents = oFileData,
.FileName = oFileName
})
diff --git a/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb b/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb
index 8909546c..30105d97 100644
--- a/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb
+++ b/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb
@@ -124,7 +124,7 @@ Public Class ImportZUGFeRDFiles
Public Sub Start(Arguments As Object) Implements IJob.Start
Dim oArgs As WorkerArgs = Arguments
Dim oPropertyExtractor = New PropertyValues(_logConfig)
- Dim oAttachmentExtractor = New PDFAttachments(_logConfig)
+ Dim oAttachmentExtractor = New PDFEmbeds(_logConfig)
_logger.Debug("Starting Job {0}", [GetType].Name)
@@ -172,7 +172,7 @@ Public Class ImportZUGFeRDFiles
' Create file lists
Dim oFileGroupFiles As List(Of FileInfo) = oFileGroup.Value
Dim oEmailAttachmentFiles As New List(Of FileInfo)
- Dim oEmbeddedAttachmentFiles As New List(Of PDFAttachments.AttachmentResult)
+ Dim oEmbeddedAttachmentFiles As New List(Of PDFEmbeds.EmbeddedFile)
Dim oMessageId As String = oFileGroup.Key
Dim oMissingProperties As New List(Of String)
@@ -462,7 +462,7 @@ Public Class ImportZUGFeRDFiles
MessageId As String,
Files As List(Of FileInfo),
AttachmentFiles As List(Of FileInfo),
- EmbeddedAttachments As List(Of PDFAttachments.AttachmentResult),
+ EmbeddedAttachments As List(Of PDFEmbeds.EmbeddedFile),
MoveDirectory As String,
IsSuccess As Boolean)