Modules.Jobs: MIME-Typen (pdf, xlsx, odt) - Fehlerhandling ergänzt, wenn Dateien nicht erstellt werden können.
This commit is contained in:
parent
04a408ab97
commit
717909d7e8
@ -28,6 +28,10 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Private Const DIRECTORY_DONT_MOVE = "DIRECTORY_DONT_MOVE"
|
||||
|
||||
Private Const MIME_TYPE_PDF = "application/pdf"
|
||||
Private Const MIME_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
Private Const MIME_TYPE_ODT = "application/vnd.oasis.opendocument.spreadsheet"
|
||||
|
||||
' List of allowed extensions for PDF/A Attachments
|
||||
' This list should not contain xml so the zugferd xml file will be filtered out
|
||||
Private ReadOnly AllowedExtensions As New List(Of String) From {"docx", "doc", "pdf", "xls", "xlsx", "ppt", "pptx", "txt"}
|
||||
@ -41,14 +45,16 @@ Public Class ImportZUGFeRDFiles
|
||||
' Allowed Values are:
|
||||
'- application/pdf
|
||||
'- application/vnd.openxmlformats-officedocument.spreadsheetml.sheet (xlsx)
|
||||
'- application/vnd.oasis.opendocument.spreadsheet
|
||||
'- application/vnd.oasis.opendocument.spreadsheet (odt)
|
||||
'- image/jpeg
|
||||
'- image/png
|
||||
'- image/tiff (UBL)
|
||||
'- text/csv
|
||||
'- text/xml (UBL)
|
||||
Private ReadOnly AllowedMimeTypesInEmbeddedFiles As List(Of String) = New List(Of String) From {
|
||||
"application/pdf", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
MIME_TYPE_PDF,
|
||||
MIME_TYPE_XLSX,
|
||||
MIME_TYPE_ODT
|
||||
}
|
||||
|
||||
Private ReadOnly _logger As Logger
|
||||
@ -806,12 +812,16 @@ Public Class ImportZUGFeRDFiles
|
||||
pProcessFileResult.EmailAttachmentFiles.Add(New FileInfo(embeddedFilePath))
|
||||
Else
|
||||
_logger.Error("Could not save File to Disk!")
|
||||
Return False
|
||||
Dim oReasonString = "Could not save file " + newAttachmentFilename + " to disk."
|
||||
AddRejectedState(pMessageId, oReasonString, "EMBEDDED FILE CONSISTENCY NOT OK", "Info GUI", pConnections.SQLServerTransaction)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If TestFileOnDisk(embeddedFilePath, oMimeCodeString) = False Then
|
||||
_logger.Error("Could not save File to Disk!")
|
||||
Return False
|
||||
Dim oReasonString = "Validation of file " + newAttachmentFilename + " on disk was NOT succesfully."
|
||||
AddRejectedState(pMessageId, oReasonString, "EMBEDDED FILE CONSISTENCY NOT OK", "Info GUI", pConnections.SQLServerTransaction)
|
||||
Continue For
|
||||
End If
|
||||
|
||||
If InsertAttachmentHistoryEntry(pMessageId, oOrgFilename, embeddedFilePath) = False Then
|
||||
@ -832,7 +842,7 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Private Function TestFileOnDisk(pEmbeddedFilePath As String, pMimeCodeString As String) As Boolean
|
||||
Try
|
||||
If pMimeCodeString = "application/pdf" Then
|
||||
If pMimeCodeString = MIME_TYPE_PDF Then
|
||||
Dim oGdPicturePDF As New GdPicturePDF
|
||||
Dim oStatus As GdPictureStatus = oGdPicturePDF.LoadFromFile(pEmbeddedFilePath, True)
|
||||
If oStatus <> GdPictureStatus.OK Then
|
||||
@ -864,11 +874,11 @@ Public Class ImportZUGFeRDFiles
|
||||
End If
|
||||
|
||||
Select Case pMimeTypeValue.ToLower()
|
||||
Case "application/pdf"
|
||||
Case MIME_TYPE_PDF
|
||||
Return "pdf"
|
||||
Case "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
||||
Case MIME_TYPE_XLSX
|
||||
Return "xlsx"
|
||||
Case "application/vnd.oasis.opendocument.spreadsheet"
|
||||
Case MIME_TYPE_ODT
|
||||
Return "odt"
|
||||
Case "image/jpeg"
|
||||
Return "jpg"
|
||||
@ -971,18 +981,20 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
|
||||
''' <summary>
|
||||
''' Speichere base64 als Datei auf der Platte ab
|
||||
''' Speichere base64 als Datei auf der Platte ab.
|
||||
''' </summary>
|
||||
Private Function SaveBase64ToDisk(pExportFilePath As String, pBase64String As String) As Boolean
|
||||
|
||||
Try
|
||||
Dim base64BinaryDataString As String = pBase64String ' Hier Base64-String einfügen
|
||||
Dim binaryDataString As Byte() = Convert.FromBase64String(base64BinaryDataString)
|
||||
Dim oFilename As String = pExportFilePath
|
||||
' Using verwenden, um blockieren des PDF zu verhindern
|
||||
Using Stream As FileStream = New FileStream(oFilename, FileMode.Create)
|
||||
Stream.Write(binaryDataString, 0, binaryDataString.Length)
|
||||
Stream.Close()
|
||||
Dim base64BinaryDataString As String = pBase64String
|
||||
Dim binaryDataString As Byte() = Convert.FromBase64String(base64BinaryDataString)
|
||||
|
||||
' Using verwenden, um blockieren der Datei zu verhindern
|
||||
Using fs = New FileStream(oFilename, FileMode.Create, FileAccess.ReadWrite)
|
||||
fs.Write(binaryDataString, 0, binaryDataString.Length)
|
||||
fs.Flush()
|
||||
fs.Close()
|
||||
End Using
|
||||
|
||||
Return True
|
||||
@ -1174,6 +1186,15 @@ Public Class ImportZUGFeRDFiles
|
||||
_logger.Warn("Step [{0}] with SQL [{1}] was not successful.", oStep, oDelSQL)
|
||||
End Try
|
||||
|
||||
Try
|
||||
oDelSQL = $"DELETE FROM TBEDMI_ITEM_FILES where REFERENCE_GUID = '{pMessageId}'"
|
||||
oStep = "TBEDMI_ITEM_FILES Delete MessageID Items"
|
||||
Dim retValue As Boolean = _mssql.ExecuteNonQueryWithConnectionObject(oDelSQL, pConnections.SQLServerConnection, MSSQLServer.TransactionMode.ExternalTransaction, pConnections.SQLServerTransaction)
|
||||
Return retValue
|
||||
Catch ex As Exception
|
||||
_logger.Warn("Step [{0}] with SQL [{1}] was not successful.", oStep, oDelSQL)
|
||||
End Try
|
||||
|
||||
Return False
|
||||
End Function
|
||||
|
||||
@ -1197,6 +1218,10 @@ Public Class ImportZUGFeRDFiles
|
||||
Return True
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Fügt neue Datensätze in Tabelle TBEMLP_HISTORY_STATE ein,
|
||||
''' per Prozedur DD_ECM.[dbo].[PRCUST_ADD_HISTORY_STATE]
|
||||
''' </summary>
|
||||
Private Sub AddRejectedState(pMessageID As String, pTitle As String, pTitle1 As String, pComment As String, pTransaction As SqlTransaction)
|
||||
Try
|
||||
'PRCUST_ADD_HISTORY_STATE: @MessageID VARCHAR(250), @TITLE1 VARCHAR(250), @TITLE2 VARCHAR(250)
|
||||
@ -1206,4 +1231,5 @@ Public Class ImportZUGFeRDFiles
|
||||
_logger.Error(ex)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user