From 5abc1d9779548e18480b7374a55ae7079b47d8b8 Mon Sep 17 00:00:00 2001 From: SchreiberM Date: Tue, 19 Mar 2024 15:10:51 +0100 Subject: [PATCH] MS Common Verzeichnisstruktur --- EnvelopeGenerator.Common/Entities/DbConfig.vb | 1 + .../FinalizeDocument/FinalizeDocumentJob.vb | 77 ++++++++++++++----- .../Models/ConfigModel.vb | 1 + .../My Project/Settings.Designer.vb | 7 +- .../My Project/Settings.settings | 2 +- EnvelopeGenerator.Common/app.config | 9 +-- EnvelopeGenerator.Form/frmEnvelopeEditor.vb | 3 +- 7 files changed, 67 insertions(+), 33 deletions(-) diff --git a/EnvelopeGenerator.Common/Entities/DbConfig.vb b/EnvelopeGenerator.Common/Entities/DbConfig.vb index fc94f3d9..6089dfc8 100644 --- a/EnvelopeGenerator.Common/Entities/DbConfig.vb +++ b/EnvelopeGenerator.Common/Entities/DbConfig.vb @@ -1,5 +1,6 @@ Public Class DbConfig Public Property ExternalProgramName As String = "Sign Flow" + Public Property DocumentPathOrigin As String = "" Public Property DocumentPath As String = "" Public Property ExportPath As String = "" Public Property DocumentPath_DMZ As String = "" diff --git a/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb b/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb index 0e6fe232..65f46cc9 100644 --- a/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb +++ b/EnvelopeGenerator.Common/Jobs/FinalizeDocument/FinalizeDocumentJob.vb @@ -12,6 +12,7 @@ Imports EnvelopeGenerator.Common.Constants Imports DevExpress.XtraBars.Docking Imports System.ServiceModel Imports DevExpress.XtraRichEdit.Export +Imports DevExpress.Pdf.Native.BouncyCastle.Asn1.Cms Namespace Jobs Public Class FinalizeDocumentJob @@ -35,7 +36,7 @@ Namespace Jobs Private PDFMerger As PDFMerger Private ReportCreator As ReportCreator - Private ReadOnly CompleteWaitTimeInMinutes As Integer = 5 + Private ReadOnly CompleteWaitTime As Integer = 5 Private Class EnvelopeData Public EnvelopeId As Integer @@ -78,7 +79,8 @@ Namespace Jobs Logger.Debug("Loading ReportCreator..") ReportCreator = New ReportCreator(LogConfig, oState) - + Logger.Debug("My.Settings.RuninDMZ: [{0}]", My.Settings.RuninDMZ.ToString) + Logger.Debug("My.Settings.NetUse_Usr: [{0}]", My.Settings.NetUse_Usr) If My.Settings.RuninDMZ = True Then If Config.DocumentPath_DMZ <> String.Empty Then @@ -90,14 +92,16 @@ 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_necessary = True + Config.NetUse_Finish = True + Else Config.DocumentPath = Config.DocumentPath End If End If Logger.Debug("DocumentPath: [{0}]", Config.DocumentPath) + 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) @@ -109,20 +113,21 @@ Namespace Jobs 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.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 + 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 oSql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {oCompleteStatus} AND DATEDIFF(minute, CHANGED_WHEN, GETDATE()) >= {CompleteWaitTime}" Dim oTable = Database.GetDatatable(oSql) Dim oEnvelopeIds As List(Of Integer) = oTable.Rows.Cast(Of DataRow). @@ -149,6 +154,11 @@ Namespace Jobs Logger.Debug("Loading Envelope Data..") Dim oEnvelopeData = GetEnvelopeData(oId) + If Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then + oEnvelopeData.DocumentPath.Replace(Config.DocumentPathOrigin, Config.DOCUMENT_PATH_MOVE_AFTSEND) + Logger.Debug("Replaced Path in oEnvelopeData.DocumentPath!") + End If + If oEnvelopeData Is Nothing Then Logger.Warn("EnvelopeData could not be loaded for Id [{0}]!", oId) Throw New ArgumentNullException("EnvelopeData") @@ -187,7 +197,7 @@ Namespace Jobs Throw New ExportDocumentException("Could not export final document to disk!", ex) End Try - Logger.Info("Sending final Emails..") + Logger.Info("Sending finalized report-mails..") If Config.NetUse_Finish = True Then If Config.FINISHED_PATH_EX_DMZ <> String.Empty Then @@ -196,7 +206,10 @@ Namespace Jobs 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 End If @@ -238,7 +251,26 @@ Namespace Jobs Return Task.FromResult(True) End Function + 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}" + + 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 + Return True + Else + Return False + 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) Dim oFilename = System.IO.Path.GetFileName(pSourcePath) @@ -250,15 +282,15 @@ Namespace Jobs processInfo.UseShellExecute = False processInfo.CreateNoWindow = True - Using process As Process = Process.Start(processInfo) - process.WaitForExit() + Using oProcess As Process = Process.Start(processInfo) + oProcess.WaitForExit() ' Prüfe den Rückgabewert des net use Befehls - If process.ExitCode = 0 Then + 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 @@ -271,6 +303,7 @@ Namespace Jobs 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) @@ -352,8 +385,16 @@ Namespace Jobs Logger.Info("Burning [{0}] signatures", pData.AnnotationData.Count) Dim oAnnotations = pData.AnnotationData - Dim oInputPath = pData.DocumentPath - + Dim oInputPath = "" + + If My.Settings.RuninDMZ Then + oInputPath = pData.DocumentPath.Replace(Config.DocumentPathOrigin, Config.DocumentPath) + Logger.Debug("Replaced Path in pData.DocumentPath!") + ElseIf Config.DOCUMENT_PATH_MOVE_AFTSEND <> String.Empty Then + oInputPath = pData.DocumentPath.Replace(Config.DocumentPathOrigin, Config.DOCUMENT_PATH_MOVE_AFTSEND) + Logger.Debug("Replaced Path in pData.DocumentPath!") + End If + Logger.Info("Input path: [{0}]", oInputPath) Dim oInputDocumentBuffer As Byte() Try diff --git a/EnvelopeGenerator.Common/Models/ConfigModel.vb b/EnvelopeGenerator.Common/Models/ConfigModel.vb index 4769fc38..01e89f8b 100644 --- a/EnvelopeGenerator.Common/Models/ConfigModel.vb +++ b/EnvelopeGenerator.Common/Models/ConfigModel.vb @@ -17,6 +17,7 @@ Public Class ConfigModel Return New DbConfig() With { .DocumentPath = oRow.ItemEx("DOCUMENT_PATH", ""), + .DocumentPathOrigin = oRow.ItemEx("DOCUMENT_PATH", ""), .DocumentPath_DMZ = oRow.ItemEx("DOCUMENT_PATH_DMZ", ""), .ExportPath = oRow.ItemEx("EXPORT_PATH", ""), .ExportPath_DMZ = oRow.ItemEx("EXPORT_PATH_DMZ", ""), diff --git a/EnvelopeGenerator.Common/My Project/Settings.Designer.vb b/EnvelopeGenerator.Common/My Project/Settings.Designer.vb index 576fa5a0..aad32a06 100644 --- a/EnvelopeGenerator.Common/My Project/Settings.Designer.vb +++ b/EnvelopeGenerator.Common/My Project/Settings.Designer.vb @@ -72,16 +72,13 @@ Namespace My End Get End Property - _ - Public Property NetUse_PW() As String + Public ReadOnly Property NetUse_PW() As String Get Return CType(Me("NetUse_PW"),String) End Get - Set - Me("NetUse_PW") = value - End Set End Property End Class End Namespace diff --git a/EnvelopeGenerator.Common/My Project/Settings.settings b/EnvelopeGenerator.Common/My Project/Settings.settings index daa425de..f06f716e 100644 --- a/EnvelopeGenerator.Common/My Project/Settings.settings +++ b/EnvelopeGenerator.Common/My Project/Settings.settings @@ -8,7 +8,7 @@ dd-gan\Administrator - + sY4vnATDXwosbTJGip6SqA== diff --git a/EnvelopeGenerator.Common/app.config b/EnvelopeGenerator.Common/app.config index 19b61a68..63222b2e 100644 --- a/EnvelopeGenerator.Common/app.config +++ b/EnvelopeGenerator.Common/app.config @@ -5,9 +5,6 @@
- -
- @@ -40,13 +37,9 @@ dd-gan\Administrator - - - - sY4vnATDXwosbTJGip6SqA== - + diff --git a/EnvelopeGenerator.Form/frmEnvelopeEditor.vb b/EnvelopeGenerator.Form/frmEnvelopeEditor.vb index 679d27e0..bf3b9bea 100644 --- a/EnvelopeGenerator.Form/frmEnvelopeEditor.vb +++ b/EnvelopeGenerator.Form/frmEnvelopeEditor.vb @@ -364,7 +364,7 @@ Partial Public Class frmEnvelopeEditor ' 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 @@ -376,6 +376,7 @@ Partial Public Class frmEnvelopeEditor File.Delete(pDestinationPath) End If System.IO.File.Move(pSourcePath, pDestinationPath) + System.IO.Directory.Delete(oDirectory) Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Critical, "Unexpected error in MoveFileWithNetUse") End Try