This commit is contained in:
Developer 02 2024-06-25 13:18:05 +02:00
commit 5c51ea679e
9 changed files with 125 additions and 55 deletions

View File

@ -17,6 +17,8 @@ Public Class EmailData
Public Property EnvelopeTitle As String = ""
Public Property EmailAttachment As String = ""
Public Property ATT1_RELATED_ID As Long
Public Property ATT1_REL_TYPE As String = ""
''' <summary>
''' Constructor for sending email to receiver

View File

@ -203,7 +203,6 @@ Namespace Jobs
If Config.FINISHED_PATH_EX_DMZ <> String.Empty Then
If My.Settings.NetUse_PW <> String.Empty And My.Settings.NetUse_Usr <> String.Empty Then
Clean_DNZ_PAth(Config.FINISHED_PATH_EX_DMZ)
End If
End If
End If
@ -211,7 +210,7 @@ Namespace Jobs
Update_File_DB(oOutputFilePath, oEnvelope.Id)
Logger.Info("Sending finalized report-mails..")
If SendFinalEmails(oEnvelope, oOutputFilePath) = False Then
If SendFinalEmails(oEnvelope) = False Then ', oOutputFilePath
Throw New ApplicationException("Final emails could not be sent!")
End If
Logger.Debug("Setting envelope status..")
@ -329,35 +328,33 @@ Namespace Jobs
End Function
Private Function SendFinalEmails(pEnvelope As Envelope, pAttachment As String) As Boolean
Private Function SendFinalEmails(pEnvelope As Envelope) As Boolean ', pAttachment As String
Dim oMailToCreator = pEnvelope.FinalEmailToCreator
Dim oMailToReceivers = pEnvelope.FinalEmailToReceivers
If oMailToCreator <> FinalEmailType.No Then
Logger.Debug("Sending email to creator ...")
SendFinalEmailToCreator(pEnvelope, pAttachment)
SendFinalEmailToCreator(pEnvelope) ', pAttachment
End If
If oMailToReceivers <> FinalEmailType.No Then
Logger.Debug("Sending emails to receivers..")
SendFinalEmailToReceivers(pEnvelope, pAttachment)
SendFinalEmailToReceivers(pEnvelope) ', pAttachment
End If
Return True
End Function
Private Function SendFinalEmailToCreator(pEnvelope As Envelope, pAttachment As String) As Boolean
Private Function SendFinalEmailToCreator(pEnvelope As Envelope) As Boolean ', pAttachment As String
Dim oIncludeAttachment = SendFinalEmailWithAttachment(pEnvelope.FinalEmailToCreator)
Dim oAttachment = String.Empty
' Dim oAttachment = String.Empty
Logger.Debug("Attachment included: [{0}]", oIncludeAttachment)
If oIncludeAttachment Then
oAttachment = pAttachment
'oAttachment = pAttachment
End If
If ActionService.CompleteEnvelope(pEnvelope, oAttachment) = False Then
If ActionService.CompleteEnvelope(pEnvelope) = False Then ', oAttachment
Logger.Error("Envelope could not be completed for receiver [{0}]", pEnvelope.User.Email)
Return False
End If
@ -365,18 +362,18 @@ Namespace Jobs
Return True
End Function
Private Function SendFinalEmailToReceivers(pEnvelope As Envelope, pAttachment As String) As Boolean
Private Function SendFinalEmailToReceivers(pEnvelope As Envelope) As Boolean ', pAttachment As String
Dim oIncludeAttachment = SendFinalEmailWithAttachment(pEnvelope.FinalEmailToReceivers)
Dim oAttachment = String.Empty
'Dim oAttachment = String.Empty
Logger.Debug("Attachment included: [{0}]", oIncludeAttachment)
If oIncludeAttachment Then
oAttachment = pAttachment
' oAttachment = pAttachment
End If
For Each oReceiver In pEnvelope.Receivers
If ActionService.CompleteEnvelope(pEnvelope, oReceiver, oAttachment) = False Then
If ActionService.CompleteEnvelope(pEnvelope, oReceiver) = False Then ', oAttachment
Logger.Error("Envelope could not be completed for receiver [{0}]", oReceiver.Email)
Return False
End If
@ -399,30 +396,42 @@ Namespace Jobs
Logger.Info($"Burning [{pEnvelopeData.AnnotationData.Count}] signatures")
Dim oAnnotations = pEnvelopeData.AnnotationData
Dim oInputPath = ""
If My.Settings.RuninDMZ Then
Logger.Debug("Replacing Path in pData.DocumentPath ...")
oInputPath = pEnvelopeData.DocumentPath.Replace(Config.DocumentPathOrigin, Config.DocumentPath)
ElseIf Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then
Logger.Debug("Replacing Path in pData.DocumentPath ...")
oInputPath = pEnvelopeData.DocumentPath.Replace(Config.DocumentPathOrigin, Config.DOCUMENT_PATH_MOVE_AFTSEND)
If IsNothing(pEnvelopeData.DocAsByte) Then
If My.Settings.RuninDMZ Then
Logger.Debug("Replacing Path in pData.DocumentPath ...")
oInputPath = pEnvelopeData.DocumentPath.Replace(Config.DocumentPathOrigin, Config.DocumentPath)
ElseIf Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then
Logger.Debug("Replacing Path in pData.DocumentPath ...")
oInputPath = pEnvelopeData.DocumentPath.Replace(Config.DocumentPathOrigin, Config.DOCUMENT_PATH_MOVE_AFTSEND)
Else
oInputPath = pEnvelopeData.DocumentPath
End If
Logger.Info($"Input path: [{oInputPath}]")
Else
oInputPath = pEnvelopeData.DocumentPath
Logger.Info($"we got bytes..")
oInputPath = Config.DocumentPathOrigin
Dim oTempFolder = TempFiles.TempPath
End If
Logger.Info($"Input path: [{oInputPath}]")
Dim oDirectorySource As String = Path.GetDirectoryName(oInputPath)
Dim split As String() = oDirectorySource.Split("\")
ParentFolderUID = split(split.Length - 1)
Logger.Info("ParentFolderUID: [{0}]", ParentFolderUID)
Dim oInputDocumentBuffer As Byte()
Try
oInputDocumentBuffer = File.ReadAllBytes(oInputPath)
Catch ex As Exception
Logger.Error(ex)
Throw New BurnAnnotationException("Source document could not be read from disk!", ex)
End Try
If Not IsNothing(pEnvelopeData.DocAsByte) Then
oInputDocumentBuffer = pEnvelopeData.DocAsByte
Else
Try
oInputDocumentBuffer = File.ReadAllBytes(oInputPath)
Catch ex As Exception
Logger.Error(ex)
Throw New BurnAnnotationException("Source document could not be read from disk!", ex)
End Try
End If
Return PDFBurner.BurnInstantJSONAnnotationsToPDF(oInputDocumentBuffer, oAnnotations)
End Function
@ -441,7 +450,8 @@ Namespace Jobs
Dim oData As New EnvelopeData With {
.EnvelopeId = pEnvelopeId,
.DocumentPath = oRow.ItemEx("FILEPATH", ""),
.AnnotationData = oAnnotationData
.AnnotationData = oAnnotationData,
.DocAsByte = DirectCast(oRow.Item("BYTE_DATA"), Byte())
}
Logger.Debug("Document path: [{0}]", oData.DocumentPath)

View File

@ -12,8 +12,8 @@ Public Class EmailModel
Public Function Insert(pEmail As EmailData) As Boolean
Try
Dim oSql = "INSERT INTO [dbo].[TBEMLP_EMAIL_OUT] "
oSql += " (EMAIL_ADRESS, EMAIL_SUBJ, EMAIL_BODY, ADDED_WHO, SENDING_PROFILE, REFERENCE_ID, REFERENCE_STRING, REMINDER_TYPE_ID, EMAIL_ATTMT1, WF_ID) "
oSql += " VALUES (@EMAIL_ADRESS, @EMAIL_SUBJ, @EMAIL_BODY, @ADDED_WHO, @SENDING_PROFILE, @REFERENCE_ID, @REFERENCE_STRING, @REMINDER_TYPE_ID, @EMAIL_ATTMT1, @WF_ID)"
oSql += " (EMAIL_ADRESS, EMAIL_SUBJ, EMAIL_BODY, ADDED_WHO, SENDING_PROFILE, REFERENCE_ID, REFERENCE_STRING, REMINDER_TYPE_ID, WF_ID,ATT1_RELATED_ID,ATT1_REL_TYPE) "
oSql += " VALUES (@EMAIL_ADRESS, @EMAIL_SUBJ, @EMAIL_BODY, @ADDED_WHO, @SENDING_PROFILE, @REFERENCE_ID, @REFERENCE_STRING, @REMINDER_TYPE_ID, @WF_ID,@ATT1_RELATED_ID,@ATT1_REL_TYPE)"
Dim oCommand As New SqlCommand(oSql)
oCommand.Parameters.Add("EMAIL_ADRESS", SqlDbType.NVarChar).Value = pEmail.EmailAdress
oCommand.Parameters.Add("EMAIL_SUBJ", SqlDbType.NVarChar).Value = pEmail.EmailSubject
@ -23,8 +23,10 @@ Public Class EmailModel
oCommand.Parameters.Add("REFERENCE_ID", SqlDbType.Int).Value = pEmail.ReferenceID
oCommand.Parameters.Add("REFERENCE_STRING", SqlDbType.NVarChar).Value = pEmail.ReferenceString
oCommand.Parameters.Add("REMINDER_TYPE_ID", SqlDbType.Int).Value = 202377
oCommand.Parameters.Add("EMAIL_ATTMT1", SqlDbType.NVarChar).Value = pEmail.EmailAttachment
'oCommand.Parameters.Add("EMAIL_ATTMT1", SqlDbType.NVarChar).Value = pEmail.EmailAttachment
oCommand.Parameters.Add("WF_ID", SqlDbType.Int).Value = pEmail.EmailType ' Wegen DB-Trigger MUSS dieser Wert gesetzt werden
oCommand.Parameters.Add("ATT1_RELATED_ID", SqlDbType.Int).Value = pEmail.ATT1_RELATED_ID
oCommand.Parameters.Add("ATT1_REL_TYP", SqlDbType.NVarChar).Value = pEmail.ATT1_REL_TYPE
If Database.ExecuteNonQuery(oCommand) Then
Return True

View File

@ -47,15 +47,6 @@ Public Class EnvelopeModel
.FinalEmailToCreator = ObjectEx.ToEnum(Of Constants.FinalEmailType)(pRow.ItemEx("FINAL_EMAIL_TO_CREATOR", Constants.FinalEmailType.No.ToString())),
.FinalEmailToReceivers = ObjectEx.ToEnum(Of Constants.FinalEmailType)(pRow.ItemEx("FINAL_EMAIL_TO_RECEIVERS", Constants.FinalEmailType.No.ToString()))
}
Dim oDoc1 = pRow.Item("DOC1")
If Not IsDBNull(oDoc1) Then
Dim oByte As Byte() = DirectCast(pRow.Item("DOC1"), Byte())
If Not IsNothing(oByte) Then
oEnvelope.Doc1 = oByte
End If
Else
oEnvelope.Doc1 = Nothing
End If
Dim oDOC_RESULT = pRow.Item("DOC_RESULT")
If Not IsDBNull(oDOC_RESULT) Then
Dim oByte As Byte() = DirectCast(pRow.Item("DOC_RESULT"), Byte())

