72 lines
2.4 KiB
VB.net
72 lines
2.4 KiB
VB.net
Imports System.Timers
|
|
Imports DigitalData.GUIs.ClientSuite.Base
|
|
Imports DigitalData.Modules.Logging
|
|
|
|
Namespace Workers
|
|
Public Class WorkerManager
|
|
Inherits BaseClass
|
|
|
|
''' <summary>
|
|
''' List of workers that will be started.
|
|
''' </summary>
|
|
Private WorkerTypes As New List(Of Type) From {
|
|
GetType(HeartbeatWorker),
|
|
GetType(WorkflowOverviewWorker)
|
|
}
|
|
Private Workers As New List(Of IWorker)
|
|
Private TimerList As New List(Of Timer)
|
|
|
|
Public Sub New(LogConfig As LogConfig, SyncronizingObject As frmMain)
|
|
MyBase.New(LogConfig)
|
|
|
|
Workers = CreateWorkers()
|
|
|
|
For Each oWorker As IWorker In Workers
|
|
Dim oTimer = New Timer(oWorker.Interval) With {
|
|
.SynchronizingObject = SyncronizingObject,
|
|
.Enabled = True
|
|
}
|
|
|
|
AddHandler oTimer.Elapsed, Sub(sender As Object, e As ElapsedEventArgs)
|
|
Try
|
|
oWorker.Callback(Me, e)
|
|
Catch ex As Exception
|
|
Logger.Warn("Worker {0} threw an error in callback.", oWorker.GetType.Name)
|
|
End Try
|
|
End Sub
|
|
|
|
TimerList.Add(oTimer)
|
|
Next
|
|
End Sub
|
|
|
|
Public Function GetWorker(Of T)() As T
|
|
For Each oWorker In Workers
|
|
If TypeOf oWorker Is T Then
|
|
Return oWorker
|
|
End If
|
|
Next
|
|
|
|
Return Nothing
|
|
End Function
|
|
|
|
Private Function CreateWorkers() As List(Of IWorker)
|
|
Dim oWorkers As New List(Of IWorker)
|
|
|
|
For Each oWorkerType In WorkerTypes
|
|
Try
|
|
Dim oWorker As IWorker = Activator.CreateInstance(oWorkerType, New Object() {LogConfig})
|
|
oWorker.Setup()
|
|
oWorkers.Add(oWorker)
|
|
Catch ex As Exception
|
|
Logger.Warn("Worker {0} threw an error while creating. Skipping.", oWorkerType.Name)
|
|
Logger.Error(ex)
|
|
Continue For
|
|
End Try
|
|
Next
|
|
|
|
Return oWorkers
|
|
End Function
|
|
End Class
|
|
End Namespace
|
|
|