Use ConfigManager for Config

This commit is contained in:
Jonathan Jenne
2022-10-17 09:02:50 +02:00
parent bbd6704262
commit 5b97238d66
4 changed files with 61 additions and 54 deletions

View File

@@ -6,10 +6,14 @@ Imports DigitalData.Modules.Database
Imports DigitalData.Modules.Messaging
Imports DigitalData.Modules.Language
Imports DigitalData.Modules.Encryption
Imports DigitalData.Modules.Config
Public Class EmailService
Private _Logger As Logger
Private _LogConfig As LogConfig
Private _ConfigManager As ConfigManager(Of Config)
Private _Config As Config
Private _Firebird As Firebird
Private _MSSQL As MSSQLServer
Private _MSSQL_Test As MSSQLServer
@@ -30,11 +34,15 @@ Public Class EmailService
Try
' === Initialize Logger ===
Dim oLogPath = Path.Combine(My.Application.Info.DirectoryPath, "Log")
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, Nothing, "Digital Data", "EmailService") With {
.Debug = My.Settings.DEBUG
}
_LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, Nothing, "Digital Data", "EmailService")
Dim oCurrentDomain As AppDomain
' === Initialize Config ===
_ConfigManager = New ConfigManager(Of Config)(_LogConfig, My.Application.Info.DirectoryPath)
_Config = _ConfigManager.Config
_LogConfig.Debug = _Config.Debug
Dim oCurrentDomain As AppDomain = AppDomain.CurrentDomain
AddHandler oCurrentDomain.UnhandledException, AddressOf AppDomain_UnhandledException
_Logger = _LogConfig.GetLogger()
@@ -50,25 +58,25 @@ Public Class EmailService
_Logger.Info("Inititalize Databases")
If My.Settings.FB_ConnString <> String.Empty Then
_Firebird = New Firebird(_LogConfig, My.Settings.FB_ConnString, My.Settings.FB_DATABASE, My.Settings.FB_USER, My.Settings.FB_PW)
If _Config.FirebirdServer <> String.Empty Then
_Firebird = New Firebird(_LogConfig, _Config.FirebirdServer, _Config.FirebirdDatabase, _Config.FirebirdUser, _Config.FirebirdPassword)
If _Firebird._DBInitialized = False Then
_Logger.Warn("Firebird Connection could not be established. Check the Error Log")
End If
End If
If My.Settings.SQLSERVER_CS <> String.Empty Then
_MSSQL = New MSSQLServer(_LogConfig, My.Settings.SQLSERVER_CS)
If _Config.SQLServerConnectionString <> String.Empty Then
_MSSQL = New MSSQLServer(_LogConfig, _Config.SQLServerConnectionString)
If _MSSQL.DBInitialized = False Then
_Logger.Warn("MSSQL Connection could not be established. Check the Error Log")
End If
End If
If My.Settings.SQLSERVER_CS_TEST <> String.Empty Then
If _Config.SQLServerTestConnectionString <> String.Empty Then
_MSSQL_Test = New MSSQLServer(_LogConfig, My.Settings.SQLSERVER_CS_TEST)
_MSSQL_Test = New MSSQLServer(_LogConfig, _Config.SQLServerTestConnectionString)
If _MSSQL_Test.DBInitialized = False Then
_Logger.Warn("MSSQL Test Connection could not be established. Check the Error Log")
@@ -130,6 +138,7 @@ Public Class EmailService
Private Sub AppDomain_UnhandledException(sender As Object, e As UnhandledExceptionEventArgs)
Dim oException As Exception = e.ExceptionObject
_Logger.Warn("An unhandled exception has occurred.")
_Logger.Error(oException)
End Sub
@@ -168,6 +177,22 @@ Public Class EmailService
End Try
End Sub
Private Sub EmailQueue_Completed(sender As Object, e As RunWorkerCompletedEventArgs)
Try
If e.Cancelled Then
_Logger.Warn("EmailQueue has been cancelled manually!")
ElseIf e.Error IsNot Nothing Then
_Logger.Warn("Unexpected Error in EmailQueue: {0}", e.Error.Message)
_Logger.Error(e.Error)
Else
_Logger.Debug("Email Queue successfully processed.")
End If
Catch ex As Exception
_Logger.Warn("Error while processing result of Worker!")
_Logger.Error(e.Error)
End Try
End Sub
Private Class EmailAccount
Public Guid As Integer
Public Sender As String
@@ -301,7 +326,6 @@ Public Class EmailService
Return False
End If
Dim oMailSMTP, oMailport, oMailUser, oMailPW, oAuthType, oErrorMsg, oMailADDED
Dim oGuid, oJobId As Integer
For Each oAccount In oEmailAccounts
@@ -345,7 +369,6 @@ Public Class EmailService
For Each oRow As DataRow In oAccountQueue
'Dim oAccountMatch As Boolean = False
Dim oComment As String = String.Empty
oErrorMsg = ""
Dim oAttachment = String.Empty
Dim oEmailTo = String.Empty
@@ -486,19 +509,7 @@ Public Class EmailService
End Try
End Function
Private Sub EmailQueue_Completed(sender As Object, e As RunWorkerCompletedEventArgs)
Try
If e.Cancelled Then
_Logger.Warn("EmailQueue has been cancelled manually!")
ElseIf e.Error IsNot Nothing Then
_Logger.Warn("Unexpected Error in EmailQueue: {0}", e.Error.Message)
_Logger.Error(e.Error)
End If
Catch ex As Exception
_Logger.Warn("Error while processing result of Worker!")
_Logger.Error(e.Error)
End Try
End Sub
Protected Overrides Sub OnStop()
Try