View File

@ -108,20 +108,20 @@ Public Class ActionService
Return True
End Function
Public Function CompleteEnvelope(pEnvelope As Envelope, pReceiver As EnvelopeReceiver, pAttachment As String) As Boolean
Public Function CompleteEnvelope(pEnvelope As Envelope, pReceiver As EnvelopeReceiver) As Boolean ', pAttachment As String
If HistoryService.SetEnvelopeStatus(pEnvelope, Constants.EnvelopeStatus.MessageCompletionSent, pReceiver.Email) = False Then
Return False
End If
Return EmailService.SendDocumentCompletedEmailToReceiver(pEnvelope, pReceiver, pAttachment)
Return EmailService.SendDocumentCompletedEmailToReceiver(pEnvelope, pReceiver) ', pAttachment
End Function
Public Function CompleteEnvelope(pEnvelope As Envelope, pAttachment As String) As Boolean
Public Function CompleteEnvelope(pEnvelope As Envelope) As Boolean ', pAttachment As String
If HistoryService.SetEnvelopeStatus(pEnvelope, Constants.EnvelopeStatus.MessageCompletionSent, pEnvelope.User.Email) = False Then
Return False
End If
Return EmailService.SendDocumentCompletedEmailToCreator(pEnvelope, pAttachment)
Return EmailService.SendDocumentCompletedEmailToCreator(pEnvelope) ', pAttachment
End Function
Public Function CreateReport(pEnvelope As Envelope) As Boolean

