jj appserv

This commit is contained in:
Jonathan Jenne
2020-12-08 14:40:43 +01:00
parent cafa8cdbf3
commit 4c9abf3b1f
10 changed files with 209 additions and 49 deletions

View File

@@ -1,6 +1,7 @@
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Filesystem
Imports DigitalData.Modules.language
Imports DigitalData.Modules
Imports System.IO
Imports System.ServiceModel
@@ -66,20 +67,41 @@ Public Class EDMIService
#End Region
#Region "Database"
Public Function ReturnDatatableFromCache(Name As String) As TableResult Implements IEDMIService.ReturnDatatableFromCache
Public Function ReturnDatatableFromCache(Name As String, FilterExpression As String, SortByColumn As String) As TableResult Implements IEDMIService.ReturnDatatableFromCache
Try
Dim oSql = ""
_logger.Info($"ReturnDatatableFromCache, SQL: {oSql}")
_logger.Info($"ReturnDatatableFromCache, Datatable: {Name}")
Dim oDataset As DataSet = Scheduler.DataSet
Dim oDataTable As DataTable = Nothing
_logger.Debug("DataSet contains [{0}] datatables", oDataset.Tables.Count)
If oDataset.Tables.Contains(Name) Then
oDataTable = oDataset.Tables.Item(Name)
oDataTable = oDataset.Tables.Item(Name).Copy()
' Apply filter and sorting to data
Dim oFilterExpression As String = Utils.NotNull(FilterExpression, String.Empty)
Dim oSortByColumn As String = Utils.NotNull(SortByColumn, String.Empty)
Dim oFilteredTable = oDataTable.
Select(oFilterExpression, oSortByColumn).
CopyToDataTable()
_logger.Debug("Datatable Stats for [{0}]:", Name)
_logger.Debug("Unfiltered: [{0}] rows", oDataTable.Rows.Count)
_logger.Debug("Filtered: [{0}] rows", oFilteredTable.Rows.Count)
Return New TableResult(oFilteredTable)
Else
Throw New ApplicationException($"DataTable {Name} does not exist")
End If
Return New TableResult(oDataTable)
'If oDataset.Tables.Contains(Name) Then
' oDataTable = oDataset.Tables.Item(Name).Clone()
' Return New TableResult(oDataTable)
'Else
' Throw New ApplicationException($"DataTable {Name} does not exist")
'End If
Catch ex As Exception
_logger.Error(ex)
Return New TableResult(ex.Message)

View File

@@ -206,6 +206,10 @@
<Project>{991D0231-4623-496D-8BD0-9CA906029CBC}</Project>
<Name>Filesystem</Name>
</ProjectReference>
<ProjectReference Include="..\Modules.Language\Language.vbproj">
<Project>{d3c8cfed-d6f6-43a8-9bdf-454145d0352f}</Project>
<Name>Language</Name>
</ProjectReference>
<ProjectReference Include="..\Modules.Logging\Logging.vbproj">
<Project>{903B2D7D-3B80-4BE9-8713-7447B704E1B0}</Project>
<Name>Logging</Name>

View File

@@ -13,7 +13,7 @@ Interface IEDMIService
#Region "Database"
<OperationContract>
Function ReturnDatatableFromCache(Name As String) As TableResult
Function ReturnDatatableFromCache(Name As String, FilterExpression As String, SortByColumn As String) As TableResult
#End Region
#Region "Database (Firebird)"

View File

