ZUGFeRDService: Add config option MaxAttachmentSizeInMegaBytes
This commit is contained in:
parent
b81d6a1314
commit
d8c534c3e3
@ -86,7 +86,10 @@ Public Class Form1
|
|||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
|
||||||
Dim args As New WorkerArgs()
|
Dim args As New WorkerArgs() With {
|
||||||
|
.MaxAttachmentSizeInMegaBytes = 10,
|
||||||
|
.IgnoreRejectionStatus = False
|
||||||
|
}
|
||||||
args = LoadFolderConfig(args)
|
args = LoadFolderConfig(args)
|
||||||
args = LoadPropertyMapFor(args, "DEFAULT")
|
args = LoadPropertyMapFor(args, "DEFAULT")
|
||||||
args.InsertIntoSQLServer = True
|
args.InsertIntoSQLServer = True
|
||||||
|
|||||||
@ -23,6 +23,8 @@
|
|||||||
|
|
||||||
Public Const EMAIL_NO_FERDS = "<p>Ihre Email enthielt keine ZUGFeRD-Dokumente.</p>"
|
Public Const EMAIL_NO_FERDS = "<p>Ihre Email enthielt keine ZUGFeRD-Dokumente.</p>"
|
||||||
|
|
||||||
|
Public Const EMAIL_FILE_SIZE_REACHED = "<p>Ihre Email enthielt Dateien, die die erlaubte Größe von {0}MB überschreiten.</p>"
|
||||||
|
|
||||||
Public Const EMAIL_INVALID_DOCUMENT = """
|
Public Const EMAIL_INVALID_DOCUMENT = """
|
||||||
<p>Ihre Email enthielt ein ZUGFeRD Dokument, welches aber inkorrekt formatiert wurde.</p>
|
<p>Ihre Email enthielt ein ZUGFeRD Dokument, welches aber inkorrekt formatiert wurde.</p>
|
||||||
<p>Mögliche Gründe für ein inkorrektes Format:<ul>
|
<p>Mögliche Gründe für ein inkorrektes Format:<ul>
|
||||||
|
|||||||
@ -206,11 +206,24 @@ Public Class ImportZUGFeRDFiles
|
|||||||
If Not oFile.Name.EndsWith(".pdf") Then
|
If Not oFile.Name.EndsWith(".pdf") Then
|
||||||
_logger.Debug("Skipping non-pdf file {0}", oFile.Name)
|
_logger.Debug("Skipping non-pdf file {0}", oFile.Name)
|
||||||
oEmailAttachmentFiles.Add(oFile)
|
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
|
Continue For
|
||||||
End If
|
End If
|
||||||
|
|
||||||
_logger.Info("Start processing file {0}", oFile.Name)
|
_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
|
Try
|
||||||
oDocument = _zugferd.ExtractZUGFeRDFileWithGDPicture(oFile.FullName)
|
oDocument = _zugferd.ExtractZUGFeRDFileWithGDPicture(oFile.FullName)
|
||||||
Catch ex As ZUGFeRDExecption
|
Catch ex As ZUGFeRDExecption
|
||||||
@ -241,7 +254,7 @@ Public Class ImportZUGFeRDFiles
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
' Check the Checksum and rejection status
|
' 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
|
' Check if there are more than one ZUGFeRD files
|
||||||
If oZUGFeRDCount = 1 Then
|
If oZUGFeRDCount = 1 Then
|
||||||
@ -334,8 +347,6 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Catch ex As MD5HashException
|
Catch ex As MD5HashException
|
||||||
_logger.Error(ex)
|
_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)"
|
Dim oMessage = "REJECTED - Already processed (MD5Hash)"
|
||||||
Update_HistoryEntry(oMessageId, oMD5CheckSum, oMessage, oFBTransaction)
|
Update_HistoryEntry(oMessageId, oMD5CheckSum, oMessage, oFBTransaction)
|
||||||
|
|
||||||
@ -347,9 +358,6 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Catch ex As InvalidFerdException
|
Catch ex As InvalidFerdException
|
||||||
_logger.Error(ex)
|
_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.
|
' When InvalidFerdException is thrown, we don't have a MD5Hash yet.
|
||||||
' That 's why we set it to String.Empty here.
|
' That 's why we set it to String.Empty here.
|
||||||
Create_HistoryEntry(oMessageId, String.Empty, "REJECTED - ZUGFeRD yes but incorrect format", oFBTransaction)
|
Create_HistoryEntry(oMessageId, String.Empty, "REJECTED - ZUGFeRD yes but incorrect format", oFBTransaction)
|
||||||
@ -362,8 +370,6 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Catch ex As TooMuchFerdsException
|
Catch ex As TooMuchFerdsException
|
||||||
_logger.Error(ex)
|
_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)
|
Create_HistoryEntry(oMessageId, oMD5CheckSum, "REJECTED - More than one ZUGFeRD-document in email", oFBTransaction)
|
||||||
|
|
||||||
Dim oBody = EmailStrings.EMAIL_TOO_MUCH_FERDS
|
Dim oBody = EmailStrings.EMAIL_TOO_MUCH_FERDS
|
||||||
@ -374,8 +380,6 @@ Public Class ImportZUGFeRDFiles
|
|||||||
Catch ex As NoFerdsException
|
Catch ex As NoFerdsException
|
||||||
_logger.Error(ex)
|
_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)
|
Create_HistoryEntry(oMessageId, oMD5CheckSum, "REJECTED - no ZUGFeRD-Document in email", oFBTransaction)
|
||||||
|
|
||||||
Dim oBody = EmailStrings.EMAIL_NO_FERDS
|
Dim oBody = EmailStrings.EMAIL_NO_FERDS
|
||||||
@ -390,8 +394,7 @@ Public Class ImportZUGFeRDFiles
|
|||||||
For Each prop In oMissingProperties
|
For Each prop In oMissingProperties
|
||||||
oMessage &= $"- {prop}"
|
oMessage &= $"- {prop}"
|
||||||
Next
|
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)
|
Create_HistoryEntry(oMessageId, oMD5CheckSum, $"REJECTED - Missing Required Properties: [{oMessage}]", oFBTransaction)
|
||||||
|
|
||||||
Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties)
|
Dim oBody = CreateBodyForMissingProperties(ex.File.Name, oMissingProperties)
|
||||||
@ -399,6 +402,17 @@ Public Class ImportZUGFeRDFiles
|
|||||||
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "MissingValueException", _EmailOutAccountId)
|
_email.AddToEmailQueueMSSQL(oMessageId, oBody, oEmailData, "MissingValueException", _EmailOutAccountId)
|
||||||
AddRejectedState(oMessageId, "MissingValueException", "Es fehlten ZugferdSpezifikationen", oMessage, oSQLTransaction)
|
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
|
Catch ex As OutOfMemoryException
|
||||||
_logger.Warn("OutOfMemory Error occurred: {0}", ex.Message)
|
_logger.Warn("OutOfMemory Error occurred: {0}", ex.Message)
|
||||||
_logger.Error(ex)
|
_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>
|
''' <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>
|
''' <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>
|
''' <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)
|
Dim oMD5CheckSum = CreateMD5(pFilePath)
|
||||||
|
|
||||||
' Exit if MD5 could not be created
|
' Exit if MD5 could not be created
|
||||||
@ -740,4 +754,23 @@ Public Class ImportZUGFeRDFiles
|
|||||||
|
|
||||||
Return oMD5CheckSum
|
Return oMD5CheckSum
|
||||||
End Function
|
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
|
End Class
|
||||||
|
|||||||
@ -13,6 +13,7 @@ Public Class WorkerArgs
|
|||||||
|
|
||||||
Public ExceptionEmailAddress As String
|
Public ExceptionEmailAddress As String
|
||||||
Public IgnoreRejectionStatus As Boolean
|
Public IgnoreRejectionStatus As Boolean
|
||||||
|
Public MaxAttachmentSizeInMegaBytes As Integer
|
||||||
|
|
||||||
Public Sub New()
|
Public Sub New()
|
||||||
WatchDirectories = New List(Of String)
|
WatchDirectories = New List(Of String)
|
||||||
@ -26,5 +27,6 @@ Public Class WorkerArgs
|
|||||||
|
|
||||||
ExceptionEmailAddress = Nothing
|
ExceptionEmailAddress = Nothing
|
||||||
IgnoreRejectionStatus = False
|
IgnoreRejectionStatus = False
|
||||||
|
MaxAttachmentSizeInMegaBytes = -1
|
||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
@ -21,6 +21,14 @@ Public Class Exceptions
|
|||||||
End Sub
|
End Sub
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
|
Public Class FileSizeLimitReachedException
|
||||||
|
Inherits ApplicationException
|
||||||
|
|
||||||
|
Public Sub New(pFilePath As String, pFileSizeLimitInMegaBytes As Integer)
|
||||||
|
MyBase.New($"At least one file exceeded the filesize limit of {pFileSizeLimitInMegaBytes}MB: {pFilePath}")
|
||||||
|
End Sub
|
||||||
|
End Class
|
||||||
|
|
||||||
Public Class InvalidFerdException
|
Public Class InvalidFerdException
|
||||||
Inherits ApplicationException
|
Inherits ApplicationException
|
||||||
|
|
||||||
|
|||||||
@ -21,6 +21,12 @@
|
|||||||
''' regardless of the REJECTED status.
|
''' regardless of the REJECTED status.
|
||||||
''' </summary>
|
''' </summary>
|
||||||
Public Property IgnoreRejectionStatus As Boolean = False
|
Public Property IgnoreRejectionStatus As Boolean = False
|
||||||
|
|
||||||
|
''' <summary>
|
||||||
|
''' Maximum Size for attachment files in MB. If This is set to -1,
|
||||||
|
''' there's no size limit.
|
||||||
|
''' </summary>
|
||||||
|
Public Property MaxAttachmentSizeInMegaBytes As Integer = -1
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
Public Class FirebirdConfig
|
Public Class FirebirdConfig
|
||||||
|
|||||||
@ -51,7 +51,8 @@ Public Class ThreadRunner
|
|||||||
|
|
||||||
Dim oArgs As New WorkerArgs With {
|
Dim oArgs As New WorkerArgs With {
|
||||||
.ExceptionEmailAddress = _config.Config.ExceptionEmailAddress,
|
.ExceptionEmailAddress = _config.Config.ExceptionEmailAddress,
|
||||||
.IgnoreRejectionStatus = _config.Config.Custom.IgnoreRejectionStatus
|
.IgnoreRejectionStatus = _config.Config.Custom.IgnoreRejectionStatus,
|
||||||
|
.MaxAttachmentSizeInMegaBytes = _config.Config.Custom.MaxAttachmentSizeInMegaBytes
|
||||||
}
|
}
|
||||||
oArgs = LoadFolderConfig(oArgs)
|
oArgs = LoadFolderConfig(oArgs)
|
||||||
oArgs = LoadPropertyMapFor(oArgs, "DEFAULT")
|
oArgs = LoadPropertyMapFor(oArgs, "DEFAULT")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user