diff --git a/Jobs/ZUGFeRD/EmailFunctions.vb b/Jobs/ZUGFeRD/EmailFunctions.vb index 6b41b4cb..3d7562c8 100644 --- a/Jobs/ZUGFeRD/EmailFunctions.vb +++ b/Jobs/ZUGFeRD/EmailFunctions.vb @@ -141,17 +141,6 @@ Namespace ZUGFeRD End If End Function - Public Function GetEmailPathWithSubjectAsName(RejectedEmailDirectory As String, UncleanedSubject As String) As String - Dim oCleanSubject = String.Join("", UncleanedSubject.Split(Path.GetInvalidPathChars())) - Dim oAttachmentDirectory = RejectedEmailDirectory - Dim oAttachmentFile = oCleanSubject & ".eml" - _logger.Debug("Email Filename is [{0}]", oAttachmentFile) - - Dim oAttachmentPath = Path.Combine(oAttachmentDirectory, oAttachmentFile) - - Return oAttachmentPath - End Function - Private Function RandomValue(lowerBound As Integer, upperBound As Integer) As Integer Dim oRandomValue = CInt(Math.Floor((upperBound - lowerBound + 1) * Rnd())) + lowerBound Return oRandomValue diff --git a/Jobs/ZUGFeRD/FileFunctions.vb b/Jobs/ZUGFeRD/FileFunctions.vb index 920752c5..e0060913 100644 --- a/Jobs/ZUGFeRD/FileFunctions.vb +++ b/Jobs/ZUGFeRD/FileFunctions.vb @@ -10,18 +10,20 @@ Namespace ZUGFeRD Public Class FileFunctions Private ReadOnly _logConfig As LogConfig Private ReadOnly _logger As Logger - Private ReadOnly _mssql As MSSQLServer Private ReadOnly _filesystem As FilesystemEx Private ReadOnly _email As ZUGFeRD.EmailFunctions Public Sub New(pLogConfig As LogConfig, pMSSQL As MSSQLServer) _logConfig = pLogConfig _logger = _logConfig.GetLogger() - _mssql = pMSSQL _email = New EmailFunctions(pLogConfig, pMSSQL) _filesystem = New FilesystemEx(pLogConfig) End Sub + Public Function CheckFileAge(oFiles As List(Of FileInfo), pMinFileAge As Integer) + Return oFiles.Where(Function(f) Now.Subtract(f.CreationTime).Minutes < pMinFileAge).Any() + End Function + Public Sub MoveFiles( pArgs As WorkerArgs, pMessageId As String, @@ -143,9 +145,9 @@ Namespace ZUGFeRD ' If oEmailData is Nothing, TBEDM_EMAIL_PROFILER_HISTORY for MessageId was not found. ' This only should happen when testing and db-tables are deleted frequently If oEmailData Is Nothing Then - oDestination = _email.GetEmailPathWithSubjectAsName(oRejectedDirectory, pMessageId) + oDestination = GetEmailPathWithSubjectAsName(oRejectedDirectory, pMessageId) Else - oDestination = _email.GetEmailPathWithSubjectAsName(oRejectedDirectory, StringEx.ConvertTextToSlug(oEmailData.Subject)) + oDestination = GetEmailPathWithSubjectAsName(oRejectedDirectory, StringEx.ConvertTextToSlug(oEmailData.Subject)) End If _logger.Debug("Destination for eml file is {0}", oDestination) @@ -175,6 +177,17 @@ Namespace ZUGFeRD Return oEmailData End Function + + Public Function GetEmailPathWithSubjectAsName(RejectedEmailDirectory As String, UncleanedSubject As String) As String + Dim oCleanSubject = String.Join("", UncleanedSubject.Split(Path.GetInvalidPathChars())) + Dim oAttachmentDirectory = RejectedEmailDirectory + Dim oAttachmentFile = oCleanSubject & ".eml" + _logger.Debug("Email Filename is [{0}]", oAttachmentFile) + + Dim oAttachmentPath = Path.Combine(oAttachmentDirectory, oAttachmentFile) + + Return oAttachmentPath + End Function End Class End Namespace diff --git a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb index ffa2b311..df19988e 100644 --- a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -162,6 +162,11 @@ Public Class ImportZUGFeRDFiles _logger.Info("Start processing file group {0}", oMessageId) + If _file.CheckFileAge(oFileGroupFiles, oArgs.MinFileAgeInMinutes) Then + _logger.Info("At least one file was created less than [{0}] minutes ago. Skipping file group.") + Continue For + End If + Dim oEmailDataBase = _email.GetEmailDataForMessageId(oMessageId) Try diff --git a/Jobs/ZUGFeRD/WorkerArgs.vb b/Jobs/ZUGFeRD/WorkerArgs.vb index 9367384a..154b150e 100644 --- a/Jobs/ZUGFeRD/WorkerArgs.vb +++ b/Jobs/ZUGFeRD/WorkerArgs.vb @@ -21,6 +21,7 @@ Public Class WorkerArgs Public ExceptionEmailAddress As String = Nothing Public IgnoreRejectionStatus As Boolean = False Public MaxAttachmentSizeInMegaBytes As Integer = -1 + Public MinFileAgeInMinutes As Integer = 5 Public NamePortal As String = "NO PORTAL_NAME IN CONFIG" Public AllowFacturX As Boolean = True