From 96b1004749f7abfa28cf5472c35521ba305f278a Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Wed, 13 Jan 2021 14:00:59 +0100 Subject: [PATCH] Jobs/Zugferd: dont move files on application errors --- .../EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb b/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb index e9d9f6a6..8415f56f 100644 --- a/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -26,6 +26,8 @@ Public Class ImportZUGFeRDFiles Public Const ZUGFERD_ATTACHMENTS = "ZUGFeRD Attachments" Public HISTORY_ID As Integer + Private Const DIRECTORY_DONT_MOVE = "DIRECTORY_DONT_MOVE" + ' 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 List(Of String) = New List(Of String) From {"docx", "doc", "pdf", "xls", "xlsx", "ppt", "pptx", "txt"} @@ -406,29 +408,34 @@ Public Class ImportZUGFeRDFiles _logger.Error(ex) oTransaction.Rollback() - Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - Out of memory' WHERE GUID = '{HISTORY_ID}'" - _firebird.ExecuteNonQuery(oSQL) + oMoveDirectory = DIRECTORY_DONT_MOVE - AddRejectedState(oMessageId, "OutOfMemoryException", "", ex.Message) + 'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - Out of memory' WHERE GUID = '{HISTORY_ID}'" + '_firebird.ExecuteNonQuery(oSQL) + 'AddRejectedState(oMessageId, "OutOfMemoryException", "", ex.Message) Catch ex As Exception _logger.Warn("Unknown Error occurred: {0}", ex.Message) _logger.Error(ex) oTransaction.Rollback() - Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - Unknown error occured' WHERE GUID = '{HISTORY_ID}'" - _firebird.ExecuteNonQuery(oSQL) - - oMoveDirectory = oArgs.ErrorDirectory - - AddRejectedState(oMessageId, "UnexpectedException", "", ex.Message) + oMoveDirectory = DIRECTORY_DONT_MOVE + 'Dim oSQL = $"UPDATE TBEDM_ZUGFERD_HISTORY_IN SET COMMENT = 'REJECTED - Unknown error occured' WHERE GUID = '{HISTORY_ID}'" + '_firebird.ExecuteNonQuery(oSQL) + 'oMoveDirectory = oArgs.ErrorDirectory + 'AddRejectedState(oMessageId, "UnexpectedException", "", ex.Message) Finally oConnection.Close() - ' Move all files of the current group Try - MoveFiles(oArgs, oMessageId, oFileGroupFiles, oEmailAttachmentFiles, oEmbeddedAttachmentFiles, oMoveDirectory, oIsSuccess) + ' If an application error occurred, dont move files so they will be processed again later + If oMoveDirectory = DIRECTORY_DONT_MOVE Then + _logger.Info("Application Error occurred. Files for message Id {0} will not be moved.", oMessageId) + Else + ' Move all files of the current group + MoveFiles(oArgs, oMessageId, oFileGroupFiles, oEmailAttachmentFiles, oEmbeddedAttachmentFiles, oMoveDirectory, oIsSuccess) + End If _logger.Info("Finished processing file group {0}", oMessageId) Catch ex As Exception _logger.Warn("Could not move files!")