This commit is contained in:
SchreiberM 2024-06-25 08:42:42 +02:00
parent a7f38eafb2
commit 29eac347c3
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 EnvelopeTitle As String = ""
Public Property EmailAttachment As String = "" Public Property EmailAttachment As String = ""
Public Property ATT1_RELATED_ID As Long
Public Property ATT1_REL_TYPE As String = ""
''' <summary> ''' <summary>
''' Constructor for sending email to receiver ''' Constructor for sending email to receiver

View File

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

View File

@ -12,8 +12,8 @@ Public Class EmailModel
Public Function Insert(pEmail As EmailData) As Boolean Public Function Insert(pEmail As EmailData) As Boolean
Try Try
Dim oSql = "INSERT INTO [dbo].[TBEMLP_EMAIL_OUT] " 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 += " (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, @EMAIL_ATTMT1, @WF_ID)" 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) Dim oCommand As New SqlCommand(oSql)
oCommand.Parameters.Add("EMAIL_ADRESS", SqlDbType.NVarChar).Value = pEmail.EmailAdress oCommand.Parameters.Add("EMAIL_ADRESS", SqlDbType.NVarChar).Value = pEmail.EmailAdress
oCommand.Parameters.Add("EMAIL_SUBJ", SqlDbType.NVarChar).Value = pEmail.EmailSubject 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_ID", SqlDbType.Int).Value = pEmail.ReferenceID
oCommand.Parameters.Add("REFERENCE_STRING", SqlDbType.NVarChar).Value = pEmail.ReferenceString oCommand.Parameters.Add("REFERENCE_STRING", SqlDbType.NVarChar).Value = pEmail.ReferenceString
oCommand.Parameters.Add("REMINDER_TYPE_ID", SqlDbType.Int).Value = 202377 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("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 If Database.ExecuteNonQuery(oCommand) Then
Return True 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())), .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())) .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") Dim oDOC_RESULT = pRow.Item("DOC_RESULT")
If Not IsDBNull(oDOC_RESULT) Then If Not IsDBNull(oDOC_RESULT) Then
Dim oByte As Byte() = DirectCast(pRow.Item("DOC_RESULT"), Byte()) Dim oByte As Byte() = DirectCast(pRow.Item("DOC_RESULT"), Byte())

View File

@ -108,20 +108,20 @@ Public Class ActionService
Return True Return True
End Function 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 If HistoryService.SetEnvelopeStatus(pEnvelope, Constants.EnvelopeStatus.MessageCompletionSent, pReceiver.Email) = False Then
Return False Return False
End If End If
Return EmailService.SendDocumentCompletedEmailToReceiver(pEnvelope, pReceiver, pAttachment) Return EmailService.SendDocumentCompletedEmailToReceiver(pEnvelope, pReceiver) ', pAttachment
End Function 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 If HistoryService.SetEnvelopeStatus(pEnvelope, Constants.EnvelopeStatus.MessageCompletionSent, pEnvelope.User.Email) = False Then
Return False Return False
End If End If
Return EmailService.SendDocumentCompletedEmailToCreator(pEnvelope, pAttachment) Return EmailService.SendDocumentCompletedEmailToCreator(pEnvelope) ', pAttachment
End Function End Function
Public Function CreateReport(pEnvelope As Envelope) As Boolean Public Function CreateReport(pEnvelope As Envelope) As Boolean

View File

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

View File

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

View File

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