diff --git a/Filesystem/EncryptionLegacy.vb b/Filesystem/EncryptionLegacy.vb new file mode 100644 index 00000000..c56a9683 --- /dev/null +++ b/Filesystem/EncryptionLegacy.vb @@ -0,0 +1,66 @@ +Imports System.Security.Cryptography + +Public Class EncryptionLegacy + Private TripleDes As New TripleDESCryptoServiceProvider + Sub New(ByVal key As String) + ' Initialize the crypto provider. + TripleDes.Key = TruncateHash(key, TripleDes.KeySize \ 8) + TripleDes.IV = TruncateHash("", TripleDes.BlockSize \ 8) + End Sub + + Private Function TruncateHash(ByVal key As String, ByVal length As Integer) As Byte() + Dim sha1 As New SHA1CryptoServiceProvider + + ' Hash the key. + Dim keyBytes() As Byte = + System.Text.Encoding.Unicode.GetBytes(key) + Dim hash() As Byte = sha1.ComputeHash(keyBytes) + + ' Truncate or pad the hash. + ReDim Preserve hash(length - 1) + Return hash + End Function + + Public Function EncryptData(ByVal plaintext As String) As String + + ' Convert the plaintext string to a byte array. + Dim plaintextBytes() As Byte = + System.Text.Encoding.Unicode.GetBytes("!Didalog35452Heuchelheim=" & plaintext) + + ' Create the stream. + Dim ms As New System.IO.MemoryStream + ' Create the encoder to write to the stream. + Dim encStream As New CryptoStream(ms, + TripleDes.CreateEncryptor(), + System.Security.Cryptography.CryptoStreamMode.Write) + + ' Use the crypto stream to write the byte array to the stream. + encStream.Write(plaintextBytes, 0, plaintextBytes.Length) + encStream.FlushFinalBlock() + + ' Convert the encrypted stream to a printable string. + Return Convert.ToBase64String(ms.ToArray) + End Function + + 'Entschlüsselt die Zeichenfolge + Public Function DecryptData(ByVal encryptedtext As String) As String + ' Convert the encrypted text string to a byte array. + Dim encryptedBytes() As Byte = Convert.FromBase64String(encryptedtext) + + ' Create the stream. + Dim ms As New System.IO.MemoryStream + ' Create the decoder to write to the stream. + Dim decStream As New CryptoStream(ms, + TripleDes.CreateDecryptor(), + System.Security.Cryptography.CryptoStreamMode.Write) + + ' Use the crypto stream to write the byte array to the stream. + decStream.Write(encryptedBytes, 0, encryptedBytes.Length) + decStream.FlushFinalBlock() + Dim result = System.Text.Encoding.Unicode.GetString(ms.ToArray) + result = result.Replace("!Didalog35452Heuchelheim=", "") + ' Convert the plaintext stream to a string. + Return result + End Function +End Class + diff --git a/Filesystem/Filesystem.vbproj b/Filesystem/Filesystem.vbproj index 56723e0a..94131794 100644 --- a/Filesystem/Filesystem.vbproj +++ b/Filesystem/Filesystem.vbproj @@ -77,6 +77,7 @@ + diff --git a/Modules.Database/Constants.vb b/Modules.Database/Constants.vb index 76bc98be..e18e265b 100644 --- a/Modules.Database/Constants.vb +++ b/Modules.Database/Constants.vb @@ -2,4 +2,6 @@ Public Const PROVIDER_MSSQL = "MS-SQL" Public Const PROVIDER_ORACLE = "ORACLE" Public Const PROVIDER_ODBC = "ODBC" + + Public Const DEFAULT_TIMEOUT = 120 End Class diff --git a/ZooFlow/ApplicationEvents.vb b/ZooFlow/ApplicationEvents.vb new file mode 100644 index 00000000..1316755f --- /dev/null +++ b/ZooFlow/ApplicationEvents.vb @@ -0,0 +1,44 @@ +Imports Microsoft.VisualBasic.ApplicationServices +Imports DigitalData.Modules.Logging +Imports DigitalData.Modules.Config +Imports DigitalData.Modules.Logging.LogConfig + +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 _BaseUserConfigPath As String = Windows.Forms.Application.UserAppDataPath + Private _BaseLocalUserConfigPath As String = Windows.Forms.Application.LocalUserAppDataPath + Private _BaseMachineConfigPath As String = Windows.Forms.Application.CommonAppDataPath + + Public Sub App_Startup() Handles Me.Startup + Dim oLogConfig As New LogConfig(PathType.AppData) + + ' System Config files like Service Url will be saved in %LocalAppdata% so they will remain on the machine + Dim oSystemConfigManager As New ConfigManager(Of ClassConfig)(oLogConfig, + _BaseLocalUserConfigPath, + _BaseMachineConfigPath) + + ' Layout files will be saved in %Appdata% (Roaming) so they will be syncronized with the user profile + Dim oUIConfigPath = IO.Path.Combine(_BaseUserConfigPath, ClassConstants.FOLDER_NAME_LAYOUT) + Dim oUIConfigManager As New ConfigManager(Of ClassUIConfig)(oLogConfig, oUIConfigPath, oUIConfigPath) + + LogConfig = oLogConfig + SystemConfigManager = oSystemConfigManager + UIConfigManager = oUIConfigManager + + _Logger = LogConfig.GetLogger() + _Logger.Debug("Starting Client Suite..") + End Sub + + Public Sub App_Shutdown(sender As Object, e As EventArgs) Handles Me.Shutdown + _Logger.Debug("Shutting down Client Suite..") + End Sub + End Class +End Namespace diff --git a/ZooFlow/Base/BaseClass.vb b/ZooFlow/Base/BaseClass.vb new file mode 100644 index 00000000..73c5d141 --- /dev/null +++ b/ZooFlow/Base/BaseClass.vb @@ -0,0 +1,22 @@ +Imports DigitalData.Modules.Logging + + +Namespace Base + ''' + ''' Base Class which supplies a Logger/LogConfig + ''' + Public Class BaseClass + Protected LogConfig As LogConfig + Protected Logger As Logger + + Public Sub New(LogConfig As LogConfig) + Dim oClassName = Me.GetType().Name + + Me.LogConfig = LogConfig + Me.Logger = LogConfig.GetLogger(oClassName) + End Sub + End Class +End Namespace + + + diff --git a/ZooFlow/ClassConstants.vb b/ZooFlow/ClassConstants.vb new file mode 100644 index 00000000..da07d4d5 --- /dev/null +++ b/ZooFlow/ClassConstants.vb @@ -0,0 +1,25 @@ +Public Class ClassConstants + Public Const SERVICE_MAX_MESSAGE_SIZE = 2147483647 + Public Const SERVICE_MAX_BUFFER_SIZE = 2147483647 + Public Const SERVICE_MAX_ARRAY_LENGTH = 2147483647 + Public Const SERVICE_MAX_STRING_LENGTH = 2147483647 + Public Const SERVICE_MAX_CONNECTIONS = 10000 + Public Const SERVICE_OPEN_TIMEOUT = 3 + + Public Const CONTROL_TEXTEDIT = "TextBox" + Public Const CONTROL_MEMOEDIT = "Memoedit" + Public Const CONTROL_COMBOEDIT = "Combobox" + Public Const CONTROL_CHECKEDIT = "Checkbox" + Public Const CONTROL_RADIOEDIT = "Radiobutton" + Public Const CONTROL_DATEEDIT = "Datepicker" + + Public Const FOLDER_NAME_LAYOUT = "Layout" + + Public Const ATTRIBUTE_ID_COLUMN = "RECORD_ID" + + Public Const DB_USER_ATTRIBUTE_ID = 1 + Public Const DB_USER_ATTRIBUTE_SYSKEY = "001" + + Public Const DB_GROUP_ATTRIBUTE_ID = 2 + Public Const DB_GROUP_ATTRIBUTE_SYSKEY = "002" +End Class diff --git a/ZooFlow/ClassErrorHandler.vb b/ZooFlow/ClassErrorHandler.vb new file mode 100644 index 00000000..bceded3f --- /dev/null +++ b/ZooFlow/ClassErrorHandler.vb @@ -0,0 +1,60 @@ +Imports System.Reflection +Imports DigitalData.Modules.Logging + +Public Class ClassErrorHandler + Private _Logger As Logger + + Private Const UNKNOWN_METHOD = "Unknown Method" + Private Const UNKNOWN_FORM = "Unknown Form" + + Public Sub New(Logger As Logger) + _Logger = Logger + End Sub + Public Sub ShowErrorMessage(Exception As Exception) + _Logger.Error(Exception) + MsgBox(GetMessage(Exception), MsgBoxStyle.Critical, "Unexpected Error") + End Sub + + Private Function GetMessage(Exception As Exception) + Dim oTargetSite = Exception.TargetSite + Dim oMethodName = GetMethodName(Exception) + Dim oFormName = GetFormName(Exception) + Dim oMessage As String = String.Empty + + oMessage &= $"Form: {oFormName}{vbNewLine}" + oMessage &= $"Method: {oMethodName}{vbNewLine}" + + If Not String.IsNullOrEmpty(Exception.StackTrace) Then + oMessage &= $"Message: {Exception.Message}{vbNewLine}{vbNewLine}" + End If + + If Not String.IsNullOrEmpty(Exception.StackTrace) Then + oMessage &= $"Stacktrace: {Exception.StackTrace}{vbNewLine}" + End If + + oMessage &= $"{vbNewLine}" + oMessage &= $"Please report this error to error@digitaldata.works" + + Return oMessage + End Function + + Private Function GetMethodName(Exception As Exception) As String + Dim oMethodName = Exception.TargetSite?.ReflectedType?.Name + + If oMethodName Is Nothing Then + Return UNKNOWN_METHOD + Else + Return oMethodName + End If + End Function + + Private Function GetFormName(Exception As Exception) As String + Dim oFormName = Exception.TargetSite?.ReflectedType?.ReflectedType?.Name + + If oFormName Is Nothing Then + Return UNKNOWN_FORM + Else + Return oFormName + End If + End Function +End Class diff --git a/ZooFlow/ClassInit.vb b/ZooFlow/ClassInit.vb new file mode 100644 index 00000000..fd047200 --- /dev/null +++ b/ZooFlow/ClassInit.vb @@ -0,0 +1,78 @@ +Imports System.ComponentModel +Imports DevExpress.XtraSplashScreen +Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Filesystem + +Public Class ClassInit + Private _MainForm As frmMain + + Public Sub New(ParentForm As frmMain) + _MainForm = ParentForm + End Sub + + Public Sub InitializeApplication() + ' Init Connectivity + ' - Database / Service / Application Server + ' (Init Licensing) + ' Init User + ' Zeile -> Objekt / NameValue List + + If Not InitializeDatabase() Then + MsgBox("Verbindung konnte nicht hergestellt werden! Anwendung wird beendet", MsgBoxStyle.Critical, _MainForm.Text) + Application.Exit() + Else + Dim oInit As New ClassInitLoader() + oInit.AddStep("Checking connectivity..", AddressOf CheckConnectivity, True) + oInit.AddStep("Checking connectivity..2", AddressOf CheckConnectivity, True) + oInit.AddStep("Checking connectivity..3", AddressOf CheckConnectivity, True) + oInit.AddStep("Checking connectivity..4", AddressOf CheckConnectivity, True) + oInit.AddStep("Checking connectivity..5", AddressOf CheckConnectivity, True) + oInit.AddStep("Checking connectivity..6", AddressOf CheckConnectivity, True) + + AddHandler oInit.ProgressChanged, AddressOf ProgressChanged + AddHandler oInit.InitCompleted, AddressOf InitCompleted + + SplashScreenManager.ActivateParentOnSplashFormClosing = True + SplashScreenManager.ShowForm(_MainForm, GetType(frmSplash), False, False) + + oInit.Run() + + + End If + End Sub + + Private Sub ProgressChanged(sender As Object, Progress As ClassInitLoader.InitProgress) + SplashScreenManager.Default.SendCommand(frmSplash.SplashScreenCommand.SetProgress, Progress.CurrentPercent) + SplashScreenManager.Default.SendCommand(frmSplash.SplashScreenCommand.SetActionName, Progress.CurrentStep.Name) + End Sub + + Private Sub InitCompleted(sender As Object, e As RunWorkerCompletedEventArgs) + SplashScreenManager.CloseForm(False) + End Sub + + Private Sub CheckConnectivity() + Dim oCrypt As New EncryptionLegacy("!35452didalog=") + Dim oBuilder = My.SystemConfig.GetConnectionStringBuilder(My.SystemConfig.ConnectionString) + oBuilder.Password = oCrypt.DecryptData(oBuilder.Password) + Dim oDecryptedConnectionString = oBuilder.ToString + + My.Database = New MSSQLServer(My.LogConfig, oDecryptedConnectionString) + + If My.Database.DBInitialized = False Then + Throw New ApplicationException() + End If + End Sub + + Private Function InitializeDatabase() As Boolean + If My.SystemConfig.ConnectionString = String.Empty Then + Dim oResult = frmConfigDatabase.ShowDialog() + + If oResult = DialogResult.Cancel Then + MsgBox("Es wurde keine Datenbank hinterlegt. Die Anwendung wird beendet.") + Return False + End If + End If + + Return True + End Function +End Class diff --git a/ZooFlow/ClassInitLoader.vb b/ZooFlow/ClassInitLoader.vb new file mode 100644 index 00000000..4a8e58e2 --- /dev/null +++ b/ZooFlow/ClassInitLoader.vb @@ -0,0 +1,92 @@ +Imports System.ComponentModel +Imports DigitalData.Modules.Logging + +Public Class ClassInitLoader + Private _Worker As BackgroundWorker + Private _Logger As Logger + Private _CurrentStep As InitStep + + Public Steps As New List(Of InitStep) + Public Event ProgressChanged As EventHandler(Of InitProgress) + Public Event InitCompleted As EventHandler(Of RunWorkerCompletedEventArgs) + + Public Sub New() + _Logger = My.LogConfig.GetLogger() + End Sub + + Public Sub AddStep(Name As String, Action As Action, Optional Fatal As Boolean = False) + Steps.Add(New InitStep() With { + .Name = Name, + .Action = Action, + .Fatal = Fatal + }) + End Sub + + Public Function Run() As Boolean + _Worker = New BackgroundWorker() + _Worker.WorkerReportsProgress = True + + AddHandler _Worker.DoWork, AddressOf DoWork + AddHandler _Worker.ProgressChanged, Sub(sender As Object, e As ProgressChangedEventArgs) + Dim oProgress As New InitProgress() With { + .CurrentStep = _CurrentStep, + .CurrentPercent = e.ProgressPercentage + } + RaiseEvent ProgressChanged(sender, oProgress) + End Sub + AddHandler _Worker.RunWorkerCompleted, Sub(sender As Object, e As RunWorkerCompletedEventArgs) + RaiseEvent InitCompleted(sender, e) + End Sub + + _Worker.RunWorkerAsync() + + Return True + End Function + + Private Sub DoWork(sender As Object, e As DoWorkEventArgs) + Dim oStepCounter = 0 + + For Each oStep In Steps + _CurrentStep = oStep + + Try + oStep.Action.Invoke() + Catch ex As Exception + _Logger.Error(ex) + _Logger.Warn("Init Step '{0}' failed!", oStep.Name) + + If oStep.Fatal Then + _Logger.Warn("Fatal error in '{0}'. Init will be aborted!", oStep.Name) + e.Cancel = True + End If + End Try + + oStepCounter += 1 + + Dim oPercentComplete As Integer = CInt(Math.Truncate(oStepCounter / Steps.Count * 100)) + _Worker.ReportProgress(oPercentComplete) + + Threading.Thread.Sleep(600) + Next + End Sub + + Public Class InitProgress + Public CurrentStep As InitStep + Public CurrentPercent As Integer + End Class + + Public Class InitStep + ''' + ''' Human Readable Name of init step + ''' + Public Name As String + ''' + ''' The function to execute + ''' + Public Action As Action + ''' + ''' Should init be aborted if this step fails? + ''' + Public Fatal As Boolean + End Class +End Class \ No newline at end of file diff --git a/ZooFlow/Config/ClassConfig.vb b/ZooFlow/Config/ClassConfig.vb new file mode 100644 index 00000000..84fc6230 --- /dev/null +++ b/ZooFlow/Config/ClassConfig.vb @@ -0,0 +1,48 @@ +Imports System.Xml.Serialization +Imports DigitalData.Modules.Config.ConfigAttributes + +''' +''' --- User Config for EDMI --- +''' +''' All settings are simple properties that should have a default value where possible +''' +''' More complex properties (for example, ServiceConnection) are built from simple ones, +''' should be readonly and have an `XmlIgnore` Attribute to prevent them from being saved to the config file. +''' +''' They can make saving and loading complex properties more easy. +''' +''' The config is loaded with `ConfigManager` which is initialized in ApplicationEvents +''' to ensure that the config is loaded before any of the forms (that might need a config) +''' +''' The config object can be accessed in two ways: +''' +''' - My.ConfigManager.Config +''' - My.Config (which simply points to My.ConfigManager.Config) +''' +''' After changing a config value, My.ConfigManager.Save() must be called to persist the change in the config file +''' +Public Class ClassConfig + Public Function GetConnectionStringBuilder(ConnectionString As String) As SqlClient.SqlConnectionStringBuilder + Try + If ConnectionString = String.Empty Then + Return Nothing + End If + + Dim oBuilder As New SqlClient.SqlConnectionStringBuilder(ConnectionString) + Return oBuilder + Catch ex As Exception + Return Nothing + End Try + End Function + + + ' === Service Configuration === + + Public Property ConnectionString As String = String.Empty + + ' === Logging Configuration + Public Property LogDebug As Boolean = False + + ' === User Configuration === + Public Property UserLanguage As String = "de-DE" +End Class diff --git a/ZooFlow/Config/ClassUIConfig.vb b/ZooFlow/Config/ClassUIConfig.vb new file mode 100644 index 00000000..44a4d80d --- /dev/null +++ b/ZooFlow/Config/ClassUIConfig.vb @@ -0,0 +1,12 @@ +Public Class ClassUIConfig + Public Property SkinName As String = "Office 2016 Colorful" + + Public Property EditFormConfigs As New List(Of EditFormConfig) + + Public Class EditFormConfig + Public Property SysKey As String + + Public Property SplitterDistance As Integer = 700 + Public Property SplitterHorizontal As Boolean = True + End Class +End Class diff --git a/ZooFlow/My Project/licenses.licx b/ZooFlow/My Project/licenses.licx index 1d12274f..4ba5c3e6 100644 --- a/ZooFlow/My Project/licenses.licx +++ b/ZooFlow/My Project/licenses.licx @@ -1,3 +1,8 @@ DevExpress.XtraEditors.PictureEdit, DevExpress.XtraEditors.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a -DevExpress.XtraEditors.ProgressBarControl, DevExpress.XtraEditors.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a DevExpress.XtraBars.Ribbon.RibbonControl, DevExpress.XtraBars.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraLayout.LayoutControl, DevExpress.XtraLayout.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraEditors.ComboBoxEdit, DevExpress.XtraEditors.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraEditors.TextEdit, DevExpress.XtraEditors.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraEditors.ProgressBarControl, DevExpress.XtraEditors.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraEditors.CheckEdit, DevExpress.XtraEditors.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a +DevExpress.XtraEditors.ButtonEdit, DevExpress.XtraEditors.v18.1, Version=18.1.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a diff --git a/ZooFlow/MyApplication.vb b/ZooFlow/MyApplication.vb new file mode 100644 index 00000000..0a7de47c --- /dev/null +++ b/ZooFlow/MyApplication.vb @@ -0,0 +1,42 @@ +Imports DigitalData.Modules.Config +Imports DigitalData.Modules.Logging +Imports DigitalData.Modules.Database + +Namespace My + ''' + ''' Extends the My Namespace + ''' Example: My.LogConfig + ''' + + Module Extension + Property SystemConfigManager As ConfigManager(Of ClassConfig) + ReadOnly Property SystemConfig As ClassConfig + Get + Return SystemConfigManager.Config + End Get + End Property + + Property UIConfigManager As ConfigManager(Of ClassUIConfig) + ReadOnly Property UIConfig As ClassUIConfig + Get + Return UIConfigManager.Config + End Get + End Property + + Property LogConfig As LogConfig + Property MainForm As frmMain + Property Database As MSSQLServer + End Module + + ''' + ''' Extends the My.Application Namespace to hold Application State + ''' Example: My.Application.User + ''' + Partial Class MyApplication + ' User Config + Public User As New ClassUserState() + Public Service As New ClassServiceState() + End Class +End Namespace + + diff --git a/ZooFlow/State/ClassServiceState.vb b/ZooFlow/State/ClassServiceState.vb new file mode 100644 index 00000000..25047b48 --- /dev/null +++ b/ZooFlow/State/ClassServiceState.vb @@ -0,0 +1,4 @@ +Public Class ClassServiceState + Public Property Online As Boolean = True + Public Property LastChecked As DateTime = DateTime.Now +End Class diff --git a/ZooFlow/State/ClassUserState.vb b/ZooFlow/State/ClassUserState.vb new file mode 100644 index 00000000..41bc5b75 --- /dev/null +++ b/ZooFlow/State/ClassUserState.vb @@ -0,0 +1,20 @@ +Imports System.Threading + +''' +''' Helper Class to hold User State +''' +Public Class ClassUserState + Public UserName As String + Public MachineName As String + Public Language As String + Public IsAdmin As Boolean + + ''' + ''' Initialize user object with values that can be read from the environment + ''' + Public Sub New() + Language = Thread.CurrentThread.CurrentCulture.Name + UserName = Environment.UserName + MachineName = Environment.MachineName + End Sub +End Class \ No newline at end of file diff --git a/ZooFlow/ZooFlow.vbproj b/ZooFlow/ZooFlow.vbproj index 45b48dbc..b5f3d878 100644 --- a/ZooFlow/ZooFlow.vbproj +++ b/ZooFlow/ZooFlow.vbproj @@ -50,8 +50,17 @@ + + + ..\packages\NLog.4.5.11\lib\net45\NLog.dll + + + + + + @@ -73,9 +82,23 @@ + + + + + + + + + + frmConfigDatabase.vb + + + Form + Form @@ -99,6 +122,12 @@ Application.myapp + + + + + frmConfigDatabase.vb + frmMain.vb @@ -137,11 +166,30 @@ + + + + {991d0231-4623-496d-8bd0-9ca906029cbc} + Filesystem + + + {44982F9B-6116-44E2-85D0-F39650B1EF99} + Config + + + {EAF0EA75-5FA7-485D-89C7-B2D843B03A96} + Database + + + {903B2D7D-3B80-4BE9-8713-7447B704E1B0} + Logging + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/ZooFlow/frmConfigDatabase.vb b/ZooFlow/frmConfigDatabase.vb new file mode 100644 index 00000000..c67ada12 --- /dev/null +++ b/ZooFlow/frmConfigDatabase.vb @@ -0,0 +1,117 @@ +Imports DigitalData.Modules.Database +Imports DigitalData.Modules.Filesystem +Imports DigitalData.Modules.Logging + +Public Class frmConfigDatabase + Private Const STRING_CONNECTION_SUCCESSFUL = "Die Verbindung wurde erfolgreich aufgebaut!" & vbNewLine & "Möchten Sie diese Verbindung nun in der Anwendung speichern?" + + Private Logger As Logger = My.LogConfig.GetLogger() + + Private Sub frmConfigDatabase_Load(sender As Object, e As EventArgs) Handles MyBase.Load + Dim oConnectionString = My.SystemConfig.ConnectionString + + If Not oConnectionString = String.Empty Then + Dim oBuilder = My.SystemConfig.GetConnectionStringBuilder(oConnectionString) + + If oBuilder Is Nothing Then + MsgBox("Connection String ist ungültig!", MsgBoxStyle.Critical) + Exit Sub + End If + + If oConnectionString.Contains("Trusted") Then + chkWinAuth.Checked = True + txtConnectionString.Text = oConnectionString + Else + chkWinAuth.Checked = False + txtConnectionString.Text = oConnectionString.Replace(oBuilder.Password, "XXXXXX") + txtUserName.Text = oBuilder.UserID + End If + + txtServerName.Text = oBuilder.DataSource + cmbDatabase.Text = oBuilder.InitialCatalog + End If + End Sub + + Private Sub chkWinAuth_CheckedChanged(sender As Object, e As EventArgs) Handles chkWinAuth.CheckedChanged + txtPassword.Enabled = Not chkWinAuth.Checked + txtUserName.Enabled = Not chkWinAuth.Checked + End Sub + + Private Sub cmbDatabase_Click(sender As Object, e As EventArgs) Handles cmbDatabase.Click + Cursor = Cursors.WaitCursor + + Dim oConnectionString As String = GetConnectionString(False) + Dim oDatabase As New MSSQLServer(My.LogConfig, oConnectionString) + + If oDatabase.DBInitialized = False Then + MsgBox("Verbindung fehlgeschlagen!", MsgBoxStyle.Critical) + Exit Sub + End If + + Try + Using oConnection = New SqlClient.SqlConnection(oConnectionString) + oConnection.Open() + Using cmd As New SqlClient.SqlCommand("sp_databases", oConnection) + Using dr As SqlClient.SqlDataReader = cmd.ExecuteReader + If dr.HasRows Then + cmbDatabase.Properties.Items.Clear() + + Do While dr.Read + cmbDatabase.Properties.Items.Add(dr("Database_Name")) + Loop + cmbDatabase.ShowPopup() + Else + MsgBox("The standard-databases could not be retrieved. The default database will be set!" & vbNewLine & "Check rights in sql-server for user: " & Me.txtUserName.Text, MsgBoxStyle.Exclamation) + End If + End Using + End Using + End Using + + Catch ex As Exception + Logger.Error(ex) + End Try + + Cursor = Cursors.Default + End Sub + + Private Function GetConnectionString(WithDatabase As Boolean) As String + Dim oConnectionString As String + + If chkWinAuth.Checked Then + oConnectionString = $"Data Source={txtServerName.Text};Trusted_Connection=True;" + Else + oConnectionString = $"Server={txtServerName.Text};User Id={txtUserName.Text};Password={txtPassword.Text};" + End If + + If WithDatabase Then + oConnectionString &= $"Database={cmbDatabase.Text};" + End If + + Return oConnectionString + End Function + + Private Sub btnTestConnection_Click(sender As Object, e As EventArgs) Handles btnTestConnection.Click + Try + Dim oConnectionString = GetConnectionString(True) + + Using oConnection As New SqlClient.SqlConnection(oConnectionString) + oConnection.Open() + oConnection.Close() + End Using + + Dim oResult = MessageBox.Show(STRING_CONNECTION_SUCCESSFUL, Me.Text, MessageBoxButtons.YesNo, MessageBoxIcon.Question) + + If oResult = DialogResult.Yes Then + Dim oCrypt As New EncryptionLegacy("!35452didalog=") + Dim oEncryptedPassword = oCrypt.EncryptData(txtPassword.Text) + Dim oEncryptedConnectionString = $"Server={txtServerName.Text};Database={cmbDatabase.Text};User Id={txtUserName.Text};Password={oEncryptedPassword};" + + My.SystemConfig.ConnectionString = oEncryptedConnectionString + My.SystemConfigManager.Save() + End If + Catch ex As Exception + Logger.Error(ex) + MsgBox("Error while connecting to Database") + End Try + End Sub +End Class \ No newline at end of file diff --git a/ZooFlow/frmMain.vb b/ZooFlow/frmMain.vb index dd784da1..13f3c7a4 100644 --- a/ZooFlow/frmMain.vb +++ b/ZooFlow/frmMain.vb @@ -1,22 +1,26 @@ - +Imports System.ComponentModel Imports DevExpress.XtraSplashScreen +Imports DigitalData.Modules.Logging +Imports DigitalData.Modules.Filesystem +Imports DigitalData.Modules.Database Partial Public Class frmMain Private WithEvents FlowForm As New frmFlowForm() + Private Logger As Logger = My.LogConfig.GetLogger Public Sub New() InitializeComponent() - InitializeApplication() + End Sub Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load - FlowForm.Show() - - ToastNotificationsManager.ShowNotification(ToastNotificationsManager.Notifications.First) + Dim oInit As New ClassInit(Me) + oInit.InitializeApplication() End Sub Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown Hide() + FlowForm.Show() End Sub Private Sub FlowForm_ClipboardChanged(sender As Object, e As IDataObject) Handles FlowForm.ClipboardChanged @@ -49,16 +53,17 @@ Partial Public Class frmMain End If End Sub - Private Sub InitializeApplication() - SplashScreenManager.ShowForm(Me, GetType(frmSplash), False, False, False) - ' The splash screen will be opened in a separate thread. To interact with it, use the SendCommand method. - For i As Integer = 1 To 100 - SplashScreenManager.Default.SendCommand(frmSplash.SplashScreenCommand.SetProgress, i) - 'To process commands, override the SplashScreen.ProcessCommand method. - Threading.Thread.Sleep(25) - Next i + Private Sub ProgressChanged(sender As Object, Progress As ClassInitLoader.InitProgress) + SplashScreenManager.Default.SendCommand(frmSplash.SplashScreenCommand.SetProgress, Progress.CurrentPercent) + SplashScreenManager.Default.SendCommand(frmSplash.SplashScreenCommand.SetActionName, Progress.CurrentStep.Name) + End Sub + + Private Sub InitCompleted(sender As Object, e As RunWorkerCompletedEventArgs) SplashScreenManager.CloseForm(False) End Sub + + + End Class diff --git a/ZooFlow/frmSplash.Designer.vb b/ZooFlow/frmSplash.Designer.vb index e5283b35..ee51fd9c 100644 --- a/ZooFlow/frmSplash.Designer.vb +++ b/ZooFlow/frmSplash.Designer.vb @@ -26,7 +26,7 @@ Partial Class frmSplash Me.pictureEdit2 = New DevExpress.XtraEditors.PictureEdit() Me.pictureEdit1 = New DevExpress.XtraEditors.PictureEdit() Me.labelControl2 = New DevExpress.XtraEditors.LabelControl() - Me.LabelControl3 = New DevExpress.XtraEditors.LabelControl() + Me.txtActionName = New DevExpress.XtraEditors.LabelControl() Me.Version = New DevExpress.XtraEditors.LabelControl() Me.ProgressBarControl1 = New DevExpress.XtraEditors.ProgressBarControl() CType(Me.pictureEdit2.Properties, System.ComponentModel.ISupportInitialize).BeginInit() @@ -75,14 +75,14 @@ Partial Class frmSplash Me.labelControl2.TabIndex = 12 Me.labelControl2.Text = "Starting..." ' - 'LabelControl3 + 'txtActionName ' - Me.LabelControl3.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) - Me.LabelControl3.Location = New System.Drawing.Point(12, 321) - Me.LabelControl3.Name = "LabelControl3" - Me.LabelControl3.Size = New System.Drawing.Size(75, 13) - Me.LabelControl3.TabIndex = 12 - Me.LabelControl3.Text = "Loading stuff..." + Me.txtActionName.Anchor = CType((System.Windows.Forms.AnchorStyles.Bottom Or System.Windows.Forms.AnchorStyles.Left), System.Windows.Forms.AnchorStyles) + Me.txtActionName.Location = New System.Drawing.Point(12, 321) + Me.txtActionName.Name = "txtActionName" + Me.txtActionName.Size = New System.Drawing.Size(45, 13) + Me.txtActionName.TabIndex = 12 + Me.txtActionName.Text = "Loading.." ' 'Version ' @@ -109,7 +109,7 @@ Partial Class frmSplash Me.Controls.Add(Me.pictureEdit2) Me.Controls.Add(Me.pictureEdit1) Me.Controls.Add(Me.Version) - Me.Controls.Add(Me.LabelControl3) + Me.Controls.Add(Me.txtActionName) Me.Controls.Add(Me.labelControl2) Me.Name = "frmSplash" Me.Text = "Form1" @@ -123,7 +123,7 @@ Partial Class frmSplash Private WithEvents pictureEdit2 As DevExpress.XtraEditors.PictureEdit Private WithEvents pictureEdit1 As DevExpress.XtraEditors.PictureEdit Private WithEvents labelControl2 As DevExpress.XtraEditors.LabelControl - Private WithEvents LabelControl3 As DevExpress.XtraEditors.LabelControl + Private WithEvents txtActionName As DevExpress.XtraEditors.LabelControl Private WithEvents Version As DevExpress.XtraEditors.LabelControl Friend WithEvents ProgressBarControl1 As DevExpress.XtraEditors.ProgressBarControl End Class diff --git a/ZooFlow/frmSplash.vb b/ZooFlow/frmSplash.vb index 078fd848..8cf7d7ab 100644 --- a/ZooFlow/frmSplash.vb +++ b/ZooFlow/frmSplash.vb @@ -11,6 +11,8 @@ Case SplashScreenCommand.SetProgress Dim oPosition As Integer = CInt(Fix(arg)) ProgressBarControl1.Position = oPosition + Case SplashScreenCommand.SetActionName + txtActionName.Text = arg.ToString End Select End Sub @@ -20,5 +22,6 @@ Public Enum SplashScreenCommand SetProgress + SetActionName End Enum End Class diff --git a/ZooFlow/packages.config b/ZooFlow/packages.config new file mode 100644 index 00000000..f89fa324 --- /dev/null +++ b/ZooFlow/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file