Zooflow: Implement prefix for Config and Logging, Remove halbgar dev config

This commit is contained in:
Jonathan Jenne
2022-05-06 13:29:06 +02:00
parent 02f61b1e3f
commit 308b26556c
14 changed files with 109 additions and 130 deletions

View File

@@ -1,4 +1,5 @@
Imports DigitalData.Modules.Config
Imports System.IO.Path
Imports DigitalData.Modules.Config
Imports DigitalData.Modules.EDMI.API
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Logging.LogConfig
@@ -12,25 +13,57 @@ Namespace My
' StartupNextInstance: Wird beim Starten einer Einzelinstanzanwendung ausgelöst, wenn die Anwendung bereits aktiv ist.
' NetworkAvailabilityChanged: Wird beim Herstellen oder Trennen der Netzwerkverbindung ausgelöst.
Partial Friend Class MyApplication
Private _Logger As Logger
Private Logger As Logger
Private UserAppDataPath As String = Windows.Forms.Application.UserAppDataPath
Private BaseLocalUserConfigPath As String = Windows.Forms.Application.LocalUserAppDataPath
Private CommonAppDataPath As String = Windows.Forms.Application.CommonAppDataPath
Private StartupPath As String = Windows.Forms.Application.StartupPath
Private ReadOnly CommonAppDataPath As String = Windows.Forms.Application.CommonAppDataPath
Private ReadOnly StartupPath As String = Windows.Forms.Application.StartupPath
Private ReadOnly Property Prefix
Get
Return My.Settings.UserConfig_Prefix
End Get
End Property
Private ReadOnly Property HasPrefix
Get
Return TypeOf Prefix Is String AndAlso Prefix.Length > 0
End Get
End Property
Public ReadOnly Property UserAppDataPath As String
Get
If HasPrefix Then
Return Combine(Windows.Forms.Application.UserAppDataPath, Prefix)
Else
Return Windows.Forms.Application.UserAppDataPath
End If
End Get
End Property
Public ReadOnly Property LocalUserConfigPath As String
Get
If HasPrefix Then
Return Combine(Windows.Forms.Application.LocalUserAppDataPath, Prefix)
Else
Return Windows.Forms.Application.LocalUserAppDataPath
End If
End Get
End Property
Public Sub App_Startup() Handles Me.Startup
Dim oLogConfig As New LogConfig(LogPath:=PathType.AppData, CompanyName:="Digital Data", ProductName:="ZooFlow", FileKeepRangeInDays:=30) With {.Debug = True}
Dim oLogConfig As New LogConfig(LogPath:=PathType.CustomPath,
CustomLogPath:=Combine(LocalUserConfigPath, "Log"),
CompanyName:="Digital Data",
ProductName:="ZooFlow",
FileKeepRangeInDays:=30) With {.Debug = True}
' System Config files like Service Url will be saved in %LocalAppdata% so they will remain on the machine
Dim oConfigManager As New ConfigManager(Of ClassConfig)(oLogConfig, UserAppDataPath, CommonAppDataPath, StartupPath)
Dim oConfigManager As New ConfigManager(Of SystemConfig)(oLogConfig, UserAppDataPath, CommonAppDataPath, StartupPath)
' Layout files will be saved in %Appdata% (Roaming) so they will be syncronized with the user profile
Dim oUIConfigPath = IO.Path.Combine(UserAppDataPath, ClassConstants.FOLDER_NAME_LAYOUT)
Dim oUIConfigAlternatePath = IO.Path.Combine(UserAppDataPath, ClassConstants.FOLDER_NAME_LAYOUT)
Dim oUIConfigManager As New ConfigManager(Of ClassUIConfig)(oLogConfig, oUIConfigPath, oUIConfigPath, oUIConfigAlternatePath)
Dim oUIConfigManager As New ConfigManager(Of UIConfig)(oLogConfig, oUIConfigPath, oUIConfigPath, oUIConfigAlternatePath)
LogConfig = oLogConfig
LogConfig.Debug = True
@@ -38,8 +71,8 @@ Namespace My
SystemConfigManager = oConfigManager
UIConfigManager = oUIConfigManager
_Logger = LogConfig.GetLogger()
_Logger.Debug("Starting ZooFlow...")
Logger = LogConfig.GetLogger()
Logger.Debug("Starting ZooFlow...")
If oConfigManager.Config.AppServerConfig <> String.Empty Then
Try
@@ -55,7 +88,7 @@ Namespace My
My.Application.Service.Client.Connect()
End If
Catch ex As Exception
_Logger.Warn($"Could not initialize the AppServer: {ex.Message}")
Logger.Warn($"Could not initialize the AppServer: {ex.Message}")
End Try
End If
@@ -68,12 +101,13 @@ Namespace My
End Sub
Public Sub App_Shutdown(sender As Object, e As EventArgs) Handles Me.Shutdown
_Logger.Debug("Shutting down Zooflow..")
Logger.Debug("Shutting down Zooflow..")
End Sub
Private Sub MyApplication_UnhandledException(sender As Object, e As UnhandledExceptionEventArgs) Handles Me.UnhandledException
_Logger.Warn("Unhandled exception occurred: [{0}]", e.Exception.Message)
_Logger.Error(e.Exception)
Logger.Warn("Unhandled exception occurred: [{0}]", e.Exception.Message)
Logger.Error(e.Exception)
End Sub
End Class
End Namespace