Interfaces: Rename PDFAttachments to PDFEmbeds, also throw zugferd exception when zugferd-invoice.xml could not be parsed

This commit is contained in:
Jonathan Jenne
2021-04-14 11:12:05 +02:00
parent ec986a36f2
commit 1c00cb9fc6
5 changed files with 41 additions and 26 deletions

View File

@@ -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
''' </summary>
''' <param name="FilePath">Filepath of the pdf</param>
''' <param name="AllowedExtensions">List of allowed extensions to be extracted</param>
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
''' </summary>
''' <param name="Stream">Filestream of the pdf</param>
''' <param name="AllowedExtensions">List of allowed extensions to be extracted</param>
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
})