MS Common V 1.5 New paths for email-Service

This commit is contained in:
2024-03-15 11:47:14 +01:00
parent 21baf0bad0
commit a25b517445
14 changed files with 265 additions and 32 deletions

View File

@@ -9,6 +9,9 @@ Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument.FinalizeDocumentException
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument
Imports EnvelopeGenerator.Common.My.Resources
Imports EnvelopeGenerator.Common.Constants
Imports DevExpress.XtraBars.Docking
Imports System.ServiceModel
Imports DevExpress.XtraRichEdit.Export
Namespace Jobs
Public Class FinalizeDocumentJob
@@ -76,16 +79,48 @@ Namespace Jobs
Logger.Debug("Loading ReportCreator..")
ReportCreator = New ReportCreator(LogConfig, oState)
If My.Settings.RuninDMZ = True Then
If Config.DocumentPath_DMZ <> String.Empty Then
Logger.Debug("RuninDMZ - Using DocumentPath_DMZ: [{0}] - Overwrite Document-Path", Config.DocumentPath_DMZ)
Config.DocumentPath = Config.DocumentPath_DMZ
Config.NetUse_necessary = True
Else
Config.DocumentPath = Config.DocumentPath
End If
Else
If Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then
Logger.Debug("Using DMZRemotePath: [{0}] - Overwrite Document-Path", Config.DOCUMENT_PATH_MOVE_AFTSEND)
Config.DocumentPath = Config.DOCUMENT_PATH_MOVE_AFTSEND
Config.NetUse_necessary = True
Else
Config.DocumentPath = Config.DocumentPath
End If
End If
Logger.Debug("DocumentPath: [{0}]", Config.DocumentPath)
If Config.DocumentPath_DMZ <> String.Empty Then
Logger.Debug("DMZ-DocPath configured: [{0}] - Overwrite Document-Path", Config.DocumentPath_DMZ)
Config.DocumentPath = Config.DocumentPath_DMZ
If My.Settings.RuninDMZ = True Then
If Config.FINISHED_PATH_EX_DMZ <> String.Empty Then
Logger.Debug("RuninDMZ - FINISHED_PATH_EX_DMZ configured: [{0}]", Config.FINISHED_PATH_EX_DMZ)
Config.NetUse_Finish = True
End If
If Config.ExportPath_DMZ <> String.Empty Then
Logger.Debug("RuninDMZ - Using ExportPath_DMZ: [{0}] - Overwrite ExportPath", Config.ExportPath_DMZ)
Config.ExportPath = Config.ExportPath_DMZ
Else
Config.ExportPath = Config.ExportPath
End If
ElseIf Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then
Logger.Debug("DOCUMENT_PATH_MOVE_AFTSEND configured: [{0}] - Overwrite ExportPath", Config.DOCUMENT_PATH_MOVE_AFTSEND)
Config.ExportPath = Config.DOCUMENT_PATH_MOVE_AFTSEND
Config.NetUse_Finish = True
Else
Config.ExportPath = Config.ExportPath
End If
Logger.Debug("ExportPath: [{0}]", Config.ExportPath)
If Config.ExportPath_DMZ <> String.Empty Then
Logger.Debug("DMZ-ExportPath configured: [{0}] - Overwrite ExportPath", Config.ExportPath_DMZ)
Config.ExportPath = Config.ExportPath_DMZ
End If
Dim oCompleteStatus As Integer = Constants.EnvelopeStatus.EnvelopeCompletelySigned
Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {oCompleteStatus} AND DATEDIFF(minute, CHANGED_WHEN, GETDATE()) >= {CompleteWaitTimeInMinutes}"
Dim oTable = Database.GetDatatable(oSql)
@@ -140,8 +175,8 @@ Namespace Jobs
Logger.Debug("Documents merged.")
Dim oOutputDirectoryPath = Config.ExportPath
Dim oOutputFilePath = Path.Combine(oOutputDirectoryPath, $"{oEnvelope.Uuid}.pdf")
Dim oOutputFilePath = Path.Combine(oOutputDirectoryPath, $"{oEnvelope.Uuid}.pdf")
Logger.Info("Writing finalized Pdf to disk..")
Logger.Info("Output path is [{0}]", oOutputFilePath)
@@ -154,6 +189,22 @@ Namespace Jobs
Logger.Info("Sending final Emails..")
If Config.NetUse_Finish = True 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
Dim oReturnPath = MoveFileWithNetUse(oOutputFilePath, Config.FINISHED_PATH_EX_DMZ, My.Settings.NetUse_Usr, My.Settings.NetUse_PW)
If oReturnPath <> String.Empty Then
oOutputFilePath = oReturnPath
If Config.EML_PATH_EX_DMZ <> String.Empty Then
oOutputFilePath = oOutputFilePath.Replace(Config.FINISHED_PATH_EX_DMZ, Config.EML_PATH_EX_DMZ)
End If
End If
End If
End If
End If
If SendFinalEmails(oEnvelope, oOutputFilePath) = False Then
Throw New ApplicationException("Final emails could not be sent!")
End If
@@ -188,6 +239,50 @@ Namespace Jobs
Return Task.FromResult(True)
End Function
Private Function MoveFileWithNetUse(pSourcePath As String, pDestinationPath As String, pUsername As String, pPassword As String) As String
Dim oDectryptedPW = Helpers.Decrypt(My.Settings.NetUse_PW)
Dim oFilename = System.IO.Path.GetFileName(pSourcePath)
Dim netUseCommand As String = $"net use {pDestinationPath} /user:{pUsername} {oDectryptedPW}"
Dim processInfo As New ProcessStartInfo("cmd.exe", $"/C {netUseCommand}")
processInfo.RedirectStandardOutput = True
processInfo.UseShellExecute = False
processInfo.CreateNoWindow = True
Using process As Process = Process.Start(processInfo)
process.WaitForExit()
' Prüfe den Rückgabewert des net use Befehls
If process.ExitCode = 0 Then
' Verschiebe die Datei
Try
Dim oFilePath As String = pSourcePath
Dim split As String() = oFilePath.Split("\")
Dim parentFolder As String = split(split.Length - 2)
pDestinationPath &= "\" + parentFolder
If Not System.IO.Directory.Exists(pDestinationPath) Then
System.IO.Directory.CreateDirectory(pDestinationPath)
End If
pDestinationPath &= "\" + oFilename
If File.Exists(pDestinationPath) Then
File.Delete(pDestinationPath)
End If
Logger.Info($"MoveFileWithNetUse To {pDestinationPath} ...")
System.IO.File.Move(pSourcePath, pDestinationPath)
Return pDestinationPath
Catch ex As Exception
Logger.Error(ex)
Return ""
End Try
Else
Logger.Warn("Error while connecting to network-path " & pDestinationPath)
Return ""
End If
End Using
End Function
Private Function SendFinalEmails(pEnvelope As Envelope, pAttachment As String) As Boolean
Dim oMailToCreator = pEnvelope.FinalEmailToCreator
Dim oMailToReceivers = pEnvelope.FinalEmailToReceivers
@@ -199,12 +294,7 @@ Namespace Jobs
If oMailToReceivers <> FinalEmailType.No Then
Logger.Debug("Sending emails to receivers..")
If Config.SignedMail_Path <> String.Empty And Config.ExportPath_DMZ <> String.Empty Then
Logger.Debug("SignedMailPath configured: [{0}] - Replacing Attachment-Path", Config.SignedMail_Path)
Logger.Debug("Attachment-Path BEFORE replace: [{0}]", pAttachment)
pAttachment.Replace(Config.ExportPath, Config.SignedMail_Path)
Logger.Debug("Attachment-Path AFTER replace: [{0}]", pAttachment)
End If
SendFinalEmailToReceivers(pEnvelope, pAttachment)
End If