fix init
This commit is contained in:
parent
f54532a4b1
commit
9b39f0b4ae
@ -11,7 +11,6 @@ Imports System.ComponentModel
|
||||
Public Class frmSplashScreen
|
||||
Private LogConfig As LogConfig
|
||||
Private Logger As Logger
|
||||
Private Database As MSSQLServer
|
||||
Private ConfigManager As ConfigManager(Of Config)
|
||||
|
||||
Private WithEvents Worker As New BackgroundWorker() With {.WorkerReportsProgress = True}
|
||||
@ -22,25 +21,54 @@ Public Class frmSplashScreen
|
||||
Me.BringToFront()
|
||||
End Sub
|
||||
|
||||
Private Sub Worker_DoWork(sender As Object, e As DoWorkEventArgs) Handles Worker.DoWork
|
||||
Private Sub frmSplashScreen_Shown(sender As Object, e As EventArgs) Handles Me.Shown
|
||||
Dim oLogPath = IO.Path.Combine(Application.LocalUserAppDataPath, "Log")
|
||||
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, CompanyName:="Digital Data", ProductName:="Envelope Generator")
|
||||
Logger = LogConfig.GetLogger()
|
||||
|
||||
Try
|
||||
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath, Application.CommonAppDataPath, Application.StartupPath)
|
||||
|
||||
If ConfigManager.Config.ConnectionString = String.Empty Then
|
||||
Dim oSQLConfig As New frmSQLConfig(LogConfig)
|
||||
If oSQLConfig.ShowDialog() = DialogResult.OK Then
|
||||
ConfigManager.Config.ConnectionString = oSQLConfig.ConnectionString
|
||||
ConfigManager.Save()
|
||||
|
||||
MsgBox("Database configured. Application will restart.", MsgBoxStyle.Critical, Text)
|
||||
Application.Restart()
|
||||
Else
|
||||
MsgBox("No Database configured. Application will close!", MsgBoxStyle.Critical, Text)
|
||||
Application.Exit()
|
||||
End If
|
||||
End If
|
||||
|
||||
Worker.RunWorkerAsync(New State() With {
|
||||
.User = Nothing,
|
||||
.UserId = 0,
|
||||
.LogConfig = LogConfig,
|
||||
.Config = ConfigManager.Config,
|
||||
.Database = Nothing,
|
||||
.DbConfig = New DbConfig()
|
||||
})
|
||||
Catch ex As Exception
|
||||
Logger.Error(ex)
|
||||
MsgBox("Fehler beim Initialisieren: " & ex.Message & vbNewLine & vbNewLine & ex.StackTrace, MsgBoxStyle.Critical, Text)
|
||||
Application.Exit()
|
||||
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Sub Worker_DoWork(sender As Object, e As DoWorkEventArgs) Handles Worker.DoWork
|
||||
Dim oState As State = DirectCast(e.Argument, State)
|
||||
|
||||
Worker.ReportProgress(20, "Initialize Database")
|
||||
Thread.Sleep(300)
|
||||
|
||||
Dim oConnectionString = MSSQLServer.DecryptConnectionString(oState.Config.ConnectionString)
|
||||
Database = New MSSQLServer(oState.LogConfig, oConnectionString)
|
||||
oState.Database = New MSSQLServer(oState.LogConfig, oConnectionString)
|
||||
|
||||
oState = New State With {
|
||||
.UserId = 0,
|
||||
.Config = oState.Config,
|
||||
.DbConfig = New DbConfig(),
|
||||
.LogConfig = LogConfig,
|
||||
.Database = Database
|
||||
}
|
||||
|
||||
If Database.DBInitialized = False Then
|
||||
If oState.Database?.DBInitialized = False Then
|
||||
Throw New ApplicationException("Could not connect to the database. Application will close!")
|
||||
End If
|
||||
|
||||
@ -108,31 +136,7 @@ Public Class frmSplashScreen
|
||||
Close()
|
||||
End Sub
|
||||
|
||||
Private Sub frmSplashScreen_Shown(sender As Object, e As EventArgs) Handles Me.Shown
|
||||
Dim oLogPath = IO.Path.Combine(Application.LocalUserAppDataPath, "Log")
|
||||
LogConfig = New LogConfig(LogConfig.PathType.CustomPath, oLogPath, CompanyName:="Digital Data", ProductName:="Envelope Generator")
|
||||
Logger = LogConfig.GetLogger()
|
||||
ConfigManager = New ConfigManager(Of Config)(LogConfig, Application.UserAppDataPath, Application.CommonAppDataPath, Application.StartupPath)
|
||||
|
||||
If ConfigManager.Config.ConnectionString = String.Empty Then
|
||||
Dim oSQLConfig As New frmSQLConfig(LogConfig)
|
||||
If oSQLConfig.ShowDialog() = DialogResult.OK Then
|
||||
ConfigManager.Config.ConnectionString = oSQLConfig.ConnectionString
|
||||
ConfigManager.Save()
|
||||
|
||||
MsgBox("Database configured. Application will restart.", MsgBoxStyle.Critical, Text)
|
||||
Application.Restart()
|
||||
Else
|
||||
MsgBox("No Database configured. Application will close!", MsgBoxStyle.Critical, Text)
|
||||
Application.Exit()
|
||||
End If
|
||||
End If
|
||||
|
||||
Worker.RunWorkerAsync(New State() With {
|
||||
.LogConfig = LogConfig,
|
||||
.Config = ConfigManager.Config
|
||||
})
|
||||
End Sub
|
||||
|
||||
|
||||
End Class
|
||||
Loading…
x
Reference in New Issue
Block a user