From 04577f3b616d780665d72300b007912b9acc0ac3 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 20 Dec 2023 15:08:04 +0100 Subject: [PATCH 1/7] Jobs: add check for file age --- Jobs/ZUGFeRD/EmailFunctions.vb | 11 ----------- Jobs/ZUGFeRD/FileFunctions.vb | 21 +++++++++++++++++---- Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb | 5 +++++ Jobs/ZUGFeRD/WorkerArgs.vb | 1 + 4 files changed, 23 insertions(+), 15 deletions(-) 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 From 5b2ba2eff2b8abfa1bea9a565c43cc9386c0854a Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 20 Dec 2023 15:09:06 +0100 Subject: [PATCH 2/7] Jobs: Version 2.3.0.0 --- Jobs/My Project/AssemblyInfo.vb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jobs/My Project/AssemblyInfo.vb b/Jobs/My Project/AssemblyInfo.vb index 55c5e730..a606d85e 100644 --- a/Jobs/My Project/AssemblyInfo.vb +++ b/Jobs/My Project/AssemblyInfo.vb @@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices - + @@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices ' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern ' übernehmen, indem Sie "*" eingeben: - - + + From 30c602a9bff83c6ead92dcfb46c0988207c90910 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 20 Dec 2023 15:09:10 +0100 Subject: [PATCH 3/7] clean up --- Config/ConfigUtils.vb | 1 - Jobs/GraphQL/GraphQLJob.vb | 1 - 2 files changed, 2 deletions(-) diff --git a/Config/ConfigUtils.vb b/Config/ConfigUtils.vb index 8bb41351..e27835f4 100644 --- a/Config/ConfigUtils.vb +++ b/Config/ConfigUtils.vb @@ -1,5 +1,4 @@ Imports System.IO -Imports System.Windows.Forms Imports DigitalData.Modules.Base Imports DigitalData.Modules.Logging diff --git a/Jobs/GraphQL/GraphQLJob.vb b/Jobs/GraphQL/GraphQLJob.vb index b7cae23a..cad98f37 100644 --- a/Jobs/GraphQL/GraphQLJob.vb +++ b/Jobs/GraphQL/GraphQLJob.vb @@ -9,7 +9,6 @@ Imports DigitalData.Modules.Config Imports DigitalData.Modules.Database Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Jobs.GraphQL -Imports DigitalData.Modules.Language Imports DigitalData.Modules.Logging Imports Newtonsoft.Json.Linq From 726c3481e51e68546a2e1c8153787317358745ec Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 20 Dec 2023 15:16:27 +0100 Subject: [PATCH 4/7] Jobs: Fix logging --- Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb index df19988e..96b0cddd 100644 --- a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -163,7 +163,7 @@ 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.") + _logger.Info("At least one file was created less than [{0}] minutes ago. Skipping file group.", oArgs.MinFileAgeInMinutes) Continue For End If From 71e9fe7cd2368114f71357b91d16884f0d128d66 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 20 Dec 2023 15:29:27 +0100 Subject: [PATCH 5/7] Jobs: Improve logging --- Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb index 96b0cddd..e843ae64 100644 --- a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -160,7 +160,7 @@ Public Class ImportZUGFeRDFiles Dim oMessageId As String = oFileGroup.Key Dim oMD5CheckSum As String = String.Empty - _logger.Info("Start processing file group {0}", oMessageId) + _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.", oArgs.MinFileAgeInMinutes) @@ -378,7 +378,7 @@ Public Class ImportZUGFeRDFiles ' Move all files of the current group _file.MoveFiles(oArgs, oMessageId, oFileGroupFiles, oEmailAttachmentFiles, oEmbeddedAttachmentFiles, oMoveDirectory, oIsSuccess) End If - _logger.Info("Finished processing file group {0}", oMessageId) + _logger.Info("END processing file group {0}", oMessageId) Catch ex As Exception ' Send Email to Digital Data Dim oBody = _email.CreateBodyForUnhandledException(oMessageId, ex) From 63ddbaeacf1edeaf36d9e7173119e5fa3cd3b199 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 20 Dec 2023 15:30:01 +0100 Subject: [PATCH 6/7] Jobs: Version 2.3.0.1 --- Jobs/My Project/AssemblyInfo.vb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jobs/My Project/AssemblyInfo.vb b/Jobs/My Project/AssemblyInfo.vb index a606d85e..67eb2993 100644 --- a/Jobs/My Project/AssemblyInfo.vb +++ b/Jobs/My Project/AssemblyInfo.vb @@ -13,7 +13,7 @@ Imports System.Runtime.InteropServices - + @@ -30,5 +30,5 @@ Imports System.Runtime.InteropServices ' Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern ' übernehmen, indem Sie "*" eingeben: - - + + From 9deeb35ad7dc80bb6317dadc03219df0e148dded Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 3 Jan 2024 15:19:29 +0100 Subject: [PATCH 7/7] clean up --- Interfaces/ZUGFeRDInterface/PDFConverter.vb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Interfaces/ZUGFeRDInterface/PDFConverter.vb b/Interfaces/ZUGFeRDInterface/PDFConverter.vb index 19caa813..678ec3ce 100644 --- a/Interfaces/ZUGFeRDInterface/PDFConverter.vb +++ b/Interfaces/ZUGFeRDInterface/PDFConverter.vb @@ -1,4 +1,6 @@ -Imports DigitalData.Modules.Logging +Imports System.IO +Imports DigitalData.Modules.Interfaces.Exceptions +Imports DigitalData.Modules.Logging Imports GdPicture14 Public Class PDFConverter @@ -58,5 +60,9 @@ Public Class PDFConverter _Logger.Error(ex) Return False End Try + + End Function + + End Class