First version of service

This commit is contained in:
Jonathan Jenne
2023-12-08 15:23:50 +01:00
parent feb429f8f8
commit 49e6da3d79
5 changed files with 85 additions and 49 deletions

View File

@@ -41,9 +41,6 @@ Namespace Jobs
Logger.Info("Starting job {0}", JobId)
Try
InitializeModels()
InitializeServices()
Logger.Debug("Loading GdViewer..")
GdViewer = New GdViewer()
LicenseManager.RegisterKEY(oGdPictureKey)
@@ -54,9 +51,16 @@ Namespace Jobs
Logger.Debug("Loading Database..")
Database = GetDatabase(pContext, LogConfig)
Logger.Debug("Loading Models & Services")
InitializeModels()
InitializeServices()
Logger.Debug("Loading Configuration..")
Config = ConfigModel.LoadConfiguration()
Logger.Debug("DocumentPath: [{0}]", Config.DocumentPath)
Logger.Debug("ExportPath: [{0}]", Config.ExportPath)
Dim oCompleteStatus As Integer = Constants.EnvelopeStatus.EnvelopeCompletelySigned
Dim oSql = $"SELECT * FROM TBSIG_ENVELOPE WHERE STATUS = {oCompleteStatus}"
Dim oTable = Database.GetDatatable(oSql)
@@ -155,35 +159,35 @@ Namespace Jobs
Return True
End Function
Private Async Function GenerateReportPdf(pEnvelopeId As Integer) As Task(Of Byte())
Dim oSql As String = $"SELECT * FROM VWSIG_ENVELOPE_REPORT WHERE ENVELOPE_ID = {pEnvelopeId}"
Dim oTable As DataTable = Database.GetDatatable(oSql)
Dim oItems = GetReportSource(oTable)
'Private Async Function GenerateReportPdf(pEnvelopeId As Integer) As Task(Of Byte())
' Dim oSql As String = $"SELECT * FROM VWSIG_ENVELOPE_REPORT WHERE ENVELOPE_ID = {pEnvelopeId}"
' Dim oTable As DataTable = Database.GetDatatable(oSql)
' Dim oItems = GetReportSource(oTable)
If oItems.Count = 0 Then
Return Nothing
End If
' If oItems.Count = 0 Then
' Return Nothing
' End If
Dim oState As New State() With {
.Database = Database,
.LogConfig = LogConfig
}
EnvelopeModel = New EnvelopeModel(oState)
Dim oEnvelope = EnvelopeModel.GetById(pEnvelopeId)
' Dim oState As New State() With {
' .Database = Database,
' .LogConfig = LogConfig
' }
' EnvelopeModel = New EnvelopeModel(oState)
' Dim oEnvelope = EnvelopeModel.GetById(pEnvelopeId)
Dim oCreator As New ReportCreator(oEnvelope)
Dim oBuffer = Await oCreator.CreateReport(oItems)
' Dim oCreator As New ReportCreator(oEnvelope)
' Dim oBuffer = Await oCreator.CreateReport(oItems)
Return oBuffer
End Function
' Return oBuffer
'End Function
Private Function GetReportSource(pDataTable As DataTable) As List(Of ReportItem)
Return pDataTable.Rows.
Cast(Of DataRow).
Select(AddressOf ToReportItem).
OrderByDescending(Function(r) r.ItemDate).
ToList()
End Function
'Private Function GetReportSource(pDataTable As DataTable) As List(Of ReportItem)
' Return pDataTable.Rows.
' Cast(Of DataRow).
' Select(AddressOf ToReportItem).
' OrderByDescending(Function(r) r.ItemDate).
' ToList()
'End Function
Private Function GetEnvelopeData(pEnvelopeId As Integer) As EnvelopeData
Dim oSql = $"SELECT T.GUID, T2.FILEPATH FROM [dbo].[TBSIG_ENVELOPE] T
@@ -202,6 +206,8 @@ Namespace Jobs
.AnnotationData = oAnnotationData
}
Logger.Debug("Document path: [{0}]", oData.DocumentPath)
Return oData
End Function
Private Function GetAnnotationData(pEnvelopeId As Integer) As List(Of String)
@@ -217,13 +223,13 @@ Namespace Jobs
Private Function ToReportItem(pRow As DataRow) As ReportItem
Return New ReportItem() With {
.EnvelopeId = pRow.Item("ENVELOPE_ID"),
.EnvelopeTitle = pRow.ItemEx("HEAD_TITLE", String.Empty),
.EnvelopeSubject = pRow.ItemEx("HEAD_SUBJECT", String.Empty),
.ItemDate = pRow.ItemEx(Of Date)("POS_WHEN", Nothing),
.ItemStatus = pRow.ItemEx("POS_STATUS", 0),
.ItemUserReference = pRow.ItemEx("POS_WHO", "")
}
.EnvelopeId = pRow.Item("ENVELOPE_ID"),
.EnvelopeTitle = pRow.ItemEx("HEAD_TITLE", String.Empty),
.EnvelopeSubject = pRow.ItemEx("HEAD_SUBJECT", String.Empty),
.ItemDate = pRow.ItemEx(Of Date)("POS_WHEN", Nothing),
.ItemStatus = pRow.ItemEx("POS_STATUS", 0),
.ItemUserReference = pRow.ItemEx("POS_WHO", "")
}
End Function
Private Sub InitializeServices()
@@ -245,9 +251,12 @@ Namespace Jobs
End Function
Private Function GetState() As State
Return New State() With {
Return New State With {
.LogConfig = LogConfig,
.Database = Database
.Database = Database,
.UserId = 0,
.Config = Nothing,
.DbConfig = Nothing
}
End Function
End Class

View File

@@ -27,8 +27,11 @@ Namespace Jobs
End Sub
Public Function BurnInstantJSONAnnotationsToPDF(pSourceFilePath As String, pInstantJSONList As List(Of String), pDestinationDirectoryPath As String) As Boolean
If Manager.InitFromFile(pSourceFilePath) <> GdPictureStatus.OK Then
Logger.Warn("Could not open file [{0}] for burning.", pSourceFilePath)
Dim oResult As GdPictureStatus
oResult = Manager.InitFromFile(pSourceFilePath)
If oResult <> GdPictureStatus.OK Then
Logger.Warn("Could not open file [{0}] for burning: [{1}]", pSourceFilePath, oResult.ToString)
Return False
End If
@@ -41,10 +44,21 @@ Namespace Jobs
Dim oFileInfo As New FileInfo(pSourceFilePath)
Dim oDestinationFilePath As String = Path.Combine(pDestinationDirectoryPath, oFileInfo.Name)
Try
Logger.Debug("Export filepath: [{0}]", oDestinationFilePath)
Try
oResult = Manager.BurnAnnotationsToPage(RemoveInitialAnnots:=True, VectorMode:=True)
If oResult <> GdPictureStatus.OK Then
Logger.Warn("Could not burn annotations to file file [{0}]: [{1}]", pSourceFilePath, oResult.ToString)
Return False
End If
oResult = Manager.SaveDocumentToPDF(oDestinationFilePath)
If oResult <> GdPictureStatus.OK Then
Logger.Warn("Could not save file [{0}] to path [{1}]: [{2}]", oFileInfo.Name, oDestinationFilePath, oResult.ToString)
Return False
End If
Manager.BurnAnnotationsToPage(RemoveInitialAnnots:=True, VectorMode:=True)
Manager.SaveDocumentToPDF(oDestinationFilePath)
Manager.Close()
Return True

View File

@@ -13,7 +13,7 @@ Public Class ConfigModel
Try
Dim oSql As String = "SELECT TOP 1 * FROM TBSIG_CONFIG"
Dim oTable As DataTable = Database.GetDatatable(oSql)
Dim oRow = oTable.Rows.Item(0)
Dim oRow As DataRow = oTable.Rows.Item(0)
Return New DbConfig() With {
.DocumentPath = oRow.ItemEx("DOCUMENT_PATH", ""),
@@ -23,6 +23,7 @@ Public Class ConfigModel
.ExternalProgramName = oRow.ItemEx("EXTERNAL_PROGRAM_NAME", "")
}
Catch ex As Exception
Logger.Error(ex)
Return New DbConfig()
End Try
End Function