47 lines
1.8 KiB
VB.net
47 lines
1.8 KiB
VB.net
Imports System.IO
|
|
Imports DigitalData.Modules.Config
|
|
Imports DigitalData.Modules.Database
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Logging.LogConfig
|
|
|
|
Public Class ZUGFeRDService
|
|
Private LogConfig As LogConfig
|
|
Private Logger As Logger
|
|
Private ThreadRunner As ThreadRunner
|
|
|
|
Protected Overrides Sub OnStart(args() As String)
|
|
Try
|
|
LogConfig = New LogConfig(PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"), Nothing, "Digital Data", "DDZUGFeRDService")
|
|
Dim oConfig = New ConfigManager(Of Config)(LogConfig, My.Application.Info.DirectoryPath)
|
|
LogConfig.Debug = oConfig.Config.Debug
|
|
Logger = LogConfig.GetLogger()
|
|
Logger.Info($"{Constants.SERVICE_NAME} is starting.")
|
|
|
|
If oConfig.Config.MSSQLConnectionString = String.Empty Then
|
|
Logger.Warn("MSSQL Connectionstring is empty. Exiting.")
|
|
Throw New ArgumentNullException("ConnectionString is missing!")
|
|
End If
|
|
|
|
Dim oDatabase = New MSSQLServer(LogConfig, oConfig.Config.MSSQLConnectionString)
|
|
|
|
If oDatabase.DBInitialized = False Then
|
|
Logger.Warn("MSSQL Connection failed. Exiting.")
|
|
Throw New ApplicationException("Connection failed!")
|
|
End If
|
|
|
|
ThreadRunner = New ThreadRunner(LogConfig, oConfig, oDatabase)
|
|
ThreadRunner.Start(oConfig.Config.JobInterval)
|
|
Catch ex As Exception
|
|
Logger.Warn("Starting the Service failed.")
|
|
Logger.Error(ex)
|
|
End Try
|
|
End Sub
|
|
|
|
Protected Overrides Sub OnStop()
|
|
Logger.Info($"{Constants.SERVICE_NAME} is stopping.")
|
|
ThreadRunner.Stop()
|
|
Logger.Info($"{Constants.SERVICE_NAME} stopped.")
|
|
End Sub
|
|
|
|
End Class
|