Modules/GUIs.ZooFlow/ApplicationEvents.vb
2022-02-11 14:35:06 +01:00

81 lines
4.2 KiB
VB.net

Imports DigitalData.Modules.Config
Imports DigitalData.Modules.EDMI.API
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Logging.LogConfig
Imports Microsoft.VisualBasic.ApplicationServices
Namespace My
' Für MyApplication sind folgende Ereignisse verfügbar:
' Startup: Wird beim Starten der Anwendung noch vor dem Erstellen des Startformulars ausgelöst.
' Shutdown: Wird nach dem Schließen aller Anwendungsformulare ausgelöst. Dieses Ereignis wird nicht ausgelöst, wenn die Anwendung mit einem Fehler beendet wird.
' UnhandledException: Wird bei einem Ausnahmefehler ausgelöst.
' 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 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
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}
' 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)
' 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)
LogConfig = oLogConfig
LogConfig.Debug = True
SystemConfigManager = oConfigManager
UIConfigManager = oUIConfigManager
_Logger = LogConfig.GetLogger()
_Logger.Debug("Starting ZooFlow...")
If oConfigManager.Config.AppServerConfig <> String.Empty Then
Try
Dim oSplit() As String = oConfigManager.Config.AppServerConfig.ToString.Split(":"c)
Dim oAppServerAddress As String = oSplit(0)
Dim oAppServerPort As Integer = 9000
If oSplit.Length = 2 Then
oAppServerPort = oSplit(1)
End If
My.Application.Service.Client = New Client(LogConfig, oAppServerAddress, oAppServerPort)
If Not IsNothing(My.Application.Service.Client) Then
If My.Application.Service.Client.Connect() Then
My.Application.Service.IsActive = True
End If
End If
Catch ex As Exception
_Logger.Warn($"Could not initialize the AppServer: {ex.Message}")
End Try
End If
Dim oCommandLineArgs As New ClassCommandlineArgs(LogConfig)
Dim oArgs = Environment.GetCommandLineArgs().Skip(1).ToList()
oCommandLineArgs.Parse(oArgs)
CommandLineFunction = oCommandLineArgs.FunctionName
CommandLineArguments = oCommandLineArgs.FunctionArgs
End Sub
Public Sub App_Shutdown(sender As Object, e As EventArgs) Handles Me.Shutdown
_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)
End Sub
End Class
End Namespace