From 2b80e8fa9758d8047598aaebb81ddf2dc2649e0f Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Fri, 1 Sep 2023 13:56:12 +0200 Subject: [PATCH] Jobs: Remove obsolete history function --- Jobs/ZUGFeRD/HistoryFunctions.vb | 47 ++++++++++++-------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/Jobs/ZUGFeRD/HistoryFunctions.vb b/Jobs/ZUGFeRD/HistoryFunctions.vb index 11ba89de..859732da 100644 --- a/Jobs/ZUGFeRD/HistoryFunctions.vb +++ b/Jobs/ZUGFeRD/HistoryFunctions.vb @@ -1,4 +1,5 @@ Imports System.Data.SqlClient +Imports System.ServiceModel.Channels Imports DigitalData.Modules.Database Imports DigitalData.Modules.Logging Imports Microsoft.VisualBasic.FileIO @@ -15,42 +16,30 @@ Namespace ZUGFeRD _mssql = MSSQL End Sub - Public Function Create_HistoryEntry(MessageId As String, MD5Checksum As String, Message As String, Transaction As SqlTransaction) As Boolean + Public Function Update_HistoryEntry(pMessageId As String, pMD5Checksum As String, pMessage As String) As Boolean Try - _logger.Info("Creating History Entry for MessageId [{0}] with comment [{1}]", MessageId, Message) - Dim oSQL = $"INSERT INTO TBEMLP_HISTORY (COMMENT, MD5HASH, EMAIL_MSGID) VALUES ('{Message}', '{MD5Checksum}', '{MessageId}')" + _logger.Info("Updating History Entry for MessageId [{0}] with comment [{1}]", pMessageId, pMessage) + ' Only look for history entry by MessageId since the MD5 Hash might not be generated yet Using oConnection = _mssql.GetConnection() ' 09.07.2021: This can't be in the transaction since the history ' Entry needs to be accessed by MoveAndRenameEmailToRejected shortly after - _mssql.ExecuteNonQueryWithConnectionObject(oSQL, oConnection) - If Message.Contains("REJECTED") Then - oSQL = $"UPDATE TBEMLP_HISTORY SET STATUS = 'REJECTED', COMMENT = '{Message}', CUST_REJECTED = 1,CUST_REJECTED_WHEN = GETDATE() WHERE EMAIL_MSGID = '{MessageId}'" - _mssql.ExecuteNonQueryWithConnectionObject(oSQL, oConnection) + Dim oSQL = $"UPDATE TBEMLP_HISTORY SET + COMMENT = '{pMessage}', + MD5HASH = '{pMD5Checksum}' + WHERE EMAIL_MSGID = '{pMessageId}'" + + If pMessage.Contains("REJECTED") Then + oSQL = $"UPDATE TBEMLP_HISTORY SET + COMMENT = '{pMessage}', + MD5HASH = '{pMD5Checksum}', + STATUS = 'REJECTED', + CUST_REJECTED = 1, + CUST_REJECTED_WHEN = GETDATE() + WHERE EMAIL_MSGID = '{pMessageId}'" End If - _logger.Debug("History Entry created!") - End Using - - Return True - Catch ex As Exception - _logger.Warn("History Entry count not be created for message id [{0}] and md5 [{1}]", MessageId, MD5Checksum) - _logger.Error(ex) - - Return False - End Try - End Function - - Public Function Update_HistoryEntry(MessageId As String, MD5Checksum As String, Message As String, Transaction As SqlTransaction) As Boolean - Try - _logger.Info("Updating History Entry for MessageId [{0}] with comment [{1}]", MessageId, Message) - ' Only look for history entry by MessageId since the MD5 Hash might not be generated yet - - Using oConnection = _mssql.GetConnection() - ' 09.07.2021: This can't be in the transaction since the history - ' Entry needs to be accessed by MoveAndRenameEmailToRejected shortly after - Dim oSQL = $"UPDATE TBEMLP_HISTORY SET COMMENT = '{Message}' WHERE EMAIL_MSGID = '{MessageId}'" _mssql.ExecuteNonQueryWithConnectionObject(oSQL, oConnection) End Using @@ -58,7 +47,7 @@ Namespace ZUGFeRD Return True Catch ex As Exception - _logger.Warn("History Entry count not be updated for message id [{0}] and md5 [{1}]", MessageId, MD5Checksum) + _logger.Warn("History Entry count not be updated for message id [{0}] and md5 [{1}]", pMessageId, pMD5Checksum) _logger.Error(ex) Return False