restructure job

This commit is contained in:
Jonathan Jenne
2024-01-04 10:15:55 +01:00
parent 119f54e8aa
commit 26fe798a68
8 changed files with 102 additions and 59 deletions

View File

@@ -7,8 +7,6 @@ Imports System.Security.Cryptography
Imports System.IO
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument.FinalizeDocumentExceptions
Imports EnvelopeGenerator.Common.Jobs.FinalizeDocument
Imports System.Web.Caching
Imports System.Web.UI
Namespace Jobs
Public Class FinalizeDocumentJob
@@ -29,8 +27,11 @@ Namespace Jobs
Private ActionService As ActionService
Private PDFBurner As PDFBurner
Private PDFMerger As PDFMerger
Private ReportCreator As ReportCreator
Private ReadOnly CompleteWaitTimeInMinutes As Integer = 5
Private Class EnvelopeData
Public EnvelopeId As Integer
Public DocumentPath As String
@@ -62,6 +63,9 @@ Namespace Jobs
Logger.Debug("Loading PDFBurner..")
PDFBurner = New PDFBurner(LogConfig, oGdPictureKey)
Logger.Debug("Loading PDFMerger..")
PDFMerger = New PDFMerger(LogConfig, oGdPictureKey)
Logger.Debug("Loading ReportCreator..")
ReportCreator = New ReportCreator(LogConfig, oState)
@@ -72,7 +76,7 @@ Namespace Jobs
Logger.Debug("ExportPath: [{0}]", Config.ExportPath)
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 oEnvelopeIds As List(Of Integer) = oTable.Rows.Cast(Of DataRow).
@@ -119,9 +123,11 @@ Namespace Jobs
Logger.Debug("Creating report..")
Dim oReport As Byte() = ReportCreator.CreateReport(oEnvelope)
Logger.Debug("Report created.")
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 oOutputFilePath = Path.Combine(oOutputDirectoryPath, $"{oEnvelope.Uuid}.pdf")
@@ -156,50 +162,7 @@ Namespace Jobs
Return Task.FromResult(True)
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()
Dim pEnvelopeId = pData.EnvelopeId

View File

@@ -10,7 +10,6 @@ Namespace Jobs.FinalizeDocument
Public Class PDFBurner
Inherits BaseClass
Private ReadOnly LicenseKey As String
Private ReadOnly Manager As AnnotationManager
Private ReadOnly LicenseManager As LicenseManager
@@ -20,7 +19,6 @@ Namespace Jobs.FinalizeDocument
Public Sub New(pLogConfig As LogConfig, pGDPictureLicenseKey As String)
MyBase.New(pLogConfig)
LicenseKey = pGDPictureLicenseKey
LicenseManager = New LicenseManager()
LicenseManager.RegisterKEY(pGDPictureLicenseKey)

View 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