WIDIG/WIDigForm/frmMain.vb
Jonathan Jenne 96fe8fe492 bugfixes
2021-08-12 16:31:10 +02:00

163 lines
6.4 KiB
VB.net

Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Windream
Imports DigitalData.Modules.Config
Imports DigitalData.GUIs.WiDigShared
Imports DigitalData.Modules.Encryption
Public Class frmMain
Private _ArgumentLength As Integer
Private LogConfig As LogConfig
Private Logger As Logger
Private ConfigManager As ConfigManager(Of ClassConfig)
Private Config As ClassConfig
Private WiDig As ClassWIDig
Private Windream As Windream
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Try
Dim oLogConfig As New LogConfig(LogConfig.PathType.AppData, Nothing, "Form", "Digital Data", "WIDig")
LogConfig = oLogConfig
ConfigManager = New ConfigManager(Of ClassConfig)(LogConfig, ClassWIDig.GetAppDataPath, ClassWIDig.GetProgramDataPath)
Config = ConfigManager.Config
LogConfig.Debug = Config.LOG_DEBUG
Logger = LogConfig.GetLogger
If Config.ConnectionString = String.Empty Then
ShowSQLConfig()
End If
Logger.Debug("Initializing MainForm....")
WiDig = New ClassWIDig(LogConfig, Config)
txtPW.Text = WiDig.GetUserPWPlain()
txtUser.Text = Config.WMUsername
txtWMDrive.Text = Config.WMDrive
txtWMRelpath.Text = Config.WMRelPath
txtWMServer.Text = Config.WMUserPW
txtDomain.Text = Config.Domain
txtCommands.Text = Config.Arguments
If Config.Arguments.Length > 0 Then
RibbonGroupTest.Enabled = True
End If
Catch ex As Exception
MsgBox("Error while initializing: " & vbNewLine & vbNewLine & ex.Message, MsgBoxStyle.Critical, Text)
Logger.Error(ex)
End Try
End Sub
Public Sub InitUserConfig()
Dim oProgramDataPath = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Digital Data", "WIDig")
Dim oUserAppDataPath = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Digital Data", "WIDig")
End Sub
Private Sub Form1_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Dim oErrorMessage = WiDig?.ErrorMessage
If WiDig?.ErrorWhileParsing = True Then
MsgBox("A unexpected error occured while parsing arguments:" & vbNewLine & oErrorMessage, MsgBoxStyle.Critical)
End If
If WiDig?.ErrorWhileImporting = True Then
MsgBox("A unexpected error occured while importing file:" & vbNewLine & oErrorMessage, MsgBoxStyle.Critical)
End If
End Sub
Private Sub BarButtonItem1_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem1.ItemClick
Dim oEncryption As New EncryptionLegacy("!35452didalog=")
Dim oEncryptedPassword As String = oEncryption.EncryptData(Me.txtPW.Text)
Config.WMUserPW = oEncryptedPassword
Config.WMUsername = txtUser.Text
Config.WMDrive = txtWMDrive.Text
Config.WMRelPath = txtWMRelpath.Text
Config.WMServer = txtWMServer.Text
Config.Domain = txtDomain.Text
ConfigManager.Save()
BarStaticinfo.Caption = $"WM-Settings saved - {Now.ToString}"
BarStaticinfo.ItemAppearance.Normal.BackColor = Color.Lime
End Sub
Private Sub BarButtonItem2_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem2.ItemClick
Windream = New Windream(LogConfig, False, txtWMDrive.Text, txtWMRelpath.Text, True, txtWMServer.Text, txtUser.Text, txtPW.Text, txtDomain.Text)
If Not IsNothing(Windream) Then
MsgBox("Windream-Connext successfull!", MsgBoxStyle.Information)
End If
End Sub
Private Sub GroupBox1_Enter(sender As Object, e As EventArgs) Handles GroupBox1.Enter
RibbonGroupWindream.Enabled = True
End Sub
Private Sub GroupBox1_Leave(sender As Object, e As EventArgs) Handles GroupBox1.Leave
RibbonGroupWindream.Enabled = False
End Sub
Private Sub BarButtonItem4_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem4.ItemClick
Process.Start(LogConfig.LogDirectory)
End Sub
Private Sub BarButtonItem5_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnStartTest.ItemClick
Config.Arguments = txtCommands.Text
ConfigManager.Save()
Dim oArgs() As String = txtCommands.Text.Split("|")
Logger.Debug($"[{oArgs.Length}] Arguments will be checked...")
If IsNothing(Windream) Then
Dim oUserPW = WiDig.GetUserPWPlain()
If WiDig.Connect2Windream(oUserPW) = False Then
MsgBox("Windream could not be initialized!! Check Your log!", MsgBoxStyle.Critical)
Exit Sub
End If
End If
If WiDig.ParseArgs(oArgs) = False Then
MsgBox("An unexpected error occured while parsing arguments. Check the log!", MsgBoxStyle.Critical)
Process.Start(LogConfig.LogDirectory)
Else
If WiDig.StreamORIndexFile() = True Then
MsgBox("Import succeeded!", MsgBoxStyle.Information)
Else
MsgBox("Unexpected Error while streaming or indexing WMFile! Check the logfile!", MsgBoxStyle.Critical)
Process.Start(LogConfig.LogDirectory)
End If
End If
End Sub
Private Sub txtCommands_GotFocus(sender As Object, e As EventArgs) Handles txtCommands.GotFocus
RibbonGroupTest.Enabled = True
End Sub
Private Sub txtCommands_LostFocus(sender As Object, e As EventArgs) Handles txtCommands.LostFocus
RibbonGroupTest.Enabled = False
End Sub
Private Sub GroupBox2_Enter(sender As Object, e As EventArgs) Handles GroupBox2.Enter
RibbonGroupTest.Enabled = False
End Sub
Private Sub BarButtonItem5_ItemClick_1(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles BarButtonItem5.ItemClick
ShowSQLConfig()
End Sub
Private Sub ShowSQLConfig()
Dim oForm As New DigitalData.Controls.SQLConfig.frmSQLConfig(LogConfig) With {.FormTitle = "WiDig Test"}
Dim oResult = oForm.ShowDialog()
If oResult = DialogResult.OK Then
Config.ConnectionString = oForm.ConnectionString
ConfigManager.Save()
End If
End Sub
End Class