This commit is contained in:
Developer 02
2024-06-20 11:45:20 +02:00
21 changed files with 522 additions and 106 deletions

View File

@@ -31,6 +31,7 @@
Public Property Receivers As New List(Of EnvelopeReceiver)
Public Property History As New List(Of EnvelopeHistoryEntry)
Public Property EnvelopeType As EnvelopeType
Public Property DOC_RESULT As Byte()
Public ReadOnly Property EnvelopeTypeTitle As String
Get

View File

@@ -19,4 +19,5 @@ Public Class EnvelopeDocument
Public Property Filepath As String
Public Property PageCount As Integer
Public Property Byte_Data As Byte()
End Class

View File

@@ -16,6 +16,8 @@ Imports DevExpress.Pdf.Native.BouncyCastle.Asn1.Cms
Imports DevExpress.DataAccess.Sql
Imports DevExpress.DataProcessing
Imports Quartz.Logging.OperationName
Imports System.Data.SqlClient
Imports System.Windows.Forms
Namespace Jobs
Public Class FinalizeDocumentJob
@@ -46,6 +48,7 @@ Namespace Jobs
Public EnvelopeId As Integer
Public DocumentPath As String
Public AnnotationData As List(Of String)
Public DocAsByte As Byte()
End Class
@@ -86,6 +89,7 @@ Namespace Jobs
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
Logger.Debug("RuninDMZ - Using DocumentPath_DMZ: [{0}] - Overwrite Document-Path", Config.DocumentPath_DMZ)
@@ -126,7 +130,7 @@ Namespace Jobs
End If
Dim oCompleteStatus As Integer = Constants.EnvelopeStatus.EnvelopeCompletelySigned
Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {oCompleteStatus} AND DATEDIFF(minute, CHANGED_WHEN, GETDATE()) >= {CompleteWaitTime}"
Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {oCompleteStatus} AND DATEDIFF(minute, CHANGED_WHEN, GETDATE()) >= {CompleteWaitTime} ORDER BY GUID"
Dim oTable = Database.GetDatatable(oSql)
Dim oEnvelopeIds As List(Of Integer) = oTable.Rows.Cast(Of DataRow).
@@ -142,22 +146,16 @@ Namespace Jobs
Dim oCurrent As Integer = 1
For Each oId In oEnvelopeIds
Logger.Info("Finalizing Envelope [{0}] ({1}/{2})", oId, oCurrent, oTotal)
Logger.Debug("Loading Envelope..")
Dim oEnvelope = EnvelopeModel.GetById(oId)
If oEnvelope Is Nothing Then
Logger.Warn("Envelope could not be loaded for Id [{0}]!", oId)
Throw New ArgumentNullException("EnvelopeData")
End If
Logger.Debug("Loading Envelope Data..")
Dim oEnvelopeData = GetEnvelopeData(oId)
If oEnvelopeData Is Nothing Then
Logger.Warn("EnvelopeData could not be loaded for Id [{0}]!", oId)
Throw New ArgumentNullException("EnvelopeData")
@@ -201,35 +199,21 @@ Namespace Jobs
Throw New ExportDocumentException("Could not export final document to disk!", ex)
End Try
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
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("Writing EB-bytes to database...")
Update_File_DB(oOutputFilePath, oEnvelope.Id)
Logger.Info("Sending finalized report-mails..")
If SendFinalEmails(oEnvelope, oOutputFilePath) = False Then
Throw New ApplicationException("Final emails could not be sent!")
End If
Logger.Debug("Setting envelope status..")
If ActionService.FinalizeEnvelope(oEnvelope) = False Then
Logger.Warn("Envelope could not be finalized!")
@@ -259,6 +243,50 @@ Namespace Jobs
Return Task.FromResult(True)
End Function
Private Sub Update_File_DB(pFilePath As String, pEnvelopeID As Long)
Dim SqlCom As SqlCommand
Dim imageData As Byte()
Dim sFileName As String
Dim qry As String
Try
'Read Image Bytes into a byte array
'Initialize SQL Server Connection
'Convert File to bytes Array
imageData = ReadFile(pFilePath)
If Not IsNothing(imageData) Then
sFileName = System.IO.Path.GetFileName(pFilePath)
'Set insert query
qry = $"UPDATE TBSIG_ENVELOPE SET DOC_RESULT = @ImageData WHERE GUID = {pEnvelopeID}"
'Initialize SqlCommand object for insert.
SqlCom = New SqlCommand(qry, Database.GetConnection)
'We are passing File Name and Image byte data as sql parameters.
SqlCom.Parameters.Add(New SqlParameter("@ImageData", DirectCast(imageData, Object)))
'Execute the Query
SqlCom.ExecuteNonQuery()
End If
Catch ex As Exception
Logger.Error(ex)
End Try
End Sub
'Open file in to a filestream and read data in a byte array.
Private Function ReadFile(ByVal sPath As String) As Byte()
'Initialize byte array with a null value initially.
Dim data As Byte() = Nothing
'Use FileInfo object to get file size.
Dim fInfo As New FileInfo(sPath)
Dim numBytes As Long = fInfo.Length
'Open FileStream to read file
Dim fStream As New FileStream(sPath, FileMode.Open, FileAccess.Read)
'Use BinaryReader to read file stream into byte array.
Dim br As New BinaryReader(fStream)
'When you use BinaryReader, you need to supply number of bytes to read from file.
'In this case we want to read entire file. So supplying total number of bytes.
data = br.ReadBytes(CInt(numBytes))
Return data
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}"
@@ -400,7 +428,7 @@ Namespace Jobs
End Function
Private Function GetEnvelopeData(pEnvelopeId As Integer) As EnvelopeData
Dim oSql = $"SELECT T.GUID, T2.FILEPATH FROM [dbo].[TBSIG_ENVELOPE] T
Dim oSql = $"SELECT T.GUID, T2.FILEPATH, T2.BYTE_DATA FROM [dbo].[TBSIG_ENVELOPE] T
JOIN TBSIG_ENVELOPE_DOCUMENT T2 ON T.GUID = T2.ENVELOPE_ID
WHERE T.GUID = {pEnvelopeId}"
Dim oTable As DataTable = Database.GetDatatable(oSql)

View File

@@ -24,7 +24,8 @@ Public Class DocumentModel
.Filepath = pRow.ItemEx("FILEPATH", ""),
.FileNameOriginal = pRow.ItemEx("FILENAME_ORIGINAL", ""),
.IsTempFile = False,
.Elements = ElementModel.List(oDocumentId, pReceiverId)
.Elements = ElementModel.List(oDocumentId, pReceiverId),
.Byte_Data = DirectCast(pRow.Item("BYTE_DATA"), Byte())
}
End Function
@@ -79,18 +80,21 @@ Public Class DocumentModel
([FILENAME]
,[FILENAME_ORIGINAL]
,[FILEPATH]
,[ENVELOPE_ID])
,[ENVELOPE_ID]
,[BYTE_DATA])
VALUES
(@FILENAME
,@FILENAME_ORIGINAL
,@FILEPATH
,@ENVELOPE_ID)"
,@ENVELOPE_ID
,@BYTE_DATA)"
Dim oCommand As New SqlCommand(oSql)
oCommand.Parameters.Add("FILENAME", SqlDbType.NVarChar).Value = pDocument.Filename
oCommand.Parameters.Add("FILENAME_ORIGINAL", SqlDbType.NVarChar).Value = pDocument.FileNameOriginal
oCommand.Parameters.Add("FILEPATH", SqlDbType.NVarChar).Value = pDocument.Filepath
oCommand.Parameters.Add("ENVELOPE_ID", SqlDbType.Int).Value = pEnvelope.Id
oCommand.Parameters.Add(New SqlParameter("@BYTE_DATA", DirectCast(pDocument.Byte_Data, Object)))
If Database.ExecuteNonQuery(oCommand, pTransaction) Then
pDocument.EnvelopeId = pEnvelope.Id

View File

@@ -47,7 +47,24 @@ 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())
If Not IsNothing(oByte) Then
oEnvelope.DOC_RESULT = oByte
End If
Else
oEnvelope.DOC_RESULT = Nothing
End If
oEnvelope.User = UserModel.SelectUser(oEnvelope.UserId)
oEnvelope.Receivers = ReceiverModel.ListEnvelopeReceivers(oEnvelope.Id)
oEnvelope.Documents = DocumentModel.List(oEnvelope.Id)

View File

@@ -31,5 +31,5 @@ Imports System.Runtime.InteropServices
' indem Sie "*" wie unten gezeigt eingeben:
' <Assembly: AssemblyVersion("1.0.*")>
<Assembly: AssemblyVersion("1.6.0.0")>
<Assembly: AssemblyFileVersion("1.6.0.0")>
<Assembly: AssemblyVersion("1.7.0.0")>
<Assembly: AssemblyFileVersion("1.7.0.0")>