View File

@ -83,14 +83,15 @@ Public Class EmailService
Return True
End Function
Public Function SendDocumentCompletedEmailToReceiver(pEnvelope As Envelope, pReceiver As EnvelopeReceiver, pAttachment As String) As Boolean
Public Function SendDocumentCompletedEmailToReceiver(pEnvelope As Envelope, pReceiver As EnvelopeReceiver) As Boolean ', pAttachment As String
Logger.Debug("Creating email data object.")
Dim oEmailData = New EmailData(pEnvelope, pReceiver, Constants.EnvelopeStatus.MessageCompletionSent) With
{
.SignatureLink = "",
.EmailAttachment = pAttachment
.ATT1_RELATED_ID = pEnvelope.Id,
.ATT1_REL_TYPE = "EnvelopeResult"
}
' .EmailAttachment = pAttachment,
Logger.Debug("Sending mail to receiver: [{0}]", oEmailData.EmailAdress)
EmailTemplate.FillDocumentCompletedEmailBody(oEmailData)
@ -103,14 +104,15 @@ Public Class EmailService
Return True
End Function
Public Function SendDocumentCompletedEmailToCreator(pEnvelope As Envelope, pAttachment As String) As Boolean
Public Function SendDocumentCompletedEmailToCreator(pEnvelope As Envelope) As Boolean ', pAttachment As String
Logger.Debug("Creating email data object.")
Dim oEmailData = New EmailData(pEnvelope, Constants.EnvelopeStatus.MessageCompletionSent) With
{
.SignatureLink = "",
.EmailAttachment = pAttachment
.ATT1_RELATED_ID = pEnvelope.Id,
.ATT1_REL_TYPE = "EnvelopeResult"
}
'.EmailAttachment = pAttachment,
EmailTemplate.FillDocumentCompletedEmailBody(oEmailData)
If EmailModel.Insert(oEmailData) = False Then

