ZooFlow: First working version of Clipboard Watcher

This commit is contained in:
Jonathan Jenne
2021-01-19 16:03:11 +01:00
parent f5fd5ed1e1
commit e946a130ba
11 changed files with 195 additions and 118 deletions

View File

@@ -1,13 +1,14 @@
Option Explicit On
Imports System.IO
Imports System.Runtime.InteropServices
Imports DevExpress.XtraSplashScreen
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Messaging
Imports DigitalData.GUIs.ClipboardWatcher
Imports DigitalData.GUIs.ZooFlow.ClassConstants
Imports DigitalData.GUIs.ZooFlow.ClipboardWatcher
Imports DigitalData.Modules
Imports System.Runtime.InteropServices
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Messaging
Imports DigitalData.Modules.Windows
Public Class frmFlowForm
@@ -19,14 +20,20 @@ Public Class frmFlowForm
Private Logger As Logger
Private DTIDB_SEARCHES As DataTable
' Helper Classes
' Common Helpers Classes
Private Init As ClassInit
Private AppServerOrDB As ClassDataASorDB
Private FileClass As Filesystem.File
' Globix Helper Classes
Private FileDrop As ClassFileDrop
Private FileHandle As ClassFilehandle
Private FolderWatch As ClassFolderwatcher
' ClipboardWatcher Helper Classes
Private ClassWindow As Window
Private ProfileFilter As ProfileFilter
Private clsFW As ClassFolderwatcher
Private _DataASorDB As ClassDataASorDB
Private WindowClass As Window
Private ProfileLoader As ClassProfileLoader
' Runtime Flags
Private ApplicationLoading As Boolean = True
@@ -49,51 +56,26 @@ Public Class frmFlowForm
' === Hide form initially ===
Opacity = OPACITY_INITIAL
End Sub
<StructLayout(LayoutKind.Sequential)>
Public Structure WINDOWPOS
Public hwnd As IntPtr
Public hwndInsertAfter As IntPtr
Public x As Integer
Public y As Integer
Public cx As Integer
Public cy As Integer
Public flags As Integer
End Structure
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
' === Clean up logfiles ===
FileClass = New Filesystem.File(My.LogConfig)
FileClass.RemoveFiles(My.LogConfig.LogDirectory, 30, String.Empty, "log")
' === Initialize AppServer Database Connection with Failover
AppServerOrDB = New ClassDataASorDB(My.LogConfig)
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()
_DataASorDB = New ClassDataASorDB(My.LogConfig)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
' Listen for operating system messages
@@ -104,8 +86,7 @@ Public Class frmFlowForm
MyBase.WndProc(m)
End Sub
Public Shared Sub SnapToDesktopBorder(ByVal clientForm _
As Form, ByVal LParam As IntPtr, ByVal widthAdjustment As Integer)
Public Shared Sub SnapToDesktopBorder(ByVal clientForm As Form, ByVal LParam As IntPtr, ByVal widthAdjustment As Integer)
If clientForm Is Nothing Then
' Satisfies rule: Validate parameters
Throw New ArgumentNullException("clientForm")
@@ -116,9 +97,9 @@ Public Class frmFlowForm
Try
' Marshal the LPARAM value which is a WINDOWPOS struct
Dim NewPosition As New WINDOWPOS
NewPosition = CType(Runtime.InteropServices.Marshal.PtrToStructure(
LParam, GetType(WINDOWPOS)), WINDOWPOS)
Dim NewPosition As New ClassWin32.WINDOWPOS
NewPosition = CType(Marshal.PtrToStructure(
LParam, GetType(ClassWin32.WINDOWPOS)), ClassWin32.WINDOWPOS)
If NewPosition.y = 0 OrElse NewPosition.x = 0 Then
Return ' Nothing to do!
@@ -182,11 +163,11 @@ Public Class frmFlowForm
End If
' Marshal it back
Runtime.InteropServices.Marshal.StructureToPtr(NewPosition,
LParam, True)
Marshal.StructureToPtr(NewPosition, LParam, True)
Catch ex As ArgumentException
End Try
End Sub
Private Sub Init_Completed(sender As Object, e As EventArgs)
Me.Cursor = Cursors.WaitCursor
' === Initialization Complete ===
@@ -230,7 +211,7 @@ Public Class frmFlowForm
If My.Application.ModulesActive.Contains(MODULE_CLIPBOARDWATCHER) Then
Try
WindowClass = New Window(My.LogConfig)
ClassWindow = New Window(My.LogConfig)
HotkeyClass = New Hotkey(Me)
'Add Toggle Hotkey
@@ -256,19 +237,24 @@ Public Class frmFlowForm
Case "WIN"
HotkeyClass.AddHotKey(oKeyCode, Hotkey.ModfierKey.MOD_WIN, ClassConstants.HOTKEY_TRIGGER_WATCHER)
End Select
AddHandler HotkeyClass.HotKeyPressed, AddressOf HotkeyClass_HotKeyPressed
ProfileLoader = New ClassProfileLoader(My.LogConfig, AppServerOrDB)
ProfileLoader.LoadProfiles()
Catch ex As Exception
Logger.Error(ex)
MsgBox("Error while initializing Hotkeys for Clipboard Watcher!", MsgBoxStyle.Critical, Text)
MsgBox("Error while initializing 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(ClassConstants.MODULE_GLOBAL_INDEXER) Then
If My.Application.ModulesActive.Contains(MODULE_GLOBAL_INDEXER) Then
FileDrop = New ClassFileDrop(My.LogConfig)
FileHandle = New ClassFilehandle()
clsFW = New ClassFolderwatcher
FolderWatch = New ClassFolderwatcher
Refresh_RegexTable()
If My.Application.Globix.LoadFileExclusion = False Then
If My.Application.User.Language = "de-DE" Then
@@ -286,17 +272,17 @@ Public Class frmFlowForm
End If
oSQL = "SELECT * FROM TBIDB_ATTRIBUTE"
My.DTAttributes = _DataASorDB.GetDatatable("IDB", oSQL, "TBIDB_ATTRIBUTE", "", "")
My.DTAttributes = AppServerOrDB.GetDatatable("IDB", oSQL, "TBIDB_ATTRIBUTE", "", "")
Me.Cursor = Cursors.Default
End Sub
Public Sub Init_Folderwatch()
Try
Dim oSql As String = "SELECT FOLDER_PATH FROM TBGI_FOLDERWATCH_USER WHERE FOLDER_TYPE = 'DEFAULT' AND USER_ID = " & My.Application.User.UserId
Dim folderwatchPath = My.Database.GetScalarValue(oSql)
Dim oFolderWatchPath As Object = My.Database.GetScalarValue(oSql)
oFolderWatchPath = NotNull(oFolderWatchPath, String.Empty)
folderwatchPath = IIf(IsDBNull(folderwatchPath), "", folderwatchPath)
If folderwatchPath = String.Empty Then
If oFolderWatchPath = String.Empty Then
Logger.Info("Init_Folderwatch: folderwatchPath is empty")
My.Application.Globix.Folderwatchstarted = False
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "False")
@@ -305,7 +291,7 @@ Public Class frmFlowForm
End If
If Not IO.Directory.Exists(folderwatchPath) Then
If Not IO.Directory.Exists(oFolderWatchPath) Then
Logger.Info("Init_Folderwatch: folderwatchPath does not exists or is invalid path")
My.Application.Globix.Folderwatchstarted = False
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "False")
@@ -314,11 +300,11 @@ Public Class frmFlowForm
End If
My.Application.Globix.CURRENT_FOLDERWATCH = folderwatchPath
My.Application.Globix.CURRENT_FOLDERWATCH = oFolderWatchPath
My.Application.Globix.Folderwatchstarted = True
'FWFunction_STARTED = True
clsFW.StartStop_FolderWatch()
FolderWatch.StartStop_FolderWatch()
Catch ex As Exception
MsgBox($"Init_Folderwatch: Unexpected error while starting FolderWatch: {ex.Message}", MsgBoxStyle.Critical)
Logger.Info($"Init_Folderwatch: Unexpected error: {ex.Message}")
@@ -348,7 +334,7 @@ Public Class frmFlowForm
'FWFunction_STARTED = True
clsFW.StartStop_FolderWatchSCAN()
FolderWatch.StartStop_FolderWatchSCAN()
Catch ex As Exception
MsgBox($"Init_Folderwatch: Unexpected error while starting FolderWatchScan: {ex.Message}", MsgBoxStyle.Critical)
Logger.Info($"Init_Folderwatch: Unexpected error: {ex.Message}")
@@ -855,46 +841,44 @@ Public Class frmFlowForm
End Sub
Private Sub Watcher_ClipboardChanged(sender As Object, e As IDataObject)
If My.Application.ClipboardWatcher.MonitoringActive = False Then
Dim oState = My.Application.ClipboardWatcher
If oState.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
If oState.UserProfiles Is Nothing OrElse oState.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
If oState.ProfileProcesses Is Nothing OrElse oState.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
If oState.ProfileWindows Is Nothing OrElse oState.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
If oState.ProfileProcesses Is Nothing OrElse oState.ProfileProcesses.Rows.Count = 0 Then
Logger.Warn("Profile Processes is empty!")
Exit Sub
End If
Dim oWindowInfo = WindowClass.GetWindowInfo()
Dim oWindowInfo = ClassWindow.GetWindowInfo()
Dim ClipboardContents As String = Clipboard.GetText().Trim()
Try
' Tree View zurücksetzen
My.Application.ClipboardWatcher.MatchTreeView.Nodes.Clear()
oState.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
)
oState.UserProfiles, oState.ProfileProcesses,
oState.ProfileWindows, oState.ProfileControls,
oState.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)
@@ -919,7 +903,7 @@ Public Class frmFlowForm
' Filter by Focused Control
oProfiles = ProfileFilter.FilterProfilesByFocusedControl(oProfiles, ClipboardContents, Handle)
oProfiles = ProfileFilter.LogRemainingProfiles(oProfiles, "FilterProfilesByFocusedControl")
My.Application.ClipboardWatcher.CurrentMatchingProfiles = oProfiles.ToList()
oState.CurrentMatchingProfiles = oProfiles.ToList()
' Filter by Search Results
oProfiles = ProfileFilter.FilterProfilesBySearchResults(oProfiles, oEnvironment.Database, oEnvironment.User, ClipboardContents)
@@ -930,11 +914,56 @@ Public Class frmFlowForm
oProfiles = ProfileFilter.ClearDuplicateProfiles(oProfiles)
oProfiles = ProfileFilter.LogRemainingProfiles(oProfiles, "CleanUp")
My.Application.ClipboardWatcher.CurrentProfilesWithResults = oProfiles.ToList()
My.Application.ClipboardWatcher.CurrentClipboardContents = ClipboardContents
oState.CurrentProfilesWithResults = oProfiles.ToList()
oState.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
End Class
Private Sub HotkeyClass_HotKeyPressed(HotKeyID As String)
Dim oState = My.Application.ClipboardWatcher
Select Case HotKeyID
Case HOTKEY_TRIGGER_WATCHER
If oState.CurrentClipboardContents = String.Empty Then
Logger.Info("Current Clipboard Contents is empty. Exiting.")
Exit Sub
End If
If oState.MonitoringActive = False Then
Logger.Info("Monitoring is inactive. Exiting.")
Exit Sub
End If
If oState.CurrentMatchingProfiles.Count = 0 Then
NotifyIcon.ShowBalloonTip(NOTIFICATION_DELAY, "ClipboardWatcher", "Es wurden keine passenden Profile gefunden.", ToolTipIcon.Warning)
ElseIf oState.CurrentProfilesWithResults.Count = 0 Then
NotifyIcon.ShowBalloonTip(NOTIFICATION_DELAY, "ClipboardWatcher", "Es wurden keine passenden Profile gefunden.", ToolTipIcon.Warning)
Else
Dim oProfiles = oState.CurrentProfilesWithResults
Dim oEnvironment = My.Application.GetEnvironment()
Dim oParams As New DigitalData.Modules.ZooFlow.ClipboardWatcherParams With {
.ClipboardContents = oState.CurrentClipboardContents,
.MatchingProfiles = oProfiles,
.MatchTreeView = oState.MatchTreeView
}
Dim oForm As New frmMatch(My.LogConfig, oEnvironment, oParams)
oForm.Show()
End If
Case HOTKEY_TOGGLE_WATCHER
If oState.MonitoringActive = True Then
NotifyIcon.ShowBalloonTip(NOTIFICATION_DELAY, "ClipboardWatcher", "Clipboard-Watcher wurde deaktiviert!", ToolTipIcon.Info)
Else
NotifyIcon.ShowBalloonTip(NOTIFICATION_DELAY, "ClipboardWatcher", "Clipboard-Watcher wurde aktiviert!", ToolTipIcon.Info)
End If
oState.MonitoringActive = Not oState.MonitoringActive
End Select
End Sub
End Class