@@ -33,9 +33,9 @@ Public Class Scheduler
_MSSQL = MSSQL_ECM
Dim oDataSet As New DataSet()
_JobListener = New JobListener(LogConfig, oDataSet)
_JobListener = New JobListener(LogConfig, _MSSQL, oDataSet)
Quartz.Logging.LogProvider.SetCurrentLogProvider(New LogProvider(_Logger))
Logging.LogProvider.SetCurrentLogProvider(New LogProvider(_Logger))
End Sub
Public Async Sub Start()
@@ -66,18 +66,26 @@ Public Class Scheduler
_Logger.Debug("Job details: {0}", oCronDetails.Rows.Count)
_Logger.Debug("Job definition: {0}", oDefinition)
For Each oRowDetail In oCronDetails.Rows
For Each oRowDetail As DataRow In oCronDetails.Rows
Dim oTrigger As ITrigger
Dim oJob As IJobDetail
Dim oDataTableName As String = oRowDetail.Item("DT_NAME")
Dim oRunOnStartup As Boolean = oRowDetail.Item("RUN_ON_STARTUP")
Dim oJobIdentity As String = $"{oGuid}~{oDataTableName}"
oTrigger = TriggerBuilder.Create().
WithIdentity(oTitle).
WithCronSchedule(oDefinition).
StartNow().
Build()
Dim oBaseTrigger = TriggerBuilder.Create().
WithIdentity(oJobIdentity, JOB_GROUP).
WithCronSchedule(oDefinition)
' Run directly at startup if configured
If oRunOnStartup Then
oBaseTrigger = oBaseTrigger.StartNow()
End If
oTrigger = oBaseTrigger.Build()
oJob = JobBuilder.Create(Of DatatableJob)().
WithIdentity(oGuid, JOB_GROUP).
WithIdentity(oJobIdentity, JOB_GROUP).
UsingJobData(New JobDataMap() From {
{"LogConfig", _LogConfig},
{"MSSQL", _MSSQL},

View File

@@ -8,23 +8,24 @@ Public Class DatatableJob
Public Function Execute(context As IJobExecutionContext) As Task Implements IJob.Execute
Dim oJobData = context.MergedJobDataMap
Dim oLogConfig As LogConfig = oJobData.Item("LogConfig")
Dim oCronJobTitle As String = oJobData.Item("CronJobTitle")
Dim oDetailRow As DataRow = oJobData.Item("CronJobDetails")
Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL")
Dim oConnectionId As Integer = oDetailRow.Item("CON_ID")
Dim oTitle As String = oDetailRow.Item("TITLE")
Dim oDatatableName As String = oDetailRow.Item("DT_NAME")
Dim oSQL As String = oDetailRow.Item("COMMAND")
Dim oLogger As Logger = oLogConfig.GetLogger()
oLogger.Debug("Running Command-Job [{0}]", oTitle)
oLogger.Debug("Datatable Name: {0}", oDatatableName)
oLogger.Debug("Connection Id: {0}", oConnectionId)
Dim oConnectionString = oMSSQL.Get_ConnectionStringforID(oConnectionId)
Try
Dim oCronJobTitle As String = oJobData.Item("CronJobTitle")
Dim oDetailRow As DataRow = oJobData.Item("CronJobDetails")
Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL")
Dim oConnectionId As Integer = oDetailRow.Item("CON_ID")
Dim oTitle As String = oDetailRow.Item("TITLE")
Dim oDatatableName As String = oDetailRow.Item("DT_NAME")
Dim oSQL As String = oDetailRow.Item("COMMAND")
oLogger.Debug("Running Command-Job [{0}]", oTitle)
oLogger.Debug("Datatable Name: {0}", oDatatableName)
oLogger.Debug("Connection Id: {0}", oConnectionId)
Dim oConnectionString = oMSSQL.Get_ConnectionStringforID(oConnectionId)
Dim oResult = oMSSQL.GetDatatableWithConnection(oSQL, oConnectionString)
oResult.TableName = oDatatableName
oLogger.Debug("Result Datatable contains [{0}] rows", oResult.Rows.Count)

View File

@@ -1,4 +1,5 @@
Imports System.Threading
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Logging
Imports Quartz
Imports Quartz.Listener
@@ -10,12 +11,14 @@ Public Class JobListener
Private ReadOnly _Logger As Logger
Private ReadOnly _LogConfig As LogConfig
Private ReadOnly _MSSQL As MSSQLServer
Public Sub New(LogConfig As LogConfig, ResultDataSet As DataSet)
Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer, ResultDataSet As DataSet)
MyBase.New()
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
_MSSQL = MSSQL
Dataset = ResultDataSet
End Sub
@@ -24,10 +27,11 @@ Public Class JobListener
Dim oDataTable As DataTable = context.Result
Dim oDetailRow As DataRow = context.MergedJobDataMap.Item("CronJobDetails")
Dim oDatatableName As String = oDetailRow.Item("DT_NAME")
Dim oDetailId As Integer = oDetailRow.Item("GUID")
Dim oDatatableNameTemp As String = oDatatableName & "-TEMP"
If Dataset.Tables.Contains(oDatatableName) Then
_Logger.Debug("DataTable exists, renaming and replacing")
_Logger.Debug("DataTable [{0}] exists, renaming and replacing", oDatatableName)
' Rename the new table, add TEMP suffix
oDataTable.TableName = oDatatableNameTemp
' Add the new table to the dataset
@@ -37,10 +41,13 @@ Public Class JobListener
' Rename the new table
Dataset.Tables.Item(oDatatableNameTemp).TableName = oDatatableName
Else
_Logger.Debug("DataTable does not exist, adding")
_Logger.Debug("DataTable [{0}] does not exist, adding", oDatatableName)
Dataset.Tables.Add(oDataTable)
End If
_MSSQL.ExecuteNonQuery($"INSERT INTO TBAPPSERV_CRON_DETAIL_HISTORY (DETAIL_ID) VALUES ({oDetailId})")
Catch ex As Exception
_Logger.Warn("Unexpected error in JobListener: {0}", ex.Message)
_Logger.Error(ex)
End Try