From 2ae4c9a555692e9d738c0a054e02a7875e96b778 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 10 May 2021 14:27:09 +0200 Subject: [PATCH] ZUGFeRDService: Integrate with Config Module, Remove My.Settings --- Services.ZUGFeRDService/App.config | 43 ------- Services.ZUGFeRDService/Config.vb | 19 +++ Services.ZUGFeRDService/Constants.vb | 4 + .../DDZUGFeRDService.vbproj | 6 + .../My Project/Settings.Designer.vb | 110 +----------------- .../My Project/Settings.settings | 41 +------ Services.ZUGFeRDService/ProjectInstaller.vb | 4 +- Services.ZUGFeRDService/ThreadRunner.vb | 8 +- Services.ZUGFeRDService/ZUGFeRDService.vb | 31 ++--- 9 files changed, 55 insertions(+), 211 deletions(-) create mode 100644 Services.ZUGFeRDService/Config.vb create mode 100644 Services.ZUGFeRDService/Constants.vb diff --git a/Services.ZUGFeRDService/App.config b/Services.ZUGFeRDService/App.config index d1dedcb9..b327621d 100644 --- a/Services.ZUGFeRDService/App.config +++ b/Services.ZUGFeRDService/App.config @@ -1,53 +1,10 @@  - -
- - - - - DDZUGFeRDService - - - DD ZUGFeRD Service - - - 172.24.12.41 - - - 172.24.12.41:E:\DB\Firebird\Databases\EDMI_TEMPLATE\EDMI_MASTER.FDB - - - sysdba - - - dd - - - 10 - - - - - - False - - - 1234567890_EXAMPLE_KEY - - - 1 - - - False - - - diff --git a/Services.ZUGFeRDService/Config.vb b/Services.ZUGFeRDService/Config.vb new file mode 100644 index 00000000..15ef2dd6 --- /dev/null +++ b/Services.ZUGFeRDService/Config.vb @@ -0,0 +1,19 @@ +Public Class Config + Public Property Firebird As FirebirdConfig + Public Property MSSQLConnectionString As String = "" + Public Property MSSQLEnabled As Boolean = False + Public Property MSSQLEmailOutAccountID As String = 1 + + Public Property JobInterval As Integer = 10 + Public Property GDPictureKey As String = "1234567890_EXAMPLE_KEY" + + Public Property Debug As Boolean = False + + Public Class FirebirdConfig + Public Property DataSource As String = "172.24.12.41" + Public Property Database As String = "172.24.12.41:E:\DB\Firebird\Databases\EDMI_TEMPLATE\EDMI_MASTER.FDB" + Public Property User As String = "sysdba" + Public Property Password As String = "dd" + + End Class +End Class diff --git a/Services.ZUGFeRDService/Constants.vb b/Services.ZUGFeRDService/Constants.vb new file mode 100644 index 00000000..5c49f7aa --- /dev/null +++ b/Services.ZUGFeRDService/Constants.vb @@ -0,0 +1,4 @@ +Public Class Constants + Public Const SERVICE_NAME = "DDZUGFeRDService" + Public Const SERVICE_DISPLAY_NAME = "DigitalData ZUGFeRD Service" +End Class diff --git a/Services.ZUGFeRDService/DDZUGFeRDService.vbproj b/Services.ZUGFeRDService/DDZUGFeRDService.vbproj index ea761d33..2b3fe237 100644 --- a/Services.ZUGFeRDService/DDZUGFeRDService.vbproj +++ b/Services.ZUGFeRDService/DDZUGFeRDService.vbproj @@ -82,6 +82,8 @@ + + True Application.myapp @@ -133,6 +135,10 @@ + + {44982f9b-6116-44e2-85d0-f39650b1ef99} + Config + {eaf0ea75-5fa7-485d-89c7-b2d843b03a96} Database diff --git a/Services.ZUGFeRDService/My Project/Settings.Designer.vb b/Services.ZUGFeRDService/My Project/Settings.Designer.vb index 0e2fefa7..663052da 100644 --- a/Services.ZUGFeRDService/My Project/Settings.Designer.vb +++ b/Services.ZUGFeRDService/My Project/Settings.Designer.vb @@ -15,7 +15,7 @@ Option Explicit On Namespace My _ Partial Friend NotInheritable Class MySettings Inherits Global.System.Configuration.ApplicationSettingsBase @@ -53,114 +53,6 @@ Namespace My Return defaultInstance End Get End Property - - _ - Public ReadOnly Property SERVICE_NAME() As String - Get - Return CType(Me("SERVICE_NAME"),String) - End Get - End Property - - _ - Public ReadOnly Property SERVICE_DISPLAY_NAME() As String - Get - Return CType(Me("SERVICE_DISPLAY_NAME"),String) - End Get - End Property - - _ - Public ReadOnly Property DB_DATASOURCE() As String - Get - Return CType(Me("DB_DATASOURCE"),String) - End Get - End Property - - _ - Public ReadOnly Property DB_DATABASE() As String - Get - Return CType(Me("DB_DATABASE"),String) - End Get - End Property - - _ - Public ReadOnly Property DB_USER() As String - Get - Return CType(Me("DB_USER"),String) - End Get - End Property - - _ - Public ReadOnly Property DB_PASSWORD() As String - Get - Return CType(Me("DB_PASSWORD"),String) - End Get - End Property - - _ - Public ReadOnly Property JOB_INTERVAL() As Integer - Get - Return CType(Me("JOB_INTERVAL"),Integer) - End Get - End Property - - _ - Public ReadOnly Property MSSQL_CONNECTIONSTRING() As String - Get - Return CType(Me("MSSQL_CONNECTIONSTRING"),String) - End Get - End Property - - _ - Public ReadOnly Property MSSQL_ENABLED() As Boolean - Get - Return CType(Me("MSSQL_ENABLED"),Boolean) - End Get - End Property - - _ - Public ReadOnly Property GDPICTURE_KEY() As String - Get - Return CType(Me("GDPICTURE_KEY"),String) - End Get - End Property - - _ - Public ReadOnly Property MSSQLEmailOutAccountID() As Integer - Get - Return CType(Me("MSSQLEmailOutAccountID"),Integer) - End Get - End Property - - _ - Public ReadOnly Property DEBUG() As Boolean - Get - Return CType(Me("DEBUG"),Boolean) - End Get - End Property End Class End Namespace diff --git a/Services.ZUGFeRDService/My Project/Settings.settings b/Services.ZUGFeRDService/My Project/Settings.settings index e84ed006..f7f176ac 100644 --- a/Services.ZUGFeRDService/My Project/Settings.settings +++ b/Services.ZUGFeRDService/My Project/Settings.settings @@ -1,42 +1,5 @@  - + - - - DDZUGFeRDService - - - DD ZUGFeRD Service - - - 172.24.12.41 - - - 172.24.12.41:E:\DB\Firebird\Databases\EDMI_TEMPLATE\EDMI_MASTER.FDB - - - sysdba - - - dd - - - 10 - - - - - - False - - - 1234567890_EXAMPLE_KEY - - - 1 - - - False - - + \ No newline at end of file diff --git a/Services.ZUGFeRDService/ProjectInstaller.vb b/Services.ZUGFeRDService/ProjectInstaller.vb index e066985c..7d75b95f 100644 --- a/Services.ZUGFeRDService/ProjectInstaller.vb +++ b/Services.ZUGFeRDService/ProjectInstaller.vb @@ -15,8 +15,8 @@ Public Class ProjectInstaller .Account = ServiceAccount.LocalSystem } service = New ServiceInstaller With { - .ServiceName = My.Settings.SERVICE_NAME, - .DisplayName = My.Settings.SERVICE_DISPLAY_NAME + .ServiceName = Constants.SERVICE_NAME, + .DisplayName = Constants.SERVICE_DISPLAY_NAME } Installers.Add(process) Installers.Add(service) diff --git a/Services.ZUGFeRDService/ThreadRunner.vb b/Services.ZUGFeRDService/ThreadRunner.vb index e91f0ff4..45cd7d97 100644 --- a/Services.ZUGFeRDService/ThreadRunner.vb +++ b/Services.ZUGFeRDService/ThreadRunner.vb @@ -2,6 +2,7 @@ Imports System.IO Imports System.Timers Imports System.Xml.XPath +Imports DigitalData.Modules.Config Imports DigitalData.Modules.Database Imports DigitalData.Modules.Interfaces Imports DigitalData.Modules.Jobs @@ -13,6 +14,7 @@ Public Class ThreadRunner Private WithEvents _workerThread As BackgroundWorker Private WithEvents _workerTimer As Timer + Private _config As Config Private _logConfig As LogConfig Private _logger As Logger Private _firebird As Firebird @@ -25,11 +27,11 @@ Public Class ThreadRunner Private _jobArguments As WorkerArgs Private _mssql As MSSQLServer - Public Sub New(LogConfig As LogConfig, Firebird As Firebird, Optional MSSQL As MSSQLServer = Nothing) + Public Sub New(LogConfig As LogConfig, Config As ConfigManager(Of Config), Firebird As Firebird, Optional MSSQL As MSSQLServer = Nothing) _logConfig = LogConfig _logger = _logConfig.GetLogger() - _logConfig.Debug = My.Settings.DEBUG _firebird = Firebird + _config = Config _mssql = MSSQL Try Dim directory As New IO.DirectoryInfo(_logConfig.LogDirectory) @@ -138,7 +140,7 @@ Public Class ThreadRunner Dim args As WorkerArgs = e.Argument _logger.Debug("Background worker running..") - Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird, My.Settings.MSSQLEmailOutAccountID, _mssql) + Dim job As New ImportZUGFeRDFiles(_logConfig, _firebird, _config.MSSQLEmailOutAccountID, _mssql) job.Start(args) Catch ex As Exception _logger.Warn("Background worker failed!") diff --git a/Services.ZUGFeRDService/ZUGFeRDService.vb b/Services.ZUGFeRDService/ZUGFeRDService.vb index 23aeff07..b8ff7933 100644 --- a/Services.ZUGFeRDService/ZUGFeRDService.vb +++ b/Services.ZUGFeRDService/ZUGFeRDService.vb @@ -1,9 +1,11 @@ Imports System.IO +Imports DigitalData.Modules.Config Imports DigitalData.Modules.Database 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 @@ -11,9 +13,10 @@ Public Class ZUGFeRDService Private _threadRunner As ThreadRunner - Protected Overrides Sub OnStart(ByVal args() As String) + Protected Overrides Sub OnStart(args() As String) _logConfig = New LogConfig(PathType.CustomPath, Path.Combine(My.Application.Info.DirectoryPath, "Log"), Nothing, "Digital Data", "DDZUGFeRDService") - _logConfig.Debug = My.Settings.DEBUG + _config = New ConfigManager(Of Config)(_logConfig, My.Application.Info.DirectoryPath) + _logConfig.Debug = _config.Config.Debug _logger = _logConfig.GetLogger() Try Dim directory As New IO.DirectoryInfo(_logConfig.LogDirectory) @@ -24,22 +27,20 @@ Public Class ZUGFeRDService Else Exit For End If - - Next Catch ex As Exception End Try - _logger.Info($"{My.Settings.SERVICE_NAME} is starting.") + _logger.Info($"{Constants.SERVICE_NAME} is starting.") - Dim oDataSource As String = My.Settings.DB_DATASOURCE - Dim oDatabase As String = My.Settings.DB_DATABASE - Dim oUser As String = My.Settings.DB_USER - Dim oPassword As String = My.Settings.DB_PASSWORD - Dim oJobInterval As Integer = My.Settings.JOB_INTERVAL - Dim oMSSQLConnectionString As String = My.Settings.MSSQL_CONNECTIONSTRING - Dim oMSSQLEnabled As Boolean = My.Settings.MSSQL_ENABLED - Dim oGDPictureKey As String = My.Settings.GDPICTURE_KEY + Dim oDataSource As String = _config.Config.Firebird.DataSource + Dim oDatabase As String = _config.Config.Firebird.Database + Dim oUser As String = _config.Config.Firebird.User + Dim oPassword As String = _config.Config.Firebird.Password + Dim oJobInterval As Integer = _config.Config.JobInterval + Dim oMSSQLConnectionString As String = _config.Config.MSSQLConnectionString + Dim oMSSQLEnabled As Boolean = _config.Config.MSSQLEnabled + Dim oGDPictureKey As String = _config.Config.GDPictureKey _firebird = New Firebird(_logConfig, oDataSource, oDatabase, oUser, oPassword) @@ -53,7 +54,7 @@ Public Class ZUGFeRDService End If Try - _threadRunner = New ThreadRunner(_logConfig, _firebird, _mssql) + _threadRunner = New ThreadRunner(_logConfig, _config, _firebird, _mssql) _threadRunner.Start(oJobInterval) Catch ex As Exception _logger.Error(ex) @@ -61,7 +62,7 @@ Public Class ZUGFeRDService End Sub Protected Overrides Sub OnStop() - _logger.Info($"{My.Settings.SERVICE_NAME} is stopping.") + _logger.Info($"{Constants.SERVICE_NAME} is stopping.") _threadRunner.Stop() End Sub