ZUGFeRD Service: Clean up
This commit is contained in:
parent
a16d40169d
commit
6df0d3deff
@ -68,9 +68,6 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\DDModules\Logging\bin\Debug\DigitalData.Modules.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="FirebirdSql.Data.FirebirdClient, Version=7.5.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\FirebirdSql.Data.FirebirdClient.7.5.0\lib\net452\FirebirdSql.Data.FirebirdClient.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="NLog, Version=5.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.5.0.5\lib\net46\NLog.dll</HintPath>
|
||||
|
||||
@ -18,10 +18,7 @@ Public Class ThreadRunner
|
||||
Private ReadOnly _jobArguments As WorkerArgs
|
||||
Private ReadOnly _mssql As MSSQLServer
|
||||
|
||||
Private ReadOnly RejectedMaxDifferenceInMinutes As Integer = 60
|
||||
Private RejectedLastRun As Date = Now.AddMinutes(-(RejectedMaxDifferenceInMinutes - 1))
|
||||
|
||||
Public Sub New(LogConfig As LogConfig, ConfigManager As ConfigManager(Of Config), Firebird As Firebird, Optional MSSQL As MSSQLServer = Nothing)
|
||||
Public Sub New(LogConfig As LogConfig, ConfigManager As ConfigManager(Of Config), MSSQL As MSSQLServer)
|
||||
_logConfig = LogConfig
|
||||
_logger = _logConfig.GetLogger()
|
||||
_config = ConfigManager
|
||||
|
||||
@ -5,48 +5,42 @@ Imports DigitalData.Modules.Logging
|
||||
Imports DigitalData.Modules.Logging.LogConfig
|
||||
|
||||
Public Class ZUGFeRDService
|
||||
Private _config As ConfigManager(Of Config)
|
||||
Private _logConfig As LogConfig
|
||||
Private _logger As Logger
|
||||
Private _firebird As Firebird
|
||||
Private _mssql As MSSQLServer = Nothing
|
||||
|
||||
Private _threadRunner As ThreadRunner
|
||||
Private LogConfig As LogConfig
|
||||
Private Logger As Logger
|
||||
Private ThreadRunner As ThreadRunner
|
||||
|
||||
Protected Overrides Sub OnStart(args() As String)
|
||||
_logConfig = New LogConfig(PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"), Nothing, "Digital Data", "DDZUGFeRDService")
|
||||
_config = New ConfigManager(Of Config)(_logConfig, My.Application.Info.DirectoryPath)
|
||||
_logConfig.Debug = _config.Config.Debug
|
||||
_logger = _logConfig.GetLogger()
|
||||
_logger.Info($"{Constants.SERVICE_NAME} is starting.")
|
||||
|
||||
Dim oJobInterval As Integer = _config.Config.JobInterval
|
||||
Dim oMSSQLConnectionString As String = _config.Config.MSSQLConnectionString
|
||||
|
||||
If oMSSQLConnectionString = String.Empty Then
|
||||
_logger.Warn("MSSQL Connectionstring is empty. Exiting.")
|
||||
Throw New ArgumentNullException("ConnectionString is missing!")
|
||||
End If
|
||||
|
||||
_mssql = New MSSQLServer(_logConfig, oMSSQLConnectionString)
|
||||
|
||||
If _mssql.DBInitialized = False Then
|
||||
_logger.Warn("MSSQL Connection failed. Exiting.")
|
||||
Throw New ApplicationException("Connection failed!")
|
||||
End If
|
||||
|
||||
Try
|
||||
_threadRunner = New ThreadRunner(_logConfig, _config, _firebird, _mssql)
|
||||
_threadRunner.Start(oJobInterval)
|
||||
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.Error(ex)
|
||||
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} is stopping.")
|
||||
ThreadRunner.Stop()
|
||||
Logger.Info($"{Constants.SERVICE_NAME} stopped.")
|
||||
End Sub
|
||||
|
||||
End Class
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="FirebirdSql.Data.FirebirdClient" version="7.5.0" targetFramework="net461" />
|
||||
<package id="NLog" version="5.0.5" targetFramework="net461" />
|
||||
</packages>
|
||||
Loading…
x
Reference in New Issue
Block a user