View File

@ -144,6 +144,7 @@
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<Compile Include="Scheduler.vb" />
<Compile Include="TempFiles.vb" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="My Project\Resources.resx">

View File

@ -14,7 +14,7 @@ Public Class Service
Private ConfigManager As ConfigManager(Of Config)
Private Config As Config
Private Database As MSSQLServer
Private TempFiles As TempFiles
Private Scheduler As Scheduler
Protected Overrides Async Sub OnStart(ByVal args() As String)
@ -33,9 +33,10 @@ Public Class Service
Logger.Info($"DEBUG = {LogConfig.Debug}")
Logger.Info("Starting [{0}]", ServiceName)
TempFiles = New TempFiles(LogConfig)
TempFiles.Create()
' === Initialize Databases ===
Logger.Info("Inititalize Databases")
If Config.ConnectionString = String.Empty Then
@ -72,6 +73,7 @@ Public Class Service
Try
Logger.Info("Stopping [{0}] !", ServiceName)
Await Scheduler.Stop()
TempFiles.CleanUp()
Logger.Info("Stopped [{0}] !", ServiceName)
Catch ex As Exception
Logger.Error(ex)

View File

@ -0,0 +1,60 @@
Imports System.IO
Imports DigitalData.Modules.Base
Imports DigitalData.Modules.Logging
Public Class TempFiles
Inherits BaseClass
Public Property TempPath As String
Public Sub New(pLogConfig As LogConfig)
MyBase.New(pLogConfig)
Dim oTempDirectoryPath = Path.GetTempPath()
TempPath = Path.Combine(oTempDirectoryPath, "EnvelopeGenerator")
End Sub
Public Function Create() As Boolean
Try
If Directory.Exists(TempPath) = False Then
Directory.CreateDirectory(TempPath)
Else
CleanUpFiles()
End If
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
Private Function CleanUpFiles() As Boolean
Try
For Each fileItem As String In Directory.GetFiles(TempPath)
Logger.Debug("Deleting tempPath-file: {0} ...", fileItem)
File.Delete(fileItem)
Next
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
Public Function CleanUp() As Boolean
Try
Logger.Debug("Deleting tempPath-Data: {0} ...", TempPath)
Directory.Delete(TempPath, True)
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
End Function
End Class