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

View File

@ -27,8 +27,11 @@ Namespace Jobs
End Sub End Sub
Public Function BurnInstantJSONAnnotationsToPDF(pSourceFilePath As String, pInstantJSONList As List(Of String), pDestinationDirectoryPath As String) As Boolean Public Function BurnInstantJSONAnnotationsToPDF(pSourceFilePath As String, pInstantJSONList As List(Of String), pDestinationDirectoryPath As String) As Boolean
If Manager.InitFromFile(pSourceFilePath) <> GdPictureStatus.OK Then Dim oResult As GdPictureStatus
Logger.Warn("Could not open file [{0}] for burning.", pSourceFilePath)
oResult = Manager.InitFromFile(pSourceFilePath)
If oResult <> GdPictureStatus.OK Then
Logger.Warn("Could not open file [{0}] for burning: [{1}]", pSourceFilePath, oResult.ToString)
Return False Return False
End If End If
@ -41,10 +44,21 @@ Namespace Jobs
Dim oFileInfo As New FileInfo(pSourceFilePath) Dim oFileInfo As New FileInfo(pSourceFilePath)
Dim oDestinationFilePath As String = Path.Combine(pDestinationDirectoryPath, oFileInfo.Name) 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() Manager.Close()
Return True Return True

View File

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

View File

@ -10,12 +10,14 @@ Public Class Scheduler
Private Scheduler As IScheduler Private Scheduler As IScheduler
Private ConnectionString As String Private ConnectionString As String
Private LicenseKey As String
Private Const JobName = "CertificateDocumentJob" Private Const JobName = "CertificateDocumentJob"
Public Sub New(pLogConfig As LogConfig, pConnectionString As String) Public Sub New(pLogConfig As LogConfig, pConnectionString As String, pLicenseKey As String)
MyBase.New(pLogConfig) MyBase.New(pLogConfig)
ConnectionString = pConnectionString ConnectionString = pConnectionString
LicenseKey = pLicenseKey
End Sub End Sub
Public Async Function Start(pInterval As Integer) As Task Public Async Function Start(pInterval As Integer) As Task
@ -29,6 +31,7 @@ Public Class Scheduler
Dim oJobKey = New JobKey(JobName) Dim oJobKey = New JobKey(JobName)
Dim oJobData = New JobDataMap() From { Dim oJobData = New JobDataMap() From {
{Common.Constants.GDPICTURE, LicenseKey},
{Common.Constants.LOGCONFIG, LogConfig}, {Common.Constants.LOGCONFIG, LogConfig},
{Common.Constants.DATABASE, ConnectionString} {Common.Constants.DATABASE, ConnectionString}
} }

View File

@ -6,6 +6,7 @@ Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Database Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Messaging Imports DigitalData.Modules.Messaging
Imports DigitalData.Modules.Config Imports DigitalData.Modules.Config
Imports GdPicture.Internal.WPF
Public Class Service Public Class Service
Private Logger As Logger Private Logger As Logger
@ -37,19 +38,27 @@ Public Class Service
Logger.Info("Inititalize Databases") Logger.Info("Inititalize Databases")
If Config.ConnectionString <> String.Empty Then If Config.ConnectionString = String.Empty Then
Database = New MSSQLServer(LogConfig, Config.ConnectionString) Throw New ApplicationException("Connection String is empty!")
End If
If Database.DBInitialized = False Then Database = New MSSQLServer(LogConfig, Config.ConnectionString)
Logger.Warn("MSSQL Connection could not be established. Check the Error Log")
End If If Database.DBInitialized = False Then
Throw New ApplicationException("Database connection could not be established!")
End If
Dim oKey = Database.GetScalarValue("SELECT LICENSE FROM TBDD_3RD_PARTY_MODULES WHERE NAME = 'GDPICTURE'")
If String.IsNullOrWhiteSpace(oKey) Then
Throw New ApplicationException("GDPicture License could not be loaded!")
End If End If
' === Initialize Queue === ' === Initialize Queue ===
Logger.Debug("Inititalize Quartz") Logger.Debug("Inititalize Quartz")
Scheduler = New Scheduler(LogConfig, Config.ConnectionString) Scheduler = New Scheduler(LogConfig, Config.ConnectionString, oKey)
Await Scheduler.Start(Config.IntervalInMin) Await Scheduler.Start(Config.IntervalInMin)
Logger.Info("Started [{0}] !", ServiceName) Logger.Info("Started [{0}] !", ServiceName)