136 lines
6.2 KiB
VB.net
136 lines
6.2 KiB
VB.net
Option Explicit On
|
|
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Language.Utils
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Imports Quartz
|
|
|
|
Public Class DatatableJob
|
|
Implements IJob
|
|
|
|
Private _MSSQL As MSSQLServer
|
|
|
|
Public Function Execute(context As IJobExecutionContext) As Task Implements IJob.Execute
|
|
Dim oJobData = context.MergedJobDataMap
|
|
Dim oLogConfig As LogConfig = oJobData.Item("LogConfig")
|
|
Dim oCronJobId As Integer = oJobData.Item("CronJobId")
|
|
Dim oCronJobTitle As String = oJobData.Item("CronJobTitle")
|
|
Dim oLogger As Logger = oLogConfig.GetLogger()
|
|
|
|
Dim oResult As New JobResult()
|
|
|
|
oLogger.Info("Running Datatable Job [{0}]", oCronJobTitle)
|
|
|
|
Try
|
|
Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL")
|
|
Dim oCronSQL As String = $"SELECT * FROM TBAPPSERV_CRON_DETAIL WHERE CRON_ID = {oCronJobId}"
|
|
Dim oCronDetails As DataTable = oMSSQL.GetDatatable(oCronSQL)
|
|
|
|
For Each oRow As DataRow In oCronDetails.Rows
|
|
Dim oConnectionId As Integer = NotNull(oRow.Item("CON_ID"), String.Empty)
|
|
Dim oTitle As String = NotNull(oRow.Item("TITLE"), String.Empty)
|
|
Dim oSQL As String = NotNull(oRow.Item("COMMAND"), String.Empty)
|
|
Dim oDatatableName As String = NotNull(oRow.Item("DT_NAME"), String.Empty)
|
|
|
|
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 oTable = oMSSQL.GetDatatableWithConnection(oSQL, oConnectionString)
|
|
oTable.TableName = oDatatableName
|
|
oLogger.Debug("Result Datatable [{0}] contains [{1}] rows", oTable.TableName, oTable.Rows.Count)
|
|
|
|
Dim oResultTable = New JobResult.ResultTable() With {
|
|
.Table = oTable,
|
|
.DetailRow = oRow
|
|
}
|
|
|
|
Dim oChildTableNAme As String = NotNull(oRow.Item("CHILD_DT_NAME"), String.Empty)
|
|
|
|
If oChildTableNAme <> String.Empty Then
|
|
Dim oParentColumn As String = NotNull(oRow.Item("DT_COLUMN"), String.Empty)
|
|
Dim oChildColumn As String = NotNull(oRow.Item("CHILD_DT_COLUMN"), String.Empty)
|
|
oLogger.Debug("Child Datatable [{0}] defined, Relation: Parent [{1}] -> Child [{2}]", oChildTableNAme, oParentColumn, oChildColumn)
|
|
|
|
Dim oChildTable As DataTable = oMSSQL.GetDatatableWithConnection($"SELECT * FROM {oChildTableNAme}", oConnectionString)
|
|
oChildTable.TableName = oChildTableNAme
|
|
oLogger.Debug("Child Datatable [{0}] contains [{1}] rows", oChildTable.TableName, oChildTable.Rows.Count)
|
|
|
|
oResultTable.ChildTable = oChildTable
|
|
oResultTable.ChildRelationColumn = oChildColumn
|
|
oResultTable.TableRelationColumn = oParentColumn
|
|
End If
|
|
|
|
oLogger.Info("Fetched Datatable [{0}]", oDatatableName)
|
|
oResult.Tables.Add(oResultTable)
|
|
Next
|
|
|
|
' Das Ergebnis speichern
|
|
context.Result = oResult
|
|
|
|
Catch ex As Exception
|
|
oLogger.Error(ex)
|
|
oLogger.Warn("Unhandled exception while executing SQL for Datatable {0}", oCronJobTitle)
|
|
End Try
|
|
|
|
Return Task.FromResult(True)
|
|
|
|
#Region "OLD"
|
|
'Dim oJobData = context.MergedJobDataMap
|
|
'Dim oLogConfig As LogConfig = oJobData.Item("LogConfig")
|
|
'Dim oLogger As Logger = oLogConfig.GetLogger()
|
|
'Dim oDetailRow As DataRow = oJobData.Item("CronJobDetails")
|
|
'Dim oDatatableName As String = NotNull(oDetailRow.Item("DT_NAME"), String.Empty)
|
|
|
|
'Try
|
|
' Dim oCronJobTitle As String = oJobData.Item("CronJobTitle")
|
|
' Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL")
|
|
|
|
' Dim oConnectionId As Integer = NotNull(oDetailRow.Item("CON_ID"), String.Empty)
|
|
' Dim oTitle As String = NotNull(oDetailRow.Item("TITLE"), String.Empty)
|
|
' Dim oSQL As String = NotNull(oDetailRow.Item("COMMAND"), String.Empty)
|
|
|
|
' 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 oTable = oMSSQL.GetDatatableWithConnection(oSQL, oConnectionString)
|
|
' oTable.TableName = oDatatableName
|
|
' oLogger.Debug("Result Datatable [{0}] contains [{1}] rows", oTable.TableName, oTable.Rows.Count)
|
|
|
|
' Dim oResult = New JobResult() With {
|
|
' .Table = oTable
|
|
' }
|
|
|
|
' Dim oChildTableNAme As String = NotNull(oDetailRow.Item("CHILD_DT_NAME"), String.Empty)
|
|
|
|
' If oChildTableNAme <> String.Empty Then
|
|
' Dim oParentColumn As String = NotNull(oDetailRow.Item("DT_COLUMN"), String.Empty)
|
|
' Dim oChildColumn As String = NotNull(oDetailRow.Item("CHILD_DT_COLUMN"), String.Empty)
|
|
' oLogger.Debug("Child Datatable [{0}] defined, Relation: Parent [{1}] -> Child [{2}]", oChildTableName, oParentColumn, oChildColumn)
|
|
|
|
' Dim oChildTable As DataTable = oMSSQL.GetDatatableWithConnection($"SELECT * FROM {oChildTableName}", oConnectionString)
|
|
' oChildTable.TableName = oChildTableName
|
|
' oLogger.Debug("Child Datatable [{0}] contains [{1}] rows", oChildTable.TableName, oChildTable.Rows.Count)
|
|
|
|
' oResult.ChildTable = oChildTable
|
|
' oResult.ChildRelationColumn = oChildColumn
|
|
' oResult.TableRelationColumn = oParentColumn
|
|
' End If
|
|
|
|
' ' Das Ergebnis speichern
|
|
' context.Result = oResult
|
|
'Catch ex As Exception
|
|
' oLogger.Error(ex)
|
|
' oLogger.Warn("Unhandled exception while executing SQL for Datatable {0}", oDatatableName)
|
|
'End Try
|
|
|
|
'Return Task.FromResult(True)
|
|
#End Region
|
|
End Function
|
|
End Class
|