V 1.7 Test ByteData

This commit is contained in:
2024-06-25 11:23:13 +02:00
parent 3d07cdb488
commit 797a01245a
4 changed files with 138 additions and 6 deletions

View File

@@ -19,11 +19,14 @@ Public Class EmailService
Private _Encryption As EncryptionLegacy
Private _EmailQueue As BackgroundWorker
Private _QueueTimer As Timer
Private _TempFiles As TempFiles
Private _AnyDatabaseInitialized As Boolean = False
Private _limilab As Limilab
Private _MailSender As Mail.MailSender
Private _AttachmentByteData As Byte()
Private ReadOnly _messageSend As Boolean = False
Private Enum DatabaseType
Firebird
MSSQL
@@ -77,7 +80,8 @@ Public Class EmailService
End If
_AnyDatabaseInitialized = _Firebird?._DBInitialized Or _MSSQL?.DBInitialized Or _MSSQL_Test?.DBInitialized
_TempFiles = New TempFiles(_LogConfig)
_TempFiles.Create()
' === Initialize Email ===
_Logger.Debug("Inititalize Email")
@@ -372,6 +376,8 @@ Public Class EmailService
Dim oSubject = String.Empty
Dim oBody = String.Empty
Dim oAddedWhen = Now
Dim ATT1_RELATED_ID = String.Empty
Dim ATT1_REL_TYPE = String.Empty
Select Case Database
Case DatabaseType.Firebird
@@ -409,16 +415,32 @@ Public Class EmailService
oAddedWhen = oRow.ItemEx("ADDED_WHEN", Now)
oAttachment = oRow.ItemEx("EMAIL_ATTMT1", String.Empty)
ATT1_RELATED_ID = oRow.ItemEx("ATT1_RELATED_ID", String.Empty)
ATT1_REL_TYPE = oRow.ItemEx("ATT1_REL_TYPE", String.Empty)
End Select
If ATT1_RELATED_ID <> String.Empty And ATT1_REL_TYPE <> String.Empty Then
_Logger.Info($"Attachment via byte/ID [{ATT1_RELATED_ID}]...")
If ATT1_REL_TYPE = "EnvelopeResult" Then
GetEnvelope_Result_FileStreamByte(ATT1_RELATED_ID, MSSQLInstance)
End If
If IsNothing(_AttachmentByteData) = False Then
Dim oTempFolder = _TempFiles.TempPath
Dim oTempFilename = String.Concat(oTempFolder, "\", $"SigningReport_{ATT1_RELATED_ID}.pdf")
Dim oFileFromByteData = CreateTempFileFromByte(oTempFilename)
If Not IsNothing(oFileFromByteData) Then
_Logger.Info($"Attachment is [{oFileFromByteData}]!")
oAttachment = oFileFromByteData
End If
End If
End If
If oAttachment <> String.Empty Then
If oAttachment.ToString.Contains("\") Then
If File.Exists(oAttachment) = False Then
_Logger.Warn($"Email Attachment [{oAttachment}] not existing!")
oComment = $"Email Attachment [{oAttachment}] not existing!"
_Logger.Warn($"Email Attachment [{oAttachment}] Not existing!")
oComment = $"Email Attachment [{oAttachment}] Not existing!"
oAttachment = String.Empty
Else
_Logger.Debug("Email Attachment is: {0}", oAttachment)
_Logger.Debug("Email Attachment Is: {0}", oAttachment)
End If
End If
@@ -505,12 +527,61 @@ Public Class EmailService
Return False
End Try
End Function
Private Sub GetEnvelope_Result_FileStreamByte(ByVal pEnvID As Long, pMSSQL As MSSQLServer)
Dim strSql As String
'For Document
Try
'Get image data from gridview column.
strSql = "Select [DOC_RESULT] from [TBSIG_ENVELOPE] WHERE GUID = " & pEnvID
Dim obyteDB = pMSSQL.GetScalarValue(strSql)
If Not IsDBNull(obyteDB) Then
'Get image data from DB
Dim fileData As Byte() = DirectCast(obyteDB, Byte())
If Not fileData Is Nothing Then
_AttachmentByteData = fileData
Else
_AttachmentByteData = Nothing
End If
Else
_AttachmentByteData = Nothing
End If
Catch ex As Exception
_Logger.Warn($"Error in GetEnvelope_Result_FileStreamByte [{ex.Message}]")
_Logger.Error(ex)
_AttachmentByteData = Nothing
End Try
End Sub
Private Function CreateTempFileFromByte(ByVal sFileName As String) As String
Try
If Not _AttachmentByteData Is Nothing Then
'Read image data into a file stream
Using fs As New FileStream(sFileName, FileMode.OpenOrCreate, FileAccess.Write)
fs.Write(_AttachmentByteData, 0, _AttachmentByteData.Length)
'Set image variable value using memory stream.
fs.Flush()
fs.Close()
End Using
'Open File
Return sFileName
Else
_Logger.Warn($"Error in CreateTempFileFromByte - _AttachmentByteData is nothing!")
Return Nothing
End If
Catch ex As Exception
_Logger.Warn($"Error in CreateTempFileFromByte [{ex.Message}]")
_Logger.Error(ex)
Return Nothing
End Try
End Function
Protected Overrides Sub OnStop()
Try
_Logger.Warn("Service {0} was stopped.", ServiceName)
_TempFiles.CleanUp()
Catch ex As Exception
_Logger.Warn("Error while stopping service!")
_Logger.Error(ex)