Modules/JobRunner/JobRunner2.vb
2019-04-17 16:30:53 +02:00

114 lines
3.6 KiB
VB.net

Imports System.Collections.Specialized
Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Jobs
Imports DigitalData.Modules.Logging
Imports Quartz
Imports Quartz.Impl
Imports Quartz.Logging
Public Class JobRunner2
Private _LogConfig As LogConfig
Private _Logger As Modules.Logging.Logger
Private _firebird As Firebird
Private _mssql As MSSQLServer
Private _Props As New NameValueCollection From {
{"quartz.serializer.type", "binary"}
}
Private _factory As StdSchedulerFactory
Private _scheduler As IScheduler
Public Sub New(LogConfig As LogConfig, MSSQL As MSSQLServer, Firebird As Firebird)
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
_firebird = Firebird
_mssql = MSSQL
End Sub
Public Async Sub Start()
Logging.LogProvider.SetCurrentLogProvider(New LogProvider(_Logger))
Dim oProps As New NameValueCollection From {
{"quartz.serializer.type", "binary"}
}
_factory = New StdSchedulerFactory(oProps)
_scheduler = Await _factory.GetScheduler()
Await _scheduler.Start()
Dim oJobData As New JobDataMap From {
{"LogConfig", _LogConfig},
{"Firebird", _firebird},
{"MSSQL", _mssql},
{"RootPath", My.Settings.JOB_ADSYNC_ROOT_PATH}
}
Dim oJobDetail = JobBuilder.Create(Of ADJob)().
WithIdentity("activedirectory-sync").
UsingJobData(oJobData).
Build()
Dim oTrigger = TriggerBuilder.Create().
WithIdentity("activedirectory-sync-trigger").
StartNow().
WithCronSchedule("1 0 * * *").
Build()
Await _scheduler.ScheduleJob(oJobDetail, oTrigger)
End Sub
Public Async Sub [Stop]()
Await _scheduler.Shutdown()
End Sub
Public Class ADJob
Implements Quartz.IJob
Public Async Function Execute(context As IJobExecutionContext) As Task Implements Quartz.IJob.Execute
Dim oJobData = context.MergedJobDataMap
Dim oLogConfig As LogConfig = oJobData.Item("LogConfig")
Dim oFirebird As Firebird = oJobData.Item("Firebird")
Dim oMSSQL As MSSQLServer = oJobData.Item("MSSQL")
Dim oRootPath As String = oJobData.Item("RootPath")
Dim oADJobArgs = New ADSyncArgs() With {
.RootPath = oRootPath
}
Dim oADSyncJob As New ADSyncJob(oLogConfig, oFirebird, oMSSQL)
oADSyncJob.Start(oADJobArgs)
Await Task.CompletedTask
End Function
End Class
Private Class LogProvider
Implements ILogProvider
Private _Logger As Modules.Logging.Logger
Public Sub New(Logger As Modules.Logging.Logger)
MyBase.New()
_Logger = Logger
End Sub
Private Function GetLogger(name As String) As Logging.Logger Implements ILogProvider.GetLogger
Return Function(level, func, exception, parameters)
If level >= LogLevel.Info AndAlso func IsNot Nothing Then
_Logger.Info(func())
End If
Return True
End Function
End Function
Private Function OpenNestedContext(message As String) As IDisposable Implements ILogProvider.OpenNestedContext
Throw New NotImplementedException()
End Function
Private Function OpenMappedContext(key As String, value As String) As IDisposable Implements ILogProvider.OpenMappedContext
Throw New NotImplementedException()
End Function
End Class
End Class