restructure job
This commit is contained in:
@@ -142,6 +142,7 @@
|
|||||||
<Compile Include="Jobs\FinalizeDocument\FinalizeDocumentExceptions.vb" />
|
<Compile Include="Jobs\FinalizeDocument\FinalizeDocumentExceptions.vb" />
|
||||||
<Compile Include="Jobs\FinalizeDocument\FinalizeDocumentJob.vb" />
|
<Compile Include="Jobs\FinalizeDocument\FinalizeDocumentJob.vb" />
|
||||||
<Compile Include="Jobs\FinalizeDocument\PDFBurner.vb" />
|
<Compile Include="Jobs\FinalizeDocument\PDFBurner.vb" />
|
||||||
|
<Compile Include="Jobs\FinalizeDocument\PDFMerger.vb" />
|
||||||
<Compile Include="Models\BaseModel.vb" />
|
<Compile Include="Models\BaseModel.vb" />
|
||||||
<Compile Include="Models\CertificateModel.vb" />
|
<Compile Include="Models\CertificateModel.vb" />
|
||||||
<Compile Include="Models\ChartModel.vb" />
|
<Compile Include="Models\ChartModel.vb" />
|
||||||
@@ -182,6 +183,7 @@
|
|||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Services\ActionService.vb" />
|
<Compile Include="Services\ActionService.vb" />
|
||||||
|
<Compile Include="Services\BaseService.vb" />
|
||||||
<Compile Include="Services\EmailService.vb" />
|
<Compile Include="Services\EmailService.vb" />
|
||||||
<Compile Include="Services\HistoryService.vb" />
|
<Compile Include="Services\HistoryService.vb" />
|
||||||
<Compile Include="Strings\Email.en.Designer.vb">
|
<Compile Include="Strings\Email.en.Designer.vb">
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ Imports System.Security.Cryptography
|
|||||||
Imports System.IO
|
Imports System.IO
|
||||||
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument.FinalizeDocumentExceptions
|
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument.FinalizeDocumentExceptions
|
||||||
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument
|
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument
|
||||||
Imports System.Web.Caching
|
|
||||||
Imports System.Web.UI
|
|
||||||
|
|
||||||
Namespace Jobs
|
Namespace Jobs
|
||||||
Public Class FinalizeDocumentJob
|
Public Class FinalizeDocumentJob
|
||||||
@@ -29,8 +27,11 @@ Namespace Jobs
|
|||||||
Private ActionService As ActionService
|
Private ActionService As ActionService
|
||||||
|
|
||||||
Private PDFBurner As PDFBurner
|
Private PDFBurner As PDFBurner
|
||||||
|
Private PDFMerger As PDFMerger
|
||||||
Private ReportCreator As ReportCreator
|
Private ReportCreator As ReportCreator
|
||||||
|
|
||||||
|
Private ReadOnly CompleteWaitTimeInMinutes As Integer = 5
|
||||||
|
|
||||||
Private Class EnvelopeData
|
Private Class EnvelopeData
|
||||||
Public EnvelopeId As Integer
|
Public EnvelopeId As Integer
|
||||||
Public DocumentPath As String
|
Public DocumentPath As String
|
||||||
@@ -62,6 +63,9 @@ Namespace Jobs
|
|||||||
Logger.Debug("Loading PDFBurner..")
|
Logger.Debug("Loading PDFBurner..")
|
||||||
PDFBurner = New PDFBurner(LogConfig, oGdPictureKey)
|
PDFBurner = New PDFBurner(LogConfig, oGdPictureKey)
|
||||||
|
|
||||||
|
Logger.Debug("Loading PDFMerger..")
|
||||||
|
PDFMerger = New PDFMerger(LogConfig, oGdPictureKey)
|
||||||
|
|
||||||
Logger.Debug("Loading ReportCreator..")
|
Logger.Debug("Loading ReportCreator..")
|
||||||
ReportCreator = New ReportCreator(LogConfig, oState)
|
ReportCreator = New ReportCreator(LogConfig, oState)
|
||||||
|
|
||||||
@@ -72,7 +76,7 @@ Namespace Jobs
|
|||||||
Logger.Debug("ExportPath: [{0}]", Config.ExportPath)
|
Logger.Debug("ExportPath: [{0}]", Config.ExportPath)
|
||||||
|
|
||||||
Dim oCompleteStatus As Integer = Constants.EnvelopeStatus.EnvelopeCompletelySigned
|
Dim oCompleteStatus As Integer = Constants.EnvelopeStatus.EnvelopeCompletelySigned
|
||||||
Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {oCompleteStatus}"
|
Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {oCompleteStatus} AND DATEDIFF(minute, CHANGED_WHEN, GETDATE()) >= {CompleteWaitTimeInMinutes}"
|
||||||
Dim oTable = Database.GetDatatable(oSql)
|
Dim oTable = Database.GetDatatable(oSql)
|
||||||
|
|
||||||
Dim oEnvelopeIds As List(Of Integer) = oTable.Rows.Cast(Of DataRow).
|
Dim oEnvelopeIds As List(Of Integer) = oTable.Rows.Cast(Of DataRow).
|
||||||
@@ -119,9 +123,11 @@ Namespace Jobs
|
|||||||
|
|
||||||
Logger.Debug("Creating report..")
|
Logger.Debug("Creating report..")
|
||||||
Dim oReport As Byte() = ReportCreator.CreateReport(oEnvelope)
|
Dim oReport As Byte() = ReportCreator.CreateReport(oEnvelope)
|
||||||
|
Logger.Debug("Report created.")
|
||||||
|
|
||||||
Logger.Debug("Merging documents..")
|
Logger.Debug("Merging documents..")
|
||||||
Dim oMergedDocument As Byte() = MergeDocuments(oBurnedDocument, oReport)
|
Dim oMergedDocument As Byte() = PDFMerger.MergeDocuments(oBurnedDocument, oReport)
|
||||||
|
Logger.Debug("Documents merged.")
|
||||||
|
|
||||||
Dim oOutputDirectoryPath = Config.ExportPath
|
Dim oOutputDirectoryPath = Config.ExportPath
|
||||||
Dim oOutputFilePath = Path.Combine(oOutputDirectoryPath, $"{oEnvelope.Uuid}.pdf")
|
Dim oOutputFilePath = Path.Combine(oOutputDirectoryPath, $"{oEnvelope.Uuid}.pdf")
|
||||||
@@ -156,50 +162,7 @@ Namespace Jobs
|
|||||||
Return Task.FromResult(True)
|
Return Task.FromResult(True)
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function MergeDocuments(pDocument As Byte(), pReport As Byte()) As Byte()
|
|
||||||
Using oDocumentStream As New MemoryStream(pDocument)
|
|
||||||
Using oReportStream As New MemoryStream(pReport)
|
|
||||||
Using oFinalStream As New MemoryStream()
|
|
||||||
Using oDocumentPDF As New GdPicturePDF()
|
|
||||||
Using oReportPDF As New GdPicturePDF()
|
|
||||||
Dim oStatus As GdPictureStatus = GdPictureStatus.OK
|
|
||||||
|
|
||||||
' Load the source file into memory
|
|
||||||
oDocumentPDF.LoadFromStream(oDocumentStream, True)
|
|
||||||
|
|
||||||
oStatus = oDocumentPDF.GetStat()
|
|
||||||
If oStatus <> GdPictureStatus.OK Then
|
|
||||||
Throw New MergeDocumentException($"Document could not be loaded: {oStatus}")
|
|
||||||
End If
|
|
||||||
|
|
||||||
' Load the report file into memory
|
|
||||||
oReportPDF.LoadFromStream(oReportStream, True)
|
|
||||||
oStatus = oReportPDF.GetStat()
|
|
||||||
If oStatus <> GdPictureStatus.OK Then
|
|
||||||
Throw New MergeDocumentException($"Report could not be loaded: {oStatus}")
|
|
||||||
End If
|
|
||||||
|
|
||||||
' Merge the documents
|
|
||||||
Dim oMergedPDF = oDocumentPDF.Merge2Documents(oDocumentPDF, oReportPDF)
|
|
||||||
oStatus = oMergedPDF.GetStat()
|
|
||||||
If oStatus <> GdPictureStatus.OK Then
|
|
||||||
Throw New MergeDocumentException($"Documents could not be merged: {oStatus}")
|
|
||||||
End If
|
|
||||||
|
|
||||||
' Convert to PDF/A
|
|
||||||
oMergedPDF.ConvertToPDFA(oFinalStream, PdfConversionConformance.PDF_A_1b, True, True)
|
|
||||||
oStatus = oDocumentPDF.GetStat()
|
|
||||||
If oStatus <> GdPictureStatus.OK Then
|
|
||||||
Throw New MergeDocumentException($"Document could not be converted to PDF/A: {oStatus}")
|
|
||||||
End If
|
|
||||||
|
|
||||||
Return oFinalStream.ToArray()
|
|
||||||
End Using
|
|
||||||
End Using
|
|
||||||
End Using
|
|
||||||
End Using
|
|
||||||
End Using
|
|
||||||
End Function
|
|
||||||
|
|
||||||
Private Function BurnAnnotationsToPdf(pData As EnvelopeData) As Byte()
|
Private Function BurnAnnotationsToPdf(pData As EnvelopeData) As Byte()
|
||||||
Dim pEnvelopeId = pData.EnvelopeId
|
Dim pEnvelopeId = pData.EnvelopeId
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ Namespace Jobs.FinalizeDocument
|
|||||||
Public Class PDFBurner
|
Public Class PDFBurner
|
||||||
Inherits BaseClass
|
Inherits BaseClass
|
||||||
|
|
||||||
Private ReadOnly LicenseKey As String
|
|
||||||
Private ReadOnly Manager As AnnotationManager
|
Private ReadOnly Manager As AnnotationManager
|
||||||
Private ReadOnly LicenseManager As LicenseManager
|
Private ReadOnly LicenseManager As LicenseManager
|
||||||
|
|
||||||
@@ -20,7 +19,6 @@ Namespace Jobs.FinalizeDocument
|
|||||||
Public Sub New(pLogConfig As LogConfig, pGDPictureLicenseKey As String)
|
Public Sub New(pLogConfig As LogConfig, pGDPictureLicenseKey As String)
|
||||||
MyBase.New(pLogConfig)
|
MyBase.New(pLogConfig)
|
||||||
|
|
||||||
LicenseKey = pGDPictureLicenseKey
|
|
||||||
LicenseManager = New LicenseManager()
|
LicenseManager = New LicenseManager()
|
||||||
LicenseManager.RegisterKEY(pGDPictureLicenseKey)
|
LicenseManager.RegisterKEY(pGDPictureLicenseKey)
|
||||||
|
|
||||||
|
|||||||
71
EnvelopeGenerator.Common/Jobs/FinalizeDocument/PDFMerger.vb
Normal file
71
EnvelopeGenerator.Common/Jobs/FinalizeDocument/PDFMerger.vb
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
Imports DigitalData.Modules.Base
|
||||||
|
Imports DigitalData.Modules.Logging
|
||||||
|
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument.FinalizeDocumentExceptions
|
||||||
|
Imports GdPicture14
|
||||||
|
Imports System.IO
|
||||||
|
|
||||||
|
Public Class PDFMerger
|
||||||
|
Inherits BaseClass
|
||||||
|
|
||||||
|
Private ReadOnly Manager As AnnotationManager
|
||||||
|
Private ReadOnly LicenseManager As LicenseManager
|
||||||
|
|
||||||
|
Private Const ALLOW_RASTERIZATION = True
|
||||||
|
Private Const ALLOW_VECTORIZATION = True
|
||||||
|
|
||||||
|
Private ReadOnly PDFAConformanceLevel As PdfConversionConformance = PdfConversionConformance.PDF_A_1b
|
||||||
|
|
||||||
|
Public Sub New(pLogConfig As LogConfig, pGDPictureLicenseKey As String)
|
||||||
|
MyBase.New(pLogConfig)
|
||||||
|
|
||||||
|
LicenseManager = New LicenseManager()
|
||||||
|
LicenseManager.RegisterKEY(pGDPictureLicenseKey)
|
||||||
|
|
||||||
|
Manager = New AnnotationManager()
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Public Function MergeDocuments(pDocument As Byte(), pReport As Byte()) As Byte()
|
||||||
|
Using oDocumentStream As New MemoryStream(pDocument)
|
||||||
|
Using oReportStream As New MemoryStream(pReport)
|
||||||
|
Using oFinalStream As New MemoryStream()
|
||||||
|
Using oDocumentPDF As New GdPicturePDF()
|
||||||
|
Using oReportPDF As New GdPicturePDF()
|
||||||
|
Dim oStatus As GdPictureStatus = GdPictureStatus.OK
|
||||||
|
|
||||||
|
' Load the source file into memory
|
||||||
|
oDocumentPDF.LoadFromStream(oDocumentStream, True)
|
||||||
|
|
||||||
|
oStatus = oDocumentPDF.GetStat()
|
||||||
|
If oStatus <> GdPictureStatus.OK Then
|
||||||
|
Throw New MergeDocumentException($"Document could not be loaded: {oStatus}")
|
||||||
|
End If
|
||||||
|
|
||||||
|
' Load the report file into memory
|
||||||
|
oReportPDF.LoadFromStream(oReportStream, True)
|
||||||
|
oStatus = oReportPDF.GetStat()
|
||||||
|
If oStatus <> GdPictureStatus.OK Then
|
||||||
|
Throw New MergeDocumentException($"Report could not be loaded: {oStatus}")
|
||||||
|
End If
|
||||||
|
|
||||||
|
' Merge the documents
|
||||||
|
Dim oMergedPDF = oDocumentPDF.Merge2Documents(oDocumentPDF, oReportPDF)
|
||||||
|
oStatus = oMergedPDF.GetStat()
|
||||||
|
If oStatus <> GdPictureStatus.OK Then
|
||||||
|
Throw New MergeDocumentException($"Documents could not be merged: {oStatus}")
|
||||||
|
End If
|
||||||
|
|
||||||
|
' Convert to PDF/A
|
||||||
|
oMergedPDF.ConvertToPDFA(oFinalStream, PDFAConformanceLevel, ALLOW_VECTORIZATION, ALLOW_RASTERIZATION)
|
||||||
|
oStatus = oDocumentPDF.GetStat()
|
||||||
|
If oStatus <> GdPictureStatus.OK Then
|
||||||
|
Throw New MergeDocumentException($"Document could not be converted to PDF/A: {oStatus}")
|
||||||
|
End If
|
||||||
|
|
||||||
|
Return oFinalStream.ToArray()
|
||||||
|
End Using
|
||||||
|
End Using
|
||||||
|
End Using
|
||||||
|
End Using
|
||||||
|
End Using
|
||||||
|
End Function
|
||||||
|
End Class
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
Imports DigitalData.Modules.Base
|
Imports DigitalData.Modules.Base
|
||||||
|
|
||||||
Public Class ActionService
|
Public Class ActionService
|
||||||
Inherits BaseClass
|
Inherits BaseService
|
||||||
|
|
||||||
Private ReadOnly EmailService As EmailService
|
Private ReadOnly EmailService As EmailService
|
||||||
Private ReadOnly HistoryService As HistoryService
|
Private ReadOnly HistoryService As HistoryService
|
||||||
@@ -11,7 +11,7 @@ Public Class ActionService
|
|||||||
|
|
||||||
|
|
||||||
Public Sub New(pState As State)
|
Public Sub New(pState As State)
|
||||||
MyBase.New(pState.LogConfig)
|
MyBase.New(pState)
|
||||||
|
|
||||||
EmailService = New EmailService(pState)
|
EmailService = New EmailService(pState)
|
||||||
HistoryService = New HistoryService(pState)
|
HistoryService = New HistoryService(pState)
|
||||||
|
|||||||
13
EnvelopeGenerator.Common/Services/BaseService.vb
Normal file
13
EnvelopeGenerator.Common/Services/BaseService.vb
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
Imports DigitalData.Modules.Base
|
||||||
|
|
||||||
|
Public Class BaseService
|
||||||
|
Inherits BaseClass
|
||||||
|
|
||||||
|
Friend Property State As State
|
||||||
|
|
||||||
|
Public Sub New(pState As State)
|
||||||
|
MyBase.New(pState.LogConfig)
|
||||||
|
|
||||||
|
State = pState
|
||||||
|
End Sub
|
||||||
|
End Class
|
||||||
@@ -3,7 +3,7 @@ Imports DigitalData.Modules.Base
|
|||||||
Imports DigitalData.Modules.Logging
|
Imports DigitalData.Modules.Logging
|
||||||
|
|
||||||
Public Class EmailService
|
Public Class EmailService
|
||||||
Inherits BaseClass
|
Inherits BaseService
|
||||||
|
|
||||||
Private ReadOnly State As State
|
Private ReadOnly State As State
|
||||||
|
|
||||||
@@ -14,9 +14,8 @@ Public Class EmailService
|
|||||||
Private ReadOnly EmailTemplate As EmailTemplate
|
Private ReadOnly EmailTemplate As EmailTemplate
|
||||||
|
|
||||||
Public Sub New(pState As State)
|
Public Sub New(pState As State)
|
||||||
MyBase.New(pState.LogConfig)
|
MyBase.New(pState)
|
||||||
|
|
||||||
State = pState
|
|
||||||
EnvelopeModel = New EnvelopeModel(pState)
|
EnvelopeModel = New EnvelopeModel(pState)
|
||||||
ReceiverModel = New ReceiverModel(pState)
|
ReceiverModel = New ReceiverModel(pState)
|
||||||
EmailModel = New EmailModel(pState)
|
EmailModel = New EmailModel(pState)
|
||||||
|
|||||||
@@ -4,18 +4,15 @@ Imports DigitalData.Modules.Logging
|
|||||||
Imports EnvelopeGenerator.Common.Constants
|
Imports EnvelopeGenerator.Common.Constants
|
||||||
|
|
||||||
Public Class HistoryService
|
Public Class HistoryService
|
||||||
Inherits BaseClass
|
Inherits BaseService
|
||||||
|
|
||||||
Private ReadOnly State As State
|
|
||||||
|
|
||||||
Private ReadOnly EnvelopeModel As EnvelopeModel
|
Private ReadOnly EnvelopeModel As EnvelopeModel
|
||||||
Private ReadOnly ReceiverModel As ReceiverModel
|
Private ReadOnly ReceiverModel As ReceiverModel
|
||||||
Private ReadOnly HistoryModel As HistoryModel
|
Private ReadOnly HistoryModel As HistoryModel
|
||||||
|
|
||||||
Public Sub New(pState As State)
|
Public Sub New(pState As State)
|
||||||
MyBase.New(pState.LogConfig)
|
MyBase.New(pState)
|
||||||
|
|
||||||
State = pState
|
|
||||||
EnvelopeModel = New EnvelopeModel(pState)
|
EnvelopeModel = New EnvelopeModel(pState)
|
||||||
ReceiverModel = New ReceiverModel(pState)
|
ReceiverModel = New ReceiverModel(pState)
|
||||||
HistoryModel = New HistoryModel(pState)
|
HistoryModel = New HistoryModel(pState)
|
||||||
|
|||||||
Reference in New Issue
Block a user