2025-01-24 12:56:59 +01:00

521 lines
22 KiB
VB.net

Imports System.Threading
Imports System.IO
Imports System.Globalization
Imports easyFLOW.ClassConstants
Imports easyFLOW.ClassWindowAPI
Imports DigitalData.Modules.ZooFlow
Imports DigitalData.Modules.Windows
Imports DigitalData.Modules.Base
Imports DigitalData.GUIs.ClipboardWatcher
Imports DevExpress.XtraBars.ToastNotifications
Imports DigitalData.GUIs.Common
Public Class frmMain
Private Const AppTitle = "easyFLOW"
Private WithEvents _Hotkey As New ClassHotkey(Me)
Private WithEvents _Watcher As ClasseasyFLOW = ClasseasyFLOW.Singleton
Private _Animator As New Animator() With {
.PopupColor = Color.FromArgb(165, 36, 49),
.PopupOpacity = 0.8,
.PopupSize = New Size(100, 30)
}
Private _MatchForm As frmMatch = Nothing
Private _DataASorDB As ClassDataASorDB
Private Class S
Inherits My.Resources.frmMain_Strings
End Class
Public Sub New()
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
Dim splash As New frmSplash()
splash.ShowDialog()
' === Language is set in ClassInit ===
'Try
' If USER_LANGUAGE <> "" Then
' Dim cultureInfo As New CultureInfo(USER_LANGUAGE)
' cultureInfo.DateTimeFormat.ShortDatePattern = USER_DATE_FORMAT
' Thread.CurrentThread.CurrentCulture = cultureInfo
' Thread.CurrentThread.CurrentUICulture = cultureInfo
' CultureInfo.DefaultThreadCurrentCulture = cultureInfo
' CultureInfo.DefaultThreadCurrentUICulture = cultureInfo
' End If
'Catch ex As Exception
' Logger.Error(ex)
'End Try
' Dieser Aufruf ist für den Designer erforderlich.
InitializeComponent()
_DataASorDB = New ClassDataASorDB(LogConfig)
End Sub
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
ClassWindowLocation.LoadFormLocationSize(Me)
If ERROR_INIT = "FAILED DBCONNECTION" Or ERROR_INIT = "DATABASE" Then
frmConfig_Basic.ShowDialog()
End If
lblUser.Caption = USER_USERNAME
LanguageEx.LogApplicationLanguage(Logger)
If Database.DBInitialized = True Then
If ERROR_INIT <> "" Then
If ERROR_INIT = "NO CLIENT" Then
MsgBox(String.Format(S.Sie_sind_keinem_Mandanten_zugewiesen__0_Bitte_wenden_Sie_sich_an__Ihren_Administrator_, vbNewLine), MsgBoxStyle.Exclamation)
Else
MsgBox(String.Format(S.Die_Benutzerkonfiguration_konnte_nicht_erfolgreich_durchgeführt_werden__0_Grund___1__2_Bitte_kontaktieren_sie_Ihren_Administrator_, vbNewLine, ERROR_INIT, vbNewLine), MsgBoxStyle.Exclamation)
'MsgBox("Sorry Something went wrong in user configuration!" & vbNewLine & "Reason: " & ERROR_INIT & vbNewLine & "Please contact the system administrator!", MsgBoxStyle.Exclamation)
End If
Exit Sub
End If
NotifyIconMain.Visible = True
ClassInit.Refresh_Profile_Links()
_DataASorDB.Refresh_Connections()
Try
_Hotkey.AddHotKey(Keys.T, ClassHotkey.ModfierKey.MOD_CONTROL, HOTKEY_TOGGLE_WATCHER)
Dim oKeyCode As Keys
Dim oConverter As New KeysConverter
Dim oObject As Object = oConverter.ConvertFromString(HotkeySearchKey.ToUpper)
oKeyCode = CType(oObject, Keys)
If HotkeyFunctionKey = HOTKEY_CTRL Then
_Hotkey.AddHotKey(oKeyCode, ClassHotkey.ModfierKey.MOD_CONTROL, ClassConstants.HOTKEY_TRIGGER_WATCHER)
ElseIf HotkeyFunctionKey = HOTKEY_SHIFT Then
_Hotkey.AddHotKey(oKeyCode, ClassHotkey.ModfierKey.MOD_SHIFT, ClassConstants.HOTKEY_TRIGGER_WATCHER)
End If
Catch ex As Exception
Logger.Warn($"Unexpected Error in Hotkey inititialize: {ex.Message}")
End Try
Try
If APPSERVER_ACTIVE = True Then
lblApplicationServer.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
Else
lblApplicationServer.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
End If
If BASIC_CONF_VISIBLE = False Then
bbtniKonfig.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
Else
bbtniKonfig.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
End If
If USER_IS_ADMIN = True Then
bbtnitemAdmin.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
Else
bbtnitemAdmin.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
End If
If USER_IS_ADMIN = False And BASIC_CONF_VISIBLE Then
RibbonPageGroup1.Visible = False
RibbonControl1.Minimized = True
End If
If BASEDATA_DT_LANGUAGE.Rows.Count > 1 Then
bbtniKonfig.Visibility = DevExpress.XtraBars.BarItemVisibility.Always
Else
bbtniKonfig.Visibility = DevExpress.XtraBars.BarItemVisibility.Never
End If
lblVersion.Caption = My.Application.Info.Version.ToString
lblUser.Caption = String.Format(lblUser.Caption, USER_USERNAME)
Catch ex As Exception
Logger.Warn($"Unexpected Error in FormLoad2: {ex.Message}")
End Try
End If
RefreshUI()
'Dim resources = New System.ComponentModel.ComponentResourceManager(Me.[GetType]())
'GetChildren(Me).ToList().ForEach(Sub(c) resources.ApplyResources(c, c.Name))
End Sub
Private Function GetChildren(pControl As Control) As IEnumerable(Of Control)
Dim oControls = pControl.Controls.Cast(Of Control)()
Return oControls.SelectMany(Of Control)(Function(ctrl) GetChildren(ctrl)).Concat(oControls)
End Function
Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Logger.Info(">> Logout time: " & Now.ToString, False)
If ERROR_INIT = "INVALID USER" Or ERROR_INIT = "NO CLIENT" Then
Exit Sub
End If
Try
Dim sql = "DELETE FROM TBDD_USER_MODULE_LOG_IN WHERE USER_ID = " & USER_ID & " AND (MODULE = 'easyFLOW' OR MODULE = 'Clipboard-Watcher')"
Database.ExecuteNonQuery(sql)
ClassWindowLocation.SaveFormLocationSize(Me, "")
My.Settings.Save()
Catch ex As Exception
End Try
Try
_Hotkey.RemoveHotKey(HOTKEY_TOGGLE_WATCHER)
_Hotkey.RemoveHotKey(HOTKEY_TRIGGER_WATCHER)
Catch ex As Exception
Logger.Error(ex)
Logger.Warn("Hotkeys could not be removed")
End Try
'TempDateien löschen
For Each oFile In TEMP_FILES
Try
IO.File.Delete(oFile)
Catch ex As Exception
Logger.Warn("Temp file {0} could not be deleted", oFile)
Logger.Error(ex)
End Try
Next
End Sub
Private Sub frmClipboardWatch_Disposed(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Disposed
_Watcher.Dispose()
End Sub
Private Sub WatcherChanged_New(ByVal sender As Object, ByVal e As String) Handles _Watcher.Changed
If MONITORING_ACTIVE = False Then
Logger.Info("easyFLOW is inactive!")
'NotifyIconMain.ShowBalloonTip(20000, "easyFLOW", "Clipboard-watcher is inactive.", ToolTipIcon.Info)
Exit Sub
End If
If DT_USER_PROFILES Is Nothing OrElse DT_USER_PROFILES.Rows.Count = 0 Then
Logger.Warn("DT_USER_PROFILES is empty!")
Exit Sub
End If
If DTPROFILE_REL_PROCESS Is Nothing OrElse DTPROFILE_REL_PROCESS.Rows.Count = 0 Then
Logger.Warn("DTPROFILE_REL_PROCESS is empty!")
Exit Sub
End If
If DTPROFILE_REL_WINDOW Is Nothing Then
Logger.Warn("DTPROFILE_REL_WINDOW is empty!")
Exit Sub
End If
If DTPROFILE_REL_CONTROL Is Nothing Then
Logger.Warn("DTPROFILE_REL_CONTROL is empty!")
Exit Sub
End If
Dim oWindowInfo = GetWindowInfo()
Dim ClipboardContents As String = Clipboard.GetText().Trim()
Dim oProfileFilter As ProfileFilter
Try
CurrMatchTreeView.Nodes.Clear()
CurrMatchTreeView.ImageList = ImageList1
CurrMatchTreeView.SelectedImageIndex = 0
oProfileFilter = New ProfileFilter(
LogConfig,
DT_USER_PROFILES,
DTPROFILE_REL_PROCESS,
DTPROFILE_REL_WINDOW,
DTPROFILE_REL_CONTROL,
CurrMatchTreeView
)
Catch ex As Exception
Logger.Error(ex)
MsgBox(S.Fehler_beim_Laden_der_Profile_, MsgBoxStyle.Critical, Text)
'MsgBox("Fehler beim Laden der Profile. Möglicherweise liegt ein Konfigurationsfehler vor. Mehr Informationen im Log.", MsgBoxStyle.Critical, Text)
Exit Sub
End Try
Try
Dim oProfiles = oProfileFilter.Profiles.AsEnumerable()
Dim oEnvironment = GetEnvironment()
oProfiles = oProfileFilter.FilterProfilesByClipboardRegex(oProfiles, ClipboardContents)
oProfiles = oProfileFilter.LogRemainingProfiles(oProfiles, "FilterProfilesByClipboardRegex")
oProfiles = oProfileFilter.FilterProfilesByProcess(oProfiles, oWindowInfo.ProcessName)
oProfiles = oProfileFilter.LogRemainingProfiles(oProfiles, "FilterProfilesByProcess")
oProfiles = oProfileFilter.FilterWindowsByWindowTitleRegex(oProfiles, oWindowInfo.WindowTitle)
oProfiles = oProfileFilter.LogRemainingProfiles(oProfiles, "FilterWindowsByWindowTitleRegex")
oProfiles = oProfileFilter.FilterProfilesByFocusedControl(oProfiles, ClipboardContents, Handle)
oProfiles = oProfileFilter.LogRemainingProfiles(oProfiles, "FilterProfilesByFocusedControl")
CURRENT_MATCHING_PROFILES = oProfiles.ToList()
oProfiles = oProfileFilter.FilterProfilesBySearchResults(oProfiles, oEnvironment.Database, oEnvironment.User, ClipboardContents)
oProfiles = oProfileFilter.LogRemainingProfiles(oProfiles, "FilterProfilesBySearchResults")
oProfiles = oProfileFilter.ClearNotMatchedProfiles(oProfiles)
oProfiles = oProfileFilter.ClearDuplicateProfiles(oProfiles)
oProfiles = oProfileFilter.LogRemainingProfiles(oProfiles, "CleanUp")
CURRENT_PROFILES_WITH_RESULTS = oProfiles.ToList()
CURRENT_CLIPBOARD_CONTENTS = ClipboardContents
Logger.Debug("WatcherChanged_New: CURRENT_PROFILES_WITH_RESULTS.Count: " & CURRENT_PROFILES_WITH_RESULTS.Count)
Catch ex As Exception
MsgBox(S.Fehler_beim_Auswerten_der_Profile__Mehr_Informationen_im_Log_, MsgBoxStyle.Critical, Text)
'MsgBox("Fehler beim Auswerten der Profile. Mehr Informationen im Log.", MsgBoxStyle.Critical, Text)
Logger.Error(ex)
End Try
End Sub
Private Sub ReceiveHotKey(ByVal HotKeyID As String) Handles _Hotkey.HotKeyPressed
If HotKeyID = HOTKEY_TRIGGER_WATCHER Then
'_Animator.Highlight(Cursor.Position)
If CURRENT_CLIPBOARD_CONTENTS IsNot Nothing Then
If MONITORING_ACTIVE = True Then
If CURRENT_MATCHING_PROFILES.Count = 0 Then
Logger.Info("ReceiveHotKey - No profiles matched the Clipboard-Content!")
Logger.Info("NOMATCH_INFO = {0}", NOMATCH_INFO)
If NOMATCH_INFO = False Then
Dim oMessageTitle As String
Dim oMessageText As String
oMessageTitle = "easyFLOW"
oMessageText = String.Format(S.Es_wurden_keine_passenden_Profile_gefunden_für_die_Suche_nach___0___, CURRENT_CLIPBOARD_CONTENTS)
If NOTIFY_MODE.ToUpper = "MSGBOX" Then
MsgBox(oMessageText, MsgBoxStyle.Exclamation, oMessageTitle)
Else
'NotifyIconMain.BalloonTipTitle = oMessageTitle
'NotifyIconMain.BalloonTipText = oMessageText
'NotifyIconMain.BalloonTipIcon = ToolTipIcon.Warning
'NotifyIconMain.ShowBalloonTip(2500)
AlertControl1.AutoFormDelay = 2500
AlertControl1.Show(Me, oMessageTitle, oMessageText)
End If
Else
Logger.Info("Popup will not be shown. NOMATCH_INFO Is True.")
End If
ElseIf CURRENT_PROFILES_WITH_RESULTS.Count = 0 Then
Logger.Info("ReceiveHotKey - No documents or data found for Clipboard-Content!")
Logger.Info("NOMATCH_INFO = {0}", NOMATCH_INFO)
If NOMATCH_INFO = False Then
Dim oMessageTitle As String
Dim oMessageText As String
oMessageTitle = "easyFLOW"
oMessageText = String.Format(S.Es_wurden_weder_Dokumente_noch_Daten_gefunden_für_die_Suche_nach___0___, CURRENT_CLIPBOARD_CONTENTS)
If NOTIFY_MODE.ToUpper = "MSGBOX" Then
MsgBox(oMessageText, MsgBoxStyle.Exclamation, oMessageTitle)
Else
'NotifyIconMain.BalloonTipTitle = oMessageTitle
'NotifyIconMain.BalloonTipText = oMessageText
'NotifyIconMain.BalloonTipIcon = ToolTipIcon.Warning
'NotifyIconMain.ShowBalloonTip(2500)
AlertControl1.AutoFormDelay = 2500
AlertControl1.Show(Me, oMessageTitle, oMessageText)
End If
Else
Logger.Info("Popup will not be shown. NOMATCH_INFO Is True.")
End If
Else
OpenMatchForm()
End If
End If
End If
ElseIf HotKeyID = HOTKEY_TOGGLE_WATCHER Then
Change_Monitoring_State()
End If
End Sub
Sub OpenMatchForm()
Logger.Debug("...now CHECK_PROFILE_MATCH...")
Dim oProfiles = CURRENT_PROFILES_WITH_RESULTS
Dim oEnv = GetEnvironment()
Dim oParams = New ClipboardWatcherParams() With {
.ClipboardContents = CURRENT_CLIPBOARD_CONTENTS,
.MatchingProfiles = oProfiles,
.MatchTreeView = CurrMatchTreeView,
.OperationModeOverride = IIf(
oEnv.Service.IsActive,
DigitalData.Modules.ZooFlow.Constants.OperationMode.WithAppServer,
DigitalData.Modules.ZooFlow.Constants.OperationMode.NoAppServer)
}
Dim oForm As New frmMatch(LogConfig, oEnv, oParams)
_MatchForm = oForm
oForm.Show()
End Sub
Private Function GetEnvironment() As Environment
Dim oUser As New State.UserState() With {
.DateFormat = USER_DATE_FORMAT,
.Email = USER_EMAIL,
.GivenName = USER_PRENAME,
.Language = USER_LANGUAGE,
.MachineName = System.Environment.MachineName,
.ShortName = USER_SHORTNAME,
.Surname = USER_SURNAME,
.UserId = USER_ID,
.UserName = USER_USERNAME
}
Dim oService As New State.ServiceState() With {
.Address = CONFIG.Config.AppServerConfig,
.IsActive = CONFIG.Config.IsIDB,
.IsOnline = False,
.Client = _Client
}
Dim oSettings As New State.SettingsState() With {
.GdPictureKey = GDPICTURE_LICENSE
}
Dim oEnvironment As New Environment() With {
.Database = Database,
.Modules = Nothing,
.User = oUser,
.Settings = oSettings,
.Service = oService
}
Return oEnvironment
End Function
Sub Change_Monitoring_State()
If MONITORING_ACTIVE = True Then
MONITORING_ACTIVE = False
NotifyIconMain.ShowBalloonTip(30000, "easyFLOW", S.Clipboard_Watcher_wurde_deaktiviert_, ToolTipIcon.Info)
Else
MONITORING_ACTIVE = True
NotifyIconMain.ShowBalloonTip(30000, "easyFLOW", S.Clipboard_Watcher_wurde_wieder_aktiviert_, ToolTipIcon.Info)
End If
End Sub
Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown
If ERROR_INIT <> "INVALID USER" And LICENSE_COUNT > 0 Then
If DT_USER_PROFILES.Rows.Count >= 1 Then
Hide()
End If
Else
If USER_IS_ADMIN = True And ERROR_INIT = "NO LICENSE" Then
MsgBox("As an admin You have access! Please inform Digital Data to add a valid license!", MsgBoxStyle.Exclamation, "No valid License")
Else
If Not USER_IS_ADMIN Then
MsgBox("Application will close now!", MsgBoxStyle.Critical, "No valid License")
Close()
End If
End If
End If
TimerRefresh.Start()
End Sub
Private Sub NotifyIcon1_DoubleClick(sender As Object, e As EventArgs) Handles NotifyIconMain.DoubleClick
OpenClose()
End Sub
Sub OpenClose()
If Visible = False Then
BringToFront()
Visible = True
TimerClose.Start()
Else
Hide()
NotifyIconMain.Visible = True
End If
End Sub
Private Sub TimerClose_Tick(sender As Object, e As EventArgs) Handles TimerClose.Tick
Hide()
End Sub
Private Sub frmMain_VisibleChanged(sender As Object, e As EventArgs) Handles Me.VisibleChanged
If TimerClose.Enabled = True Then
TimerClose.Stop()
End If
End Sub
Private Sub MinimierenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MinimierenToolStripMenuItem.Click
Hide()
End Sub
Private Sub ClientÖffnenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClientÖffnenToolStripMenuItem.Click
OpenClose()
End Sub
Private Sub ClientBeendenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClientBeendenToolStripMenuItem.Click
Shut_Down()
End Sub
Sub Shut_Down()
If MsgBox(S.Wollen_Sie_Clipboard_Watcher_wirklich_beenden_, MsgBoxStyle.Question Or MsgBoxStyle.YesNo, Text) = MsgBoxResult.Yes Then
Close()
End If
End Sub
Private Sub TimerRefresh_Tick(sender As Object, e As EventArgs) Handles TimerRefresh.Tick
RefreshUI()
End Sub
Private Sub RefreshUI()
Dim oResultText = ClassInit.Refresh_Profile_Links()
lblRefresh.Caption = ""
_DataASorDB.CheckModuleData()
'ClassInit.CheckModuleData()
labelStatus.Text = oResultText
labelRefresh.Text = String.Format(S.Aktualisiert___0_, Now.ToShortTimeString)
'labelRefresh.Text = $"Aktualisiert: {Now.ToShortTimeString}"
lblRefresh.Caption = String.Format(S.Eingeloggte_Benutzer___0_, USERCOUNT_LOGGED_IN)
'lblRefresh.Caption = $"Eingeloggte Benutzer: {USERCOUNT_LOGGED_IN}"
lblVersion.Caption = My.Application.Info.Version.ToString
lblUser.Caption = String.Format(lblUser.Caption, USER_USERNAME)
labelHotkey.Text = String.Format(labelHotkey.Text, $"{HotkeyFunctionKey.ToUpper}+{HotkeySearchKey.ToUpper}")
End Sub
Private Sub BisherigenAblaufAnzeigenToolStripMenuItem_Click_1(sender As Object, e As EventArgs) Handles BisherigenAblaufAnzeigenToolStripMenuItem.Click
If CurrMatchTreeView.Nodes.Count > 0 Then
Dim oForm As New frmTreeView(CurrMatchTreeView.Nodes)
oForm.Show()
End If
End Sub
Private Sub ClipboardWatcherStoppenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles tsmiChangeState.Click
If tsmiChangeState.Tag = "stop" Then
tsmiChangeState.Tag = "start"
tsmiChangeState.Image = My.Resources.control_start_blue
tsmiChangeState.Text = S.Clipboard_Watcher_starten
MONITORING_ACTIVE = False
NotifyIconMain.ShowBalloonTip(30000, "easyFLOW", S.Clipboard_Watcher_wurde_deaktiviert_, ToolTipIcon.Info)
Else
tsmiChangeState.Image = My.Resources.StatusAnnotations_Stop_16xLG
tsmiChangeState.Tag = "stop"
tsmiChangeState.Text = S.Clipboard_Watcher_stoppen
MONITORING_ACTIVE = True
NotifyIconMain.ShowBalloonTip(30000, "easyFLOW", S.Clipboard_Watcher_wurde_wieder_aktiviert_, ToolTipIcon.Info)
End If
End Sub
Private Sub bbtnitemAdmin_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles bbtnitemAdmin.ItemClick
TimerClose.Stop()
MONITORING_ACTIVE = False
frmAdministration.ShowDialog()
TimerClose.Start()
MONITORING_ACTIVE = True
RefreshUI()
End Sub
Private Sub bbtniKonfig_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles bbtniKonfig.ItemClick
frmConfig_Basic.ShowDialog()
End Sub
Private Sub bbtnitmLanguage_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles bbtnitmLanguage.ItemClick
Dim oNForm As New frmLanguage_Select(LogConfig, MyConnectionString, USER_USERNAME, BASEDATA_DT_LANGUAGE, "EF")
oNForm.ShowDialog()
If oNForm.pChanged = True Then
MsgBox("For the changes to take effect, the program must now be closed. Restart it afterwards.", MsgBoxStyle.Exclamation, "Restart:")
Me.Close()
End If
End Sub
End Class