MS: Emailservice und Logging

This commit is contained in:
2020-01-06 13:00:25 +01:00
parent bc18b693bb
commit f20d0e5edd
6 changed files with 272 additions and 21 deletions

View File

@@ -16,6 +16,7 @@ Public Class ConfigManager(Of T)
Private ReadOnly _UserConfigPath As String
Private ReadOnly _ComputerDirectory As String
Private ReadOnly _ComputerConfigPath As String
Private ReadOnly _AppConfigPath As String
Private ReadOnly _TestMode As Boolean = False
@@ -56,6 +57,11 @@ Public Class ConfigManager(Of T)
Return _ComputerConfigPath
End Get
End Property
Public ReadOnly Property AppConfigPath As String
Get
Return _AppConfigPath
End Get
End Property
''' <summary>
''' Creates a new instance of the ConfigManager
@@ -65,7 +71,7 @@ Public Class ConfigManager(Of T)
''' <param name="UserConfigPath">The path to check for a user config file, eg. AppData (Usually Application.UserAppDataPath or Application.LocalUserAppDataPath)</param>
''' <param name="ComputerConfigPath">The path to check for a computer config file, eg. ProgramData (Usually Application.CommonAppDataPath)</param>
''' <param name="ForceUserConfig">Override values from ComputerConfig with UserConfig</param>
Public Sub New(LogConfig As LogConfig, UserConfigPath As String, ComputerConfigPath As String, Optional ForceUserConfig As Boolean = False)
Public Sub New(LogConfig As LogConfig, UserConfigPath As String, ComputerConfigPath As String, ApplicationStartupPath As String, Optional ForceUserConfig As Boolean = False)
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
_File = New Filesystem.File(_LogConfig)
@@ -80,6 +86,7 @@ Public Class ConfigManager(Of T)
_UserConfigPath = Path.Combine(_UserDirectory, USER_CONFIG_NAME)
_ComputerConfigPath = Path.Combine(_ComputerDirectory, COMPUTER_CONFIG_NAME)
_AppConfigPath = Path.Combine(ApplicationStartupPath, "AppConfig.xml")
Config = LoadConfig()
End Sub
@@ -89,8 +96,8 @@ Public Class ConfigManager(Of T)
''' </summary>
''' <param name="LogConfig">LogConfig instance</param>
''' <param name="ConfigPath">The path to check for a user config file, eg. AppData (Usually Application.UserAppDataPath or Application.LocalUserAppDataPath)</param>
Public Sub New(LogConfig As LogConfig, ConfigPath As String)
MyClass.New(LogConfig, ConfigPath, ConfigPath, ForceUserConfig:=True)
Public Sub New(LogConfig As LogConfig, ConfigPath As String, ApplicationStartupPath As String)
MyClass.New(LogConfig, ConfigPath, ConfigPath, ApplicationStartupPath, ForceUserConfig:=True)
End Sub
''' <summary>
@@ -155,13 +162,35 @@ Public Class ConfigManager(Of T)
Private Function LoadConfig() As T
' first create an empty/default config object
Dim oConfig = Activator.CreateInstance(_BlueprintType)
' then Try to load computer config
oConfig = LoadComputerConfig(oConfig)
oConfig = LoadAppConfig(oConfig)
If oConfig Is Nothing Then
oConfig = Activator.CreateInstance(_BlueprintType)
' then Try to load computer config
oConfig = LoadComputerConfig(oConfig)
End If
' now try to load userconfig
oConfig = LoadUserConfig(oConfig)
Return oConfig
End Function
Private Function LoadAppConfig(ByVal Config As T) As T
If File.Exists(_AppConfigPath) Then
Try
Dim oAppConfig = ReadFromFile(_AppConfigPath)
CopyValues(oAppConfig, Config)
Catch ex As Exception
_Logger.Error(ex)
_Logger.Warn("ApplicationConfig could not be loaded!")
End Try
Else
_Logger.Debug("ApplicationConfig does not exist.")
_ForceUserConfig = True
Return Nothing
End If
Return Config
End Function
Private Function LoadComputerConfig(ByVal Config As T) As T
If File.Exists(_ComputerConfigPath) Then