Option Explicit On Imports System.IO Imports DevExpress.XtraSplashScreen Imports DigitalData.Modules.Logging Imports DigitalData.Modules.Messaging Imports DigitalData.Modules.Windows Imports DigitalData.GUIs.ClipboardWatcher Imports DigitalData.GUIs.ZooFlow.ClassConstants Public Class frmFlowForm ' Constants Private Const OPACITY_INITIAL = 0 Private Const OPACITY_HIDDEN = 0.65 Private Const OPACITY_SHOWN = 0.85 Private Logger As Logger Private DTIDB_SEARCHES As DataTable ' Helper Classes Private Init As ClassInit Private FileDrop As ClassFileDrop Private FileHandle As ClassFilehandle Private ProfileFilter As ProfileFilter Private WindowClass As Window ' Runtime Flags Private ApplicationLoading As Boolean = True Private IDBSearchActive As Boolean = False ' Runtime Variables Private ESCHitCount As Integer = 0 Private IndexForm As frmGlobix_Index ' Events Public Event ClipboardChanged As EventHandler(Of IDataObject) Private WithEvents HotkeyClass As Hotkey Private WithEvents Watcher As ClipboardWatcher.Watcher = ClipboardWatcher.Watcher.Singleton Public Sub New() ' Dieser Aufruf ist für den Designer erforderlich. InitializeComponent() ' === Hide form initially === Opacity = OPACITY_INITIAL End Sub Private Sub frmFlowForm_Load(sender As Object, e As EventArgs) Handles Me.Load ' === Initialize Logger === Logger = My.LogConfig.GetLogger() ' === Show Splash Screen === SplashScreenManager.ShowForm(Me, GetType(frmSplash), False, False) Try Try Dim directory As New IO.DirectoryInfo(My.LogConfig.LogDirectory) For Each file As IO.FileInfo In directory.GetFiles If (Now - file.CreationTime).Days > 29 Then file.Delete() Else Exit For End If Next Catch ex As Exception End Try Catch ex As Exception End Try ' === Initialization === Init = New ClassInit(My.LogConfig, Me) AddHandler Init.Completed, AddressOf Init_Completed Init.InitializeApplication() End Sub Private Sub Init_Completed(sender As Object, e As EventArgs) Me.Cursor = Cursors.WaitCursor ' === Initialization Complete === ApplicationLoading = False SplashScreenManager.CloseForm(False) ' === Setup Timers === AddHandler TimerRefreshData.Tick, AddressOf TimerRefreshData_Tick TimerRefreshData.Enabled = True ' === Register As Event Listener === EventBus.Instance.Register(Me) ' === Set Form Properties === TopMost = True AllowDrop = True ShowInTaskbar = False Opacity = OPACITY_HIDDEN Location = My.UIConfig.FlowForm.Location ' === Setup Event Handlers === AddHandler KeyDown, AddressOf frmFlowForm_KeyDown AddHandler KeyUp, AddressOf frmFlowForm_KeyDown For Each oControl As Control In Controls AddHandler oControl.MouseEnter, AddressOf frmFlowForm_MouseEnter AddHandler oControl.MouseLeave, AddressOf frmFlowForm_MouseLeave Next AddHandler Watcher.ClipboardChanged, AddressOf Watcher_ClipboardChanged ' TODO: Clean up Dim oSQL = My.Queries.Common.FNIDB_GET_SEARCH_PROFILES(My.Application.User.UserId, My.Application.User.Language) Dim oDatatable As DataTable = My.DatabaseIDB.GetDatatable(oSQL) PictureBoxSearch.Visible = False If Not IsNothing(oDatatable) OrElse oDatatable.Rows.Count > 0 Then IDBSearchActive = True DTIDB_SEARCHES = oDatatable PictureBoxSearch.Visible = True End If If My.Application.ModulesActive.Contains(MODULE_CLIPBOARDWATCHER) Then Try WindowClass = New Window(My.LogConfig) HotkeyClass = New Hotkey(Me) 'Add Toggle Hotkey HotkeyClass.AddHotKey(Keys.T, Hotkey.ModfierKey.MOD_CONTROL, HOTKEY_TOGGLE_WATCHER) ' Add Trigger Hotkey 'TODO: Configure Hotkey Dim oSearchKey As String = "D" Dim oFunctionKey As String = "CTRL" Dim oConverter As New KeysConverter Dim oObject As Object = oConverter.ConvertFromString(oSearchKey) Dim oKeyCode As Keys = oObject Select Case oFunctionKey Case "CTRL" HotkeyClass.AddHotKey(oKeyCode, Hotkey.ModfierKey.MOD_CONTROL, ClassConstants.HOTKEY_TRIGGER_WATCHER) Case "SHIFT" HotkeyClass.AddHotKey(oKeyCode, Hotkey.ModfierKey.MOD_SHIFT, ClassConstants.HOTKEY_TRIGGER_WATCHER) Case "ALT" HotkeyClass.AddHotKey(oKeyCode, Hotkey.ModfierKey.MOD_ALT, ClassConstants.HOTKEY_TRIGGER_WATCHER) Case "WIN" HotkeyClass.AddHotKey(oKeyCode, Hotkey.ModfierKey.MOD_WIN, ClassConstants.HOTKEY_TRIGGER_WATCHER) End Select Catch ex As Exception Logger.Error(ex) MsgBox("Error while initializing Hotkeys for Clipboard Watcher!", MsgBoxStyle.Critical, Text) End Try Else My.Application.ClipboardWatcher.MonitoringActive = False Logger.Info("Clipboard Watcher Module is not active. Hotkey Monitoring will be disabled!") End If If My.Application.ModulesActive.Contains(MODULE_GLOBAL_INDEXER) Then FileDrop = New ClassFileDrop(My.LogConfig) FileHandle = New ClassFilehandle(My.LogConfig) Refresh_RegexTable() End If My.DTAttributes = My.DatabaseIDB.GetDatatable("SELECT * FROM TBIDB_ATTRIBUTE") Me.Cursor = Cursors.Default End Sub Private Sub Watcher_ClipboardChanged(sender As Object, e As IDataObject) If My.Application.ClipboardWatcher.MonitoringActive = False Then Logger.Info("Clipboard Watcher is not active!") Exit Sub End If If My.Application.ClipboardWatcher.UserProfiles Is Nothing OrElse My.Application.ClipboardWatcher.UserProfiles.Rows.Count = 0 Then Logger.Warn("User Profiles is empty!") Exit Sub End If If My.Application.ClipboardWatcher.ProfileProcesses Is Nothing OrElse My.Application.ClipboardWatcher.ProfileProcesses.Rows.Count = 0 Then Logger.Warn("Profile Processes is empty!") Exit Sub End If If My.Application.ClipboardWatcher.ProfileWindows Is Nothing OrElse My.Application.ClipboardWatcher.ProfileWindows.Rows.Count = 0 Then Logger.Warn("Profile Processes is empty!") Exit Sub End If If My.Application.ClipboardWatcher.ProfileProcesses Is Nothing OrElse My.Application.ClipboardWatcher.ProfileProcesses.Rows.Count = 0 Then Logger.Warn("Profile Processes is empty!") Exit Sub End If Dim oWindowInfo = WindowClass.GetWindowInfo() Dim ClipboardContents As String = Clipboard.GetText().Trim() Try ' Tree View zurücksetzen My.Application.ClipboardWatcher.MatchTreeView.Nodes.Clear() ProfileFilter = New ProfileFilter(My.LogConfig, My.Application.ClipboardWatcher.UserProfiles, My.Application.ClipboardWatcher.ProfileProcesses, My.Application.ClipboardWatcher.ProfileWindows, My.Application.ClipboardWatcher.ProfileControls, My.Application.ClipboardWatcher.MatchTreeView ) Catch ex As Exception Logger.Error(ex) MsgBox("Fehler beim Laden der Profile. Möglicherweise liegt ein Konfigurationsfehler vor. Mehr Informationen im Log.", MsgBoxStyle.Critical, Text) End Try Try Dim oProfiles = ProfileFilter.Profiles.AsEnumerable() Dim oEnvironment = ClassEnvironment.GetEnvironment() ' Filter by Clipboard Contents oProfiles = ProfileFilter.FilterProfilesByClipboardRegex(oProfiles, ClipboardContents) oProfiles = ProfileFilter.LogRemainingProfiles(oProfiles, "FilterProfilesByClipboardRegex") ' Filter by Process Name oProfiles = ProfileFilter.FilterProfilesByProcess(oProfiles, oWindowInfo.ProcessName) oProfiles = ProfileFilter.LogRemainingProfiles(oProfiles, "FilterProfilesByProcess") ' Filter by Window Title oProfiles = ProfileFilter.FilterWindowsByWindowTitleRegex(oProfiles, oWindowInfo.WindowTitle) oProfiles = ProfileFilter.LogRemainingProfiles(oProfiles, "FilterWindowsByWindowTitleRegex") ' Filter by Focused Control oProfiles = ProfileFilter.FilterProfilesByFocusedControl(oProfiles, ClipboardContents, Handle) oProfiles = ProfileFilter.LogRemainingProfiles(oProfiles, "FilterProfilesByFocusedControl") My.Application.ClipboardWatcher.CurrentMatchingProfiles = oProfiles.ToList() ' Filter by Search Results oProfiles = ProfileFilter.FilterProfilesBySearchResults(oProfiles, oEnvironment.Database, oEnvironment.User, ClipboardContents) oProfiles = ProfileFilter.LogRemainingProfiles(oProfiles, "FilterProfilesBySearchResults") ' Clean up Profiles oProfiles = ProfileFilter.ClearNotMatchedProfiles(oProfiles) oProfiles = ProfileFilter.ClearDuplicateProfiles(oProfiles) oProfiles = ProfileFilter.LogRemainingProfiles(oProfiles, "CleanUp") My.Application.ClipboardWatcher.CurrentProfilesWithResults = oProfiles.ToList() My.Application.ClipboardWatcher.CurrentClipboardContents = ClipboardContents Catch ex As Exception Logger.Error(ex) MsgBox("Fehler beim Auswerten der Profile. Mehr Informationen im Log.", MsgBoxStyle.Critical, Text) End Try End Sub Private Sub TimerRefreshData_Tick(sender As Object, e As EventArgs) 'TODO: Refresh Data End Sub Private Sub frmFlowForm_MouseLeave(sender As Object, e As EventArgs) Handles MyBase.MouseLeave Opacity = OPACITY_HIDDEN End Sub Private Sub frmFlowForm_MouseEnter(sender As Object, e As EventArgs) Handles Me.MouseEnter Opacity = OPACITY_SHOWN End Sub Private Sub frmFlowForm_MouseMove(ByVal sender As Object, ByVal e As MouseEventArgs) Handles Me.MouseMove, PictureBoxDragDrop.MouseMove If e.Button = MouseButtons.Left Then ClassWin32.ReleaseCapture() ClassWin32.SendMessage(Handle, ClassWin32.WM_NCLBUTTONDOWN, ClassWin32.HTCAPTION, 0) End If End Sub Private Sub frmFlowForm_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) If e.KeyCode = Keys.Escape Then If ESCHitCount > 0 Then ExitZooflow() Else ESCHitCount += 1 End If ElseIf e.KeyCode = Keys.D AndAlso (e.Control) Then If My.Application.ModulesActive.Contains(ClassConstants.MODULE_ZOOFLOW) Then MsgBox("Search") End If End If End Sub Sub ExitZooflow() Dim oResult As DialogResult = MessageBox.Show("Exit Zooflow", "Are you sure you want to close ZooFlow", MessageBoxButtons.YesNo, MessageBoxIcon.Question) If oResult = DialogResult.Yes Then Application.Exit() Else ESCHitCount = 0 End If End Sub Public Sub OnEvent(Params As Object) Logger.Debug("OnEvent called!") End Sub Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click Cursor = Cursors.WaitCursor If TheFormIsAlreadyLoaded("frmFlowSearch") Then Cursor = Cursors.Default Exit Sub End If Dim oSQL As String = "" For Each oRow As DataRow In My.DTCOMMON_SQL.Rows If oRow.Item("TITLE") = SQLCMD_FLOW_SEARCH1 Then oSQL = oRow.Item("SQL_COMMAND") End If Next If oSQL <> String.Empty Then Dim oForm As New frmFlowSearch(oSQL) oForm.Show() oForm.BringToFront() End If Cursor = Cursors.Default End Sub Private Sub PictureBoxSearch_Click(sender As Object, e As EventArgs) Handles PictureBoxSearch.Click Cursor = Cursors.WaitCursor If TheFormIsAlreadyLoaded("frmSearchStart") Then Cursor = Cursors.Default Exit Sub End If Dim oForm As New frmSearchStart(DTIDB_SEARCHES) 'frmFlowSearch(osql) oForm.Show() Cursor = Cursors.Default If TimerCheckActiveForms.Enabled = False Then TimerCheckActiveForms.Enabled = True End If End Sub Private Sub PictureBoxSearch_MouseEnter(sender As Object, e As EventArgs) Handles PictureBoxSearch.MouseEnter PictureBoxSearch.Image = My.Resources._2_LUPE_AKTIV_ZOO End Sub Private Sub PictureBoxSearch_MouseLeave(sender As Object, e As EventArgs) Handles PictureBoxSearch.MouseLeave PictureBoxSearch.Image = My.Resources._2_LUPE_INAKTIV_ZOO End Sub Private Sub PictureBoxPM_MouseEnter(sender As Object, e As EventArgs) Handles PictureBoxPM.MouseEnter PictureBoxPM.Image = My.Resources._3_PERSON_AKTIV_ZOO End Sub Private Sub PictureBoxPM_MouseLeave(sender As Object, e As EventArgs) Handles PictureBoxPM.MouseLeave PictureBoxPM.Image = My.Resources._3_PERSON_INAKTIV_ZOO End Sub Private Sub PictureBoxGlobix_MouseEnter(sender As Object, e As EventArgs) Handles PictureBoxGlobix.MouseEnter PictureBoxGlobix.Image = My.Resources._4_GLOBIX_AKTIV_ZOO End Sub Private Sub PictureBoxGlobix_MouseLeave(sender As Object, e As EventArgs) Handles PictureBoxGlobix.MouseLeave PictureBoxGlobix.Image = My.Resources._4_GLOBIX_INAKTIV_ZOO End Sub Private Sub ZooFlowBeendenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ZooFlowBeendenToolStripMenuItem.Click ExitZooflow() End Sub Private Sub VerwaltungToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles VerwaltungToolStripMenuItem.Click frmAdministrationZooFlow.Show() End Sub Private Sub frmFlowForm_DragEnter(sender As Object, e As DragEventArgs) Handles MyBase.DragEnter PictureBoxDragDrop.Image = My.Resources._1_LOGO_ZOO_FLOW_DROP3 e.Effect = DragDropEffects.Copy Drag_Enter(sender, e) End Sub Private Sub frmFlowForm_DragDrop(sender As Object, e As DragEventArgs) Handles MyBase.DragDrop DragDropForm(e) End Sub Private Sub frmFlowForm_DragLeave(sender As Object, e As EventArgs) Handles Me.DragLeave PictureBoxDragDrop.Image = My.Resources._1_LOGO_ZOO_FLOW1 End Sub Private Sub PictureBoxAbo_MouseEnter(sender As Object, e As EventArgs) Handles PictureBoxAbo.MouseEnter PictureBoxAbo.Image = My.Resources._2_ZOO_FLOW_Abo_MouseOver End Sub Private Sub PictureBoxAbo_MouseLeave(sender As Object, e As EventArgs) Handles PictureBoxAbo.MouseLeave PictureBoxAbo.Image = My.Resources._2_ZOO_FLOW_Abo End Sub Private Sub PictureBoxAbo_Click(sender As Object, e As EventArgs) Handles PictureBoxAbo.Click Cursor = Cursors.WaitCursor If TheFormIsAlreadyLoaded("frmPreSearch") Then Cursor = Cursors.Default Exit Sub End If Dim oForm2 As New frmSearchPredefined() oForm2.Show() Cursor = Cursors.Default End Sub Private Function TheFormIsAlreadyLoaded(ByVal pFormName As String) As Boolean TheFormIsAlreadyLoaded = False For Each frm As Form In Application.OpenForms If frm.Name.Equals(pFormName) Then TheFormIsAlreadyLoaded = True Exit Function End If Next End Function Private Function FormLoaded_Visible() As Boolean For Each frm As Form In Application.OpenForms If frm.Name.Equals("frmSearchStart") Or frm.Name.Equals("frmGlobix_Index") Then Me.Visible = False Exit Function End If Next Me.Visible = True TimerCheckActiveForms.Enabled = False End Function Private Sub DatenbankverbindungToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles DatenbankverbindungToolStripMenuItem.Click frmConfigDatabase.ShowDialog() End Sub Private Sub TimerCheckActiveForms_Tick(sender As Object, e As EventArgs) Handles TimerCheckActiveForms.Tick FormLoaded_Visible() If Me.Visible = False Then Exit Sub End Sub Private Sub NotifyIcon_DoubleClick(sender As Object, e As EventArgs) Handles NotifyIcon.DoubleClick If Me.Visible = False Then Me.Visible = True TimerCheckActiveForms.Enabled = False End If End Sub Private Sub PictureBox1_DragEnter(sender As Object, e As DragEventArgs) Handles PictureBoxDragDrop.DragEnter Drag_Enter(sender, e) End Sub Sub Drag_Enter(sender As Object, e As DragEventArgs) If e.Data.GetDataPresent(DataFormats.FileDrop) Then e.Effect = DragDropEffects.All ' Console.WriteLine("DragEnter ...DragDrop") ElseIf e.Data.GetDataPresent("FileGroupDescriptor") Then 'handle a message dragged from Outlook e.Effect = DragDropEffects.Copy ' Console.WriteLine("DragEnter ...OutlookMessage") ElseIf e.Data.GetDataPresent("aryFileGroupDescriptor") AndAlso (e.Data.GetDataPresent("FileContents")) Then e.Effect = DragDropEffects.Copy ' Console.WriteLine("DragEnter ...Attachment from Outlook") Else 'otherwise, do not handle e.Effect = DragDropEffects.None End If End Sub Sub DragDropForm(e As DragEventArgs) If Not My.Application.ModulesActive.Contains(ClassConstants.MODULE_GLOBAL_INDEXER) Then Exit Sub End If If TheFormIsAlreadyLoaded("frmIndexFileList") Then Cursor = Cursors.Default MsgBox("Please index the active file first!", MsgBoxStyle.Exclamation, "Drag 'n Drop not allowed!") Exit Sub End If 'Erstmal alles löschen My.Database.ExecuteNonQuery("DELETE FROM TBGI_FILES_USER WHERE UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')") If FileDrop.Drop_File(e) = True Then TimerCheckDroppedFiles.Start() Me.Cursor = Cursors.WaitCursor End If PictureBoxDragDrop.Image = My.Resources._1_LOGO_ZOO_FLOW1 End Sub Private Sub PictureBox1_DragDrop(sender As Object, e As DragEventArgs) Handles PictureBoxDragDrop.DragDrop DragDropForm(e) End Sub Private Sub TimerCheckDroppedFiles_Tick(sender As Object, e As EventArgs) Handles TimerCheckDroppedFiles.Tick If Not My.Application.ModulesActive.Contains(ClassConstants.MODULE_GLOBAL_INDEXER) Then Exit Sub End If TimerCheckDroppedFiles.Stop() Check_Dropped_Files() Me.Cursor = Cursors.Default End Sub Sub Check_Dropped_Files() Try My.Database.ExecuteNonQuery("DELETE FROM TBGI_FILES_USER WHERE WORKED = 1 AND UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')") Dim i As Integer For Each Str As Object In FileDrop.files_dropped If Not Str Is Nothing Then Logger.Info(">> Check Drop-File: " & Str.ToString) Dim handleType As String = Str.Substring(0, Str.LastIndexOf("|") + 1) Dim filename As String = Str.Substring(Str.LastIndexOf("|") + 1) If My.Application.Globix.FileExistsinDropTable(filename) = False Then FileHandle.Decide_FileHandle(filename, handleType) i += 1 Else ' Console.WriteLine("File gibt es bereits") End If End If Next Dim sql As String = "SELECT * FROM TBGI_FILES_USER WHERE WORKED = 0 AND UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')" My.Application.Globix.DTACTUAL_FILES = Nothing My.Application.Globix.DTACTUAL_FILES = My.Database.GetDatatable(sql) My.Application.Globix.ABORT_INDEXING = False Dim oOnlyFilesFromFilesystem = True For Each oRow As DataRow In My.Application.Globix.DTACTUAL_FILES.Rows If oRow.Item("HANDLE_TYPE").ToString <> "|DROPFROMFSYSTEM|" Then oOnlyFilesFromFilesystem = False Exit For End If Next If My.Application.Globix.DTACTUAL_FILES.Rows.Count > 1 And oOnlyFilesFromFilesystem = False Then frmGlobix_IndexFileList.ShowDialog() My.Application.Globix.DTACTUAL_FILES = Nothing My.Application.Globix.DTACTUAL_FILES = My.Database.GetDatatable(sql) End If For Each oFileRow As DataRow In My.Application.Globix.DTACTUAL_FILES.Rows Dim filestring As String = oFileRow.Item("FILENAME2WORK").ToString My.Application.Globix.CURRENT_FILENAME = oFileRow.Item("FILENAME2WORK").ToString My.Application.Globix.CURRENT_WORKFILE_GUID = oFileRow.Item(0) My.Application.Globix.CURRENT_WORKFILE = oFileRow.Item("FILENAME2WORK").ToString Logger.Info(">> CURRENT_WORKFILE: " & My.Application.Globix.CURRENT_WORKFILE) If IO.File.Exists(My.Application.Globix.CURRENT_WORKFILE) = True And My.Application.Globix.DTACTUAL_FILES.Rows.Count > 0 Then Globix_Open_IndexDialog() End If Next Show() Catch ex As Exception MsgBox("Unexpected Error in Check_Dropped_Files:" & vbNewLine & ex.Message, MsgBoxStyle.Critical) Show() End Try End Sub Sub Globix_Open_IndexDialog() Try IndexForm = New frmGlobix_Index(My.LogConfig) IndexForm.Show() Cursor = Cursors.Default If TimerCheckActiveForms.Enabled = False Then TimerCheckActiveForms.Enabled = True End If Catch ex As Exception Logger.Error(ex) MsgBox(ex.Message, MsgBoxStyle.Critical) End Try End Sub Private Sub frmFlowForm_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd My.UIConfig.FlowForm.Location = Location My.UIConfigManager.Save() End Sub Private Sub frmFlowForm_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing Try HotkeyClass.RemoveHotKey(HOTKEY_TOGGLE_WATCHER) HotkeyClass.RemoveHotKey(HOTKEY_TRIGGER_WATCHER) Catch ex As Exception Logger.Error(ex) Logger.Warn("Hotkeys could not be removed") End Try End Sub End Class