82 lines
2.6 KiB
VB.net
82 lines
2.6 KiB
VB.net
Imports System.Timers
|
|
Imports System.IO
|
|
Imports System.ComponentModel
|
|
Imports DigitalData.Modules.Base
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Messaging
|
|
Imports DigitalData.Modules.Config
|
|
Imports GdPicture.Internal.WPF
|
|
|
|
Public Class Service
|
|
Private Logger As Logger
|
|
Private LogConfig As LogConfig
|
|
Private ConfigManager As ConfigManager(Of Config)
|
|
Private Config As Config
|
|
Private Database As MSSQLServer
|
|
|
|
Private Scheduler As Scheduler
|
|
|
|
Protected Overrides Async Sub OnStart(ByVal args() As String)
|
|
Try
|
|
' === Initialize Logger ===
|
|
Dim oLogPath = Path.Combine(My.Application.Info.DirectoryPath, "Log")
|
|
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, Nothing, "Digital Data", "EnvelopeGenerator.Service")
|
|
|
|
' === Initialize Config ===
|
|
ConfigManager = New ConfigManager(Of Config)(LogConfig, My.Application.Info.DirectoryPath)
|
|
Config = ConfigManager.Config
|
|
|
|
LogConfig.Debug = Config.Debug
|
|
|
|
Logger = LogConfig.GetLogger()
|
|
Logger.Info($"DEBUG = {LogConfig.Debug}")
|
|
|
|
Logger.Info("Starting [{0}]", ServiceName)
|
|
|
|
' === Initialize Databases ===
|
|
|
|
Logger.Info("Inititalize Databases")
|
|
|
|
If Config.ConnectionString = String.Empty Then
|
|
Throw New ApplicationException("Connection String is empty!")
|
|
End If
|
|
|
|
Database = New MSSQLServer(LogConfig, Config.ConnectionString)
|
|
|
|
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' and ACTIVE = 1")
|
|
|
|
If String.IsNullOrWhiteSpace(oKey) Then
|
|
Throw New ApplicationException("GDPicture License could not be loaded!")
|
|
End If
|
|
|
|
' === Initialize Queue ===
|
|
|
|
Logger.Debug("Inititalize Quartz")
|
|
|
|
Scheduler = New Scheduler(LogConfig, Config.ConnectionString, oKey)
|
|
Await Scheduler.Start(Config.IntervalInMin)
|
|
|
|
Logger.Info("Started [{0}] !", ServiceName)
|
|
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
End Try
|
|
End Sub
|
|
|
|
Protected Overrides Async Sub OnStop()
|
|
Try
|
|
Logger.Info("Stopping [{0}] !", ServiceName)
|
|
Await Scheduler.Stop()
|
|
Logger.Info("Stopped [{0}] !", ServiceName)
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
End Try
|
|
|
|
End Sub
|
|
End Class
|