ZUGFeRDService: Integrate MSSQL Transactions, Rollback for Application Exceptions #MR-2

This commit is contained in:
Jonathan Jenne
2021-04-15 15:57:09 +02:00
parent 07ce5488df
commit f6fc3be8ed
2 changed files with 74 additions and 47 deletions

View File

@@ -2,6 +2,7 @@
Imports DigitalData.Modules.Database
Imports System.Data
Imports System.IO
Imports System.Data.SqlClient
Public Class EmailFunctions
Private ReadOnly _logConfig As LogConfig
@@ -62,7 +63,7 @@ Public Class EmailFunctions
_logger.Error(ex)
End Try
End Sub
Public Sub AddToEmailQueueMSSQL(MessageId As String, BodyText As String, pEmailData As EmailData, SourceProcedure As String, pEmailAccountId As Integer)
Public Sub AddToEmailQueueMSSQL(MessageId As String, BodyText As String, pEmailData As EmailData, SourceProcedure As String, pEmailAccountId As Integer, Transaction As SqlTransaction)
If pEmailData Is Nothing Then
_logger.Warn("EmailData is empty. Email will not be sent!")
Exit Sub
@@ -97,7 +98,7 @@ Public Class EmailFunctions
_logger.Debug("Subject: {0}", oSubject)
_logger.Debug("Body {0}", oFinalBodyText)
Dim osql = $"Select MAX(GUID) FROM TBEMLP_HISTORY WHERE EMAIL_MSGID = '{MessageId}'"
Dim oHistoryID = _mssql.GetScalarValue(osql)
Dim oHistoryID = _mssql.GetScalarValue(osql, Transaction)
'osql = $"select * from TBEMLP_EMAIL_OUT where REFERENCE_ID = {oHistoryID} and EMAIL_ADRESS = '{oEmailTo}' and EMAIL_SUBJ = '{oSubject}'"
@@ -128,7 +129,7 @@ Public Class EmailFunctions
,'{SourceProcedure}'
,'{oCreatedWho}'
,'{oAttachment}')"
_mssql.ExecuteNonQuery(oInsert)
_mssql.ExecuteNonQuery(oInsert, Transaction)
Else
'If oDTResult.Rows.Count = 0 Then
' _logger.Debug("Email has already been sent!!")
@@ -173,7 +174,7 @@ Public Class EmailFunctions
Dim oAttachmentFile = MessageId & ".eml"
Dim oAttachmentPath = Path.Combine(oAttachmentDirectory, oAttachmentFile)
If IO.File.Exists(oAttachmentPath) Then
If File.Exists(oAttachmentPath) Then
Return oAttachmentPath
Else
_logger.Warn("Email File {0} does not exist. Empty String will be returned.", oAttachmentPath)