Ms Änderungen FileCopy

This commit is contained in:
2024-03-28 11:26:32 +01:00
parent 56eb385312
commit c14ed86181
10 changed files with 336 additions and 113 deletions

View File

@@ -13,6 +13,9 @@ Imports DevExpress.XtraBars.Docking
Imports System.ServiceModel
Imports DevExpress.XtraRichEdit.Export
Imports DevExpress.Pdf.Native.BouncyCastle.Asn1.Cms
Imports DevExpress.DataAccess.Sql
Imports DevExpress.DataProcessing
Imports Quartz.Logging.OperationName
Namespace Jobs
Public Class FinalizeDocumentJob
@@ -37,6 +40,7 @@ Namespace Jobs
Private ReportCreator As ReportCreator
Private ReadOnly CompleteWaitTime As Integer = 5
Private ParentFolderUID As String = ""
Private Class EnvelopeData
Public EnvelopeId As Integer
@@ -92,7 +96,7 @@ Namespace Jobs
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)
Logger.Debug("Using DMZRemotePath: [{0}] - Overwrite Document-Path ...", Config.DOCUMENT_PATH_MOVE_AFTSEND)
Config.DocumentPath = Config.DOCUMENT_PATH_MOVE_AFTSEND
Config.NetUse_Finish = True
@@ -120,7 +124,6 @@ Namespace Jobs
Logger.Debug("ExportPath: [{0}]", Config.ExportPath)
If Config.NetUse_Finish = True Then
Logger.Debug("NetUse_Finish = true, Now executing NetUse....")
If NetUse_Command(Config.DocumentPath, My.Settings.NetUse_Usr, My.Settings.NetUse_PW) = True Then
Logger.Debug("NetUse_Finish = successful!")
End If
@@ -164,7 +167,7 @@ Namespace Jobs
Throw New ArgumentNullException("EnvelopeData")
End If
Logger.Debug("Burning Annotations to pdf")
Logger.Debug("Burning Annotations to pdf ...")
Dim oBurnedDocument As Byte() = BurnAnnotationsToPdf(oEnvelopeData)
If oBurnedDocument Is Nothing Then
Logger.Warn("Document could not be finalized!")
@@ -178,14 +181,16 @@ Namespace Jobs
Logger.Debug("Creating report..")
Dim oReport As Byte() = ReportCreator.CreateReport(oEnvelope)
Logger.Debug("Report created.")
Logger.Debug("Report created!")
Logger.Debug("Merging documents..")
Logger.Debug("Merging documents ...")
Dim oMergedDocument As Byte() = PDFMerger.MergeDocuments(oBurnedDocument, oReport)
Logger.Debug("Documents merged.")
Dim oOutputDirectoryPath = Config.ExportPath
Logger.Debug("Documents merged!")
Dim oOutputDirectoryPath = Path.Combine(Config.ExportPath, ParentFolderUID)
If Not Directory.Exists(oOutputDirectoryPath) Then
Directory.CreateDirectory(oOutputDirectoryPath)
End If
Dim oOutputFilePath = Path.Combine(oOutputDirectoryPath, $"{oEnvelope.Uuid}.pdf")
Logger.Info("Writing finalized Pdf to disk..")
Logger.Info("Output path is [{0}]", oOutputFilePath)
@@ -197,26 +202,30 @@ Namespace Jobs
Throw New ExportDocumentException("Could not export final document to disk!", ex)
End Try
Logger.Info("Sending finalized report-mails..")
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
Logger.Debug($"Now replacing [{Config.FINISHED_PATH_EX_DMZ}] with ")
Logger.Debug($"............. [{Config.EML_PATH_EX_DMZ}] ")
oOutputFilePath = oOutputFilePath.Replace(Config.FINISHED_PATH_EX_DMZ, Config.EML_PATH_EX_DMZ)
Logger.Debug($"oOutputFilePath [{oOutputFilePath}] ")
End If
End If
Clean_DNZ_PAth(Config.FINISHED_PATH_EX_DMZ)
'Dim oReturnPath = MoveFileWithNetUse(Config.FINISHED_PATH_EX_DMZ, oOutputFilePath, My.Settings.NetUse_Usr, My.Settings.NetUse_PW)
'If oReturnPath <> String.Empty Then
' oOutputFilePath = oReturnPath
' If Config.EML_PATH_EX_DMZ <> String.Empty Then
' Logger.Debug($"Now replacing [{Config.FINISHED_PATH_EX_DMZ}] with ")
' Logger.Debug($"............. [{Config.EML_PATH_EX_DMZ}] ")
' oOutputFilePath = oOutputFilePath.Replace(Config.FINISHED_PATH_EX_DMZ, Config.EML_PATH_EX_DMZ)
' Logger.Debug($"oOutputFilePath [{oOutputFilePath}] ")
' End If
'Else
' Logger.Info($"Exiting/Aborting FinalizeDocuments!")
' Return Task.FromResult(False)
'End If
End If
End If
End If
Logger.Info("Sending finalized report-mails..")
If SendFinalEmails(oEnvelope, oOutputFilePath) = False Then
Throw New ApplicationException("Final emails could not be sent!")
@@ -254,7 +263,7 @@ Namespace Jobs
Private Function NetUse_Command(pDestinationPath As String, pUsername As String, pPassword As String)
Dim oDectryptedPW = Helpers.Decrypt(My.Settings.NetUse_PW)
Dim netUseCommand As String = $"net use {pDestinationPath} /user:{pUsername} {oDectryptedPW}"
Logger.Debug("EXECUTING NetUse_Command for " & pDestinationPath)
Dim processInfo As New ProcessStartInfo("cmd.exe", $"/C {netUseCommand}")
processInfo.RedirectStandardOutput = True
processInfo.UseShellExecute = False
@@ -271,57 +280,34 @@ Namespace Jobs
End If
End Using
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)
Private Function Clean_DNZ_PAth(pSourcePath As String) As Boolean
Dim oFilename = System.IO.Path.GetFileName(pSourcePath)
Dim netUseCommand As String = $"net use {pDestinationPath} /user:{pUsername} {oDectryptedPW}"
Logger.Debug("## Starting Clean_DNZ_PAth ...")
Logger.Debug("## pSourcePath {0}", pSourcePath)
Dim processInfo As New ProcessStartInfo("cmd.exe", $"/C {netUseCommand}")
processInfo.RedirectStandardOutput = True
processInfo.UseShellExecute = False
processInfo.CreateNoWindow = True
Dim oDirectorySource = Path.Combine(pSourcePath, ParentFolderUID)
Using oProcess As Process = Process.Start(processInfo)
oProcess.WaitForExit()
Try
Logger.Debug($"Deleting oDirectorySource {oDirectorySource} ...")
Directory.Delete(oDirectorySource, True)
Console.WriteLine($"Folder successfully deleted!")
Logger.Debug($"...Deleted!")
Return True
Catch ex As Exception
Logger.Error(ex)
Return False
End Try
' Prüfe den Rückgabewert des net use Befehls
If oProcess.ExitCode = 0 Then
' Verschiebe die Datei
Try
Dim oFilePath As String = pSourcePath
Dim oDirectory As String = Path.GetDirectoryName(oFilePath)
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)
Directory.Delete(oDirectory)
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
If oMailToCreator <> FinalEmailType.No Then
Logger.Debug("Sending email to creator..")
Logger.Debug("Sending email to creator ...")
SendFinalEmailToCreator(pEnvelope, pAttachment)
End If
@@ -396,6 +382,11 @@ Namespace Jobs
End If
Logger.Info("Input path: [{0}]", 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)