ZUGFeRDService: Add config option MaxAttachmentSizeInMegaBytes
This commit is contained in:
@@ -206,11 +206,24 @@ Public Class ImportZUGFeRDFiles
|
||||
If Not oFile.Name.EndsWith(".pdf") Then
|
||||
_logger.Debug("Skipping non-pdf file {0}", oFile.Name)
|
||||
oEmailAttachmentFiles.Add(oFile)
|
||||
|
||||
' Checking filesize for attachment files
|
||||
If Check_FileSize(oFile, oArgs.MaxAttachmentSizeInMegaBytes) = False Then
|
||||
_logger.Warn("Filesize for File [{0}] exceeded limit of {1} MB", oFile.Name, oArgs.MaxAttachmentSizeInMegaBytes)
|
||||
Throw New FileSizeLimitReachedException(oFile.Name, oArgs.MaxAttachmentSizeInMegaBytes)
|
||||
End If
|
||||
|
||||
Continue For
|
||||
End If
|
||||
|
||||
_logger.Info("Start processing file {0}", oFile.Name)
|
||||
|
||||
' Checking filesize for pdf files
|
||||
If Check_FileSize(oFile, oArgs.MaxAttachmentSizeInMegaBytes) = False Then
|
||||
_logger.Warn("Filesize for File [{0}] exceeded limit of {1} MB", oFile.Name, oArgs.MaxAttachmentSizeInMegaBytes)
|
||||
Throw New FileSizeLimitReachedException(oFile.Name, oArgs.MaxAttachmentSizeInMegaBytes)
|
||||
End If
|
||||
|
||||
Try
|
||||
oDocument = _zugferd.ExtractZUGFeRDFileWithGDPicture(oFile.FullName)
|
||||
Catch ex As ZUGFeRDExecption
|
||||
@@ -241,7 +254,7 @@ Public Class ImportZUGFeRDFiles
|
||||
End If
|
||||
|
||||
' Check the Checksum and rejection status
|
||||
oMD5CheckSum = Check_MD5Sum(oFile.FullName, oArgs.IgnoreRejectionStatus)
|
||||
oMD5CheckSum = GenerateAndCheck_MD5Sum(oFile.FullName, oArgs.IgnoreRejectionStatus)
|
||||
|
||||
' Check if there are more than one ZUGFeRD files
|
||||
If oZUGFeRDCount = 1 Then
|
||||
@@ -334,8 +347,6 @@ Public Class ImportZUGFeRDFiles
|
||||
Catch ex As MD5HashException
|
||||
_logger.Error(ex)
|
||||
|
||||
'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = '{oMessage}' WHERE MESSAGE_ID = '{oMessageId}'"
|
||||
'_firebird.ExecuteNonQuery(oSQL, oFBTransaction)
|
||||
Dim oMessage = "REJECTED - Already processed (MD5Hash)"
|
||||
Update_HistoryEntry(oMessageId, oMD5CheckSum, oMessage, oFBTransaction)
|
||||
|
||||
@@ -347,9 +358,6 @@ Public Class ImportZUGFeRDFiles
|
||||
Catch ex As InvalidFerdException
|
||||
_logger.Error(ex)
|
||||
|
||||
'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - ZUGFeRD yes but incorrect format' WHERE GUID = '{HISTORY_ID}'"
|
||||
'_firebird.ExecuteNonQuery(oSQL, oFBTransaction)
|
||||
|
||||
' When InvalidFerdException is thrown, we don't have a MD5Hash yet.
|
||||
' That 's why we set it to String.Empty here.
|
||||
Create_HistoryEntry(oMessageId, String.Empty, "REJECTED - ZUGFeRD yes but incorrect format", oFBTransaction)
|
||||
@@ -362,8 +370,6 @@ Public Class ImportZUGFeRDFiles
|
||||
Catch ex As TooMuchFerdsException
|
||||
_logger.Error(ex)
|
||||
|
||||
'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - More than one ZUGFeRD-document in email' WHERE GUID = '{HISTORY_ID}'"
|
||||
'_firebird.ExecuteNonQuery(oSQL, oFBTransaction)
|
||||
Create_HistoryEntry(oMessageId, oMD5CheckSum, "REJECTED - More than one ZUGFeRD-document in email", oFBTransaction)
|
||||
|
||||
Dim oBody = EmailStrings.EMAIL_TOO_MUCH_FERDS
|
||||
@@ -374,8 +380,6 @@ Public Class ImportZUGFeRDFiles
|
||||
Catch ex As NoFerdsException
|
||||
_logger.Error(ex)
|
||||
|
||||
'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - no ZUGFeRD-Document in email' WHERE GUID = '{HISTORY_ID}'"
|
||||
'_firebird.ExecuteNonQuery(oSQL, oFBTransaction)
|
||||
Create_HistoryEntry(oMessageId, oMD5CheckSum, "REJECTED - no ZUGFeRD-Document in email", oFBTransaction)
|
||||
|
||||
Dim oBody = EmailStrings.EMAIL_NO_FERDS
|
||||
@@ -390,8 +394,7 @@ Public Class ImportZUGFeRDFiles
|
||||
For Each prop In oMissingProperties
|
||||
oMessage &= $"- {prop}"
|
||||
Next
|
||||
'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - Missing Required Properties: [{oMessage}]' WHERE GUID = '{HISTORY_ID}'"
|
||||
'_firebird.ExecuteNonQuery(oSQL, oFBTransaction)
|
||||
|
||||
Create_HistoryEntry(oMessageId, oMD5CheckSum, $"REJECTED - Missing Required Properties: [{oMessage}]", oFBTransaction)
|
||||
|
||||
Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties)
|
||||
@@ -399,6 +402,17 @@ Public Class ImportZUGFeRDFiles
|
||||
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "MissingValueException", _EmailOutAccountId)
|
||||
AddRejectedState(oMessageId, "MissingValueException", "Es fehlten ZugferdSpezifikationen", oMessage, oSQLTransaction)
|
||||
|
||||
Catch ex As FileSizeLimitReachedException
|
||||
_logger.Error(ex)
|
||||
|
||||
Create_HistoryEntry(oMessageId, oMD5CheckSum, "REJECTED - File size limit reached", oFBTransaction)
|
||||
|
||||
Dim oBody = String.Format(EmailStrings.EMAIL_FILE_SIZE_REACHED, oArgs.MaxAttachmentSizeInMegaBytes)
|
||||
Dim oEmailData = MoveAndRenameEmailToRejected(oArgs, oMessageId)
|
||||
|
||||
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "FileSizeLimitReachedException", _EmailOutAccountId)
|
||||
AddRejectedState(oMessageId, "FileSizeLimitReachedException", "Erlaubte Dateigröße überschritten", "", oSQLTransaction)
|
||||
|
||||
Catch ex As OutOfMemoryException
|
||||
_logger.Warn("OutOfMemory Error occurred: {0}", ex.Message)
|
||||
_logger.Error(ex)
|
||||
@@ -678,7 +692,7 @@ Public Class ImportZUGFeRDFiles
|
||||
''' <param name="pIgnoreRejectionStatus">Should the check take into account the rejection status of the file?</param>
|
||||
''' <returns>The MD5 Checksum of the file, or an empty string, if the Checksum could not be created</returns>
|
||||
''' <exception cref="MD5HashException">Throws, when the file should be rejected, ie. if it already exists in the table</exception>
|
||||
Private Function Check_MD5Sum(pFilePath As String, pIgnoreRejectionStatus As Boolean) As String
|
||||
Private Function GenerateAndCheck_MD5Sum(pFilePath As String, pIgnoreRejectionStatus As Boolean) As String
|
||||
Dim oMD5CheckSum = CreateMD5(pFilePath)
|
||||
|
||||
' Exit if MD5 could not be created
|
||||
@@ -740,4 +754,23 @@ Public Class ImportZUGFeRDFiles
|
||||
|
||||
Return oMD5CheckSum
|
||||
End Function
|
||||
|
||||
''' <summary>
|
||||
''' Checks the size of the supplied file.
|
||||
''' </summary>
|
||||
''' <param name="pFileInfo"></param>
|
||||
''' <param name="pMaxFileSizeInMegaBytes"></param>
|
||||
''' <returns></returns>
|
||||
Private Function Check_FileSize(pFileInfo As FileInfo, pMaxFileSizeInMegaBytes As Integer) As Boolean
|
||||
If pMaxFileSizeInMegaBytes <= 0 Then
|
||||
Return True
|
||||
End If
|
||||
|
||||
Dim oMaxSize = pMaxFileSizeInMegaBytes * 1024 * 1024
|
||||
If oMaxSize > 0 And pFileInfo.Length > oMaxSize Then
|
||||
Return False
|
||||
Else
|
||||
Return True
|
||||
End If
|
||||
End Function
|
||||
End Class
|
||||
|
||||
Reference in New Issue
Block a user