From b6508ba650700ab9d03087afb8049d355608f3a0 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Fri, 30 Aug 2019 16:09:16 +0200 Subject: [PATCH] clean up --- app/DD_Clipboard_Searcher/ClassInit.vb | 2 +- .../ClassProfileFilter.vb | 32 ++++++--------- .../DD_Clipboard_Watcher.vbproj | 5 ++- app/DD_Clipboard_Searcher/frmStart.vb | 41 ++++--------------- 4 files changed, 24 insertions(+), 56 deletions(-) diff --git a/app/DD_Clipboard_Searcher/ClassInit.vb b/app/DD_Clipboard_Searcher/ClassInit.vb index fce572d..7953753 100644 --- a/app/DD_Clipboard_Searcher/ClassInit.vb +++ b/app/DD_Clipboard_Searcher/ClassInit.vb @@ -248,7 +248,7 @@ Public Class ClassInit Try Dim oSql = String.Format("SELECT DISTINCT GUID, NAME,REGEX_EXPRESSION,COMMENT,PROC_NAME,PROFILE_TYPE FROM VWCW_USER_PROFILE WHERE ACTIVE = 1 AND USER_ID = {0} OR GROUP_ID IN (SELECT DISTINCT GUID FROM TBDD_GROUPS WHERE GUID IN (SELECT GROUP_ID FROM TBDD_GROUPS_USER WHERE USER_ID = {0}))", USER_ID) DT_USER_PROFILES = Database.GetDatatable(oSql) - If DT_USER_PROFILES.Rows.Count = 0 Then + If DT_USER_PROFILES Is Nothing OrElse DT_USER_PROFILES.Rows.Count = 0 Then MsgBox("No profiles configured for this user so far!", MsgBoxStyle.Exclamation) Else oSql = $"SELECT T.* FROM TBCW_PROFILE_PROCESS T, VWPM_PROFILE_USER T1 WHERE T.PROFILE_ID = T1.PROFIL_ID AND T1.USER_ID = {USER_ID}" diff --git a/app/DD_Clipboard_Searcher/ClassProfileFilter.vb b/app/DD_Clipboard_Searcher/ClassProfileFilter.vb index 9ca9df9..55674ac 100644 --- a/app/DD_Clipboard_Searcher/ClassProfileFilter.vb +++ b/app/DD_Clipboard_Searcher/ClassProfileFilter.vb @@ -89,32 +89,24 @@ Public Class ClassProfileFilter Return _Profiles End Function - Friend Function RemoveDuplicateProfiles() As Object - Return _Profiles. - GroupBy(Function(p) p.Guid). - Select(Function(p) p.FirstOrDefault()) - End Function - Private Function NodeFind(ByVal n As TreeNode, searchTerm As String) - Dim aNode As TreeNode - For Each aNode In n.Nodes - If aNode.Text = searchTerm Then - Return aNode + Private Function FindNode(ByVal Node As TreeNode, SearchTerm As String) + Dim oNode As TreeNode + For Each oNode In Node.Nodes + If oNode.Text = SearchTerm Then + Return oNode End If Next - Return n + Return Node End Function - Private Function GetLowestNode(ByVal n As TreeNode) - Dim aNode As TreeNode - If n.GetNodeCount(False) = 1 Then - For Each aNode In n.Nodes - Return GetLowestNode(aNode) - Next + + Private Function GetLowestNode(ByVal Node As TreeNode) As TreeNode + If Node.GetNodeCount(False) = 1 Then + Return GetLowestNode(Node.Nodes.Item(0)) Else - Return n + Return Node End If - - End Function + Public Function FilterProfilesByClipboardRegex(Profiles As List(Of ProfileData), ClipboardContents As String) As List(Of ProfileData) Dim oFilteredProfiles As New List(Of ProfileData) For Each oProfile In Profiles diff --git a/app/DD_Clipboard_Searcher/DD_Clipboard_Watcher.vbproj b/app/DD_Clipboard_Searcher/DD_Clipboard_Watcher.vbproj index 1060df3..c710fee 100644 --- a/app/DD_Clipboard_Searcher/DD_Clipboard_Watcher.vbproj +++ b/app/DD_Clipboard_Searcher/DD_Clipboard_Watcher.vbproj @@ -73,8 +73,9 @@ ..\..\..\DDMonorepo\Modules.Config\bin\Debug\DigitalData.Modules.Config.dll - - P:\Projekte DIGITAL DATA\DIGITAL DATA - Entwicklung\DLL_Bibliotheken\Digital Data\DigitalData.Modules.Database.dll + + False + ..\..\..\DDMonorepo\Modules.Database\bin\Debug\DigitalData.Modules.Database.dll False diff --git a/app/DD_Clipboard_Searcher/frmStart.vb b/app/DD_Clipboard_Searcher/frmStart.vb index 3c18950..23e1fa3 100644 --- a/app/DD_Clipboard_Searcher/frmStart.vb +++ b/app/DD_Clipboard_Searcher/frmStart.vb @@ -1,9 +1,7 @@ Imports System.Threading Imports System.IO Imports System.Globalization -Imports DD_LIB_Standards Imports DD_Clipboard_Watcher.ClassConstants -Imports System.Windows.Automation Imports DD_Clipboard_Watcher.ClassWindowAPI Public Class frmStart @@ -75,8 +73,8 @@ Public Class frmStart End Try Try - Hotkey.RemoveHotKey(ClassConstants.HOTKEY_TOGGLE_WATCHER) - Hotkey.RemoveHotKey(ClassConstants.HOTKEY_TRIGGER_WATCHER) + Hotkey.RemoveHotKey(HOTKEY_TOGGLE_WATCHER) + Hotkey.RemoveHotKey(HOTKEY_TRIGGER_WATCHER) Catch ex As Exception Logger.Error(ex) Logger.Warn("Hotkeys could not be removed") @@ -107,10 +105,10 @@ Public Class frmStart Exit Sub End If - Dim oWindowInfo = ClassWindowAPI.GetWindowInfo() + Dim oWindowInfo = GetWindowInfo() Dim ClipboardContents As String = Clipboard.GetText() Dim oProfileFilter As ClassProfileFilter - Dim newoResult As IntPtr = FocusedControlinActiveWindow(Handle) + Dim oFocusedControl As IntPtr = FocusedControlinActiveWindow(Handle) Try oProfileFilter = New ClassProfileFilter(DT_USER_PROFILES, DTPROFILE_REL_PROCESS, DTPROFILE_REL_WINDOW, DTPROFILE_REL_CONTROL) Catch ex As Exception @@ -124,37 +122,14 @@ Public Class frmStart CurrMatchTreeView.SelectedImageIndex = 0 oProfiles = oProfileFilter.FilterProfilesByClipboardRegex(oProfiles, ClipboardContents) - If oProfiles.Count > 0 Then - oProfiles = oProfileFilter.FilterProfilesByProcess(oProfiles, oWindowInfo.ProcessName) - If oProfiles.Count > 0 Then - oProfiles = oProfileFilter.FilterWindowsByWindowTitleRegex(oProfiles, oWindowInfo.WindowTitle) - If oProfiles.Count > 0 Then - ' Dim ControlFocusResult - Dim oResult As WindowInfo = GetFocusedControl(Handle) - 'Automation = New ClassAutomation(LogConfig) - 'If Not IsNothing(Automation.AutomationId) Then - ' ControlFocusResult = Automation.AutomationId - 'Else - ' ControlFocusResult = String.Empty - 'End If - ' MsgBox(newoResult.ToString) - oProfiles = oProfileFilter.FilterProfilesByFocusedControl(oProfiles, ClipboardContents, newoResult.ToString) - 'oProfiles = oProfileFilter.FilterWindowsByWindowClipboardRegex(oProfiles, ClipboardContents) - End If - - - - End If - End If - 'oProfiles = oProfileFilter.RemoveDuplicateProfiles() + oProfiles = oProfileFilter.FilterProfilesByProcess(oProfiles, oWindowInfo.ProcessName) + oProfiles = oProfileFilter.FilterWindowsByWindowTitleRegex(oProfiles, oWindowInfo.WindowTitle) + oProfiles = oProfileFilter.FilterProfilesByFocusedControl(oProfiles, ClipboardContents, oFocusedControl.ToString) oProfiles = oProfileFilter.ClearNotMatchedProfiles(oProfiles) oProfiles = oProfiles.ToList() - - - CURRENT_MATCHING_PROFILES = oProfiles - CURRENT_CLIPBOARD_CONTENTS = ClipboardContents + CURRENT_CLIPBOARD_CONTENTS = ClipboardContents End Sub Private Sub ReceiveHotKey(ByVal HotKeyID As String) Handles Hotkey.HotKeyPressed