From be1f74ceb0f60a7f50a3bd35bcf27584ac8906e5 Mon Sep 17 00:00:00 2001 From: Digital Data - Marlon Schreiber Date: Fri, 12 Jul 2019 12:21:58 +0200 Subject: [PATCH] MS WindowTitleMAtch --- app/DD_Clipboard_Searcher/clsHotkey.vb | 7 ++- app/DD_Clipboard_Searcher/frmResultDoc.vb | 10 +++- app/DD_Clipboard_Searcher/frmStart.vb | 63 ++++++++++++++++------- app/DD_Clipboard_Searcher/modCurrent.vb | 2 + 4 files changed, 59 insertions(+), 23 deletions(-) diff --git a/app/DD_Clipboard_Searcher/clsHotkey.vb b/app/DD_Clipboard_Searcher/clsHotkey.vb index 6697652..46c7ed9 100644 --- a/app/DD_Clipboard_Searcher/clsHotkey.vb +++ b/app/DD_Clipboard_Searcher/clsHotkey.vb @@ -74,10 +74,13 @@ Public Class clsHotkey End Class Public Shared Sub Refresh_Profile_Links() Try - Dim sql = String.Format("SELECT * FROM VWCW_USER_PROFILE WHERE USER_ID = {0}", USER_ID) - DT_USER_PROFILES = clsDatabase.Return_Datatable(sql) + Dim oSql = String.Format("SELECT * FROM VWCW_USER_PROFILE WHERE USER_ID = {0}", USER_ID) + DT_USER_PROFILES = clsDatabase.Return_Datatable(oSql) If DT_USER_PROFILES.Rows.Count = 0 Then MsgBox("No profiles configured for this user so far!", MsgBoxStyle.Exclamation) + Else + oSql = $"SELECT * FROM VWCW_PROFILE_REL_WINDOW WHERE USER_ID = {USER_ID}" + DTPROFILE_REL_WINDOW = clsDatabase.Return_Datatable(oSql) End If Catch ex As Exception MsgBox("Unexpected Error in Refresh_Profile_Links: " & ex.Message, MsgBoxStyle.Critical) diff --git a/app/DD_Clipboard_Searcher/frmResultDoc.vb b/app/DD_Clipboard_Searcher/frmResultDoc.vb index 563cd30..6c1754f 100644 --- a/app/DD_Clipboard_Searcher/frmResultDoc.vb +++ b/app/DD_Clipboard_Searcher/frmResultDoc.vb @@ -504,8 +504,14 @@ Public Class frmResultDoc frmProfileMatch.BringToFront() End If Catch ex As Exception - _frmProfileMatch.Show() - _frmProfileMatch.BringToFront() + If Not IsNothing(CurrDT_PROFILE_MATCH) Then + If CurrDT_PROFILE_MATCH.Rows.Count > 1 Then + _frmProfileMatch.Show() + _frmProfileMatch.BringToFront() + End If + + End If + End Try End Sub diff --git a/app/DD_Clipboard_Searcher/frmStart.vb b/app/DD_Clipboard_Searcher/frmStart.vb index a9ae3c2..f022869 100644 --- a/app/DD_Clipboard_Searcher/frmStart.vb +++ b/app/DD_Clipboard_Searcher/frmStart.vb @@ -38,7 +38,7 @@ Public Class frmStart ' .AppendText(String.Concat(vbNewLine, vbNewLine, "Text = '", _ ' Clipboard.GetText, "'", vbNewLine, vbNewLine)) 'End With - Dim found As Boolean = False + Dim oFound As Boolean = False CLIPBOARD_TEXT = Clipboard.GetText Logger.Debug(String.Format(" >>[{0}] Clipboard-Watcher fired for process '{1}'", Now.ToString, CurrPROC_Name), False) Dim oDTMatchProfiles As DataTable = New DataTable @@ -48,21 +48,43 @@ Public Class frmStart oDTMatchProfiles.Columns.Add("COMMENT") For Each oProfileRow As DataRow In DT_USER_PROFILES.Rows + Dim oProfileID = oProfileRow.Item("GUID") 'If found = True Then Exit For + '#### 1st CHECK: PROCESSNAME EQUAL #### If CurrPROC_Name.ToUpper = oProfileRow.Item("PROC_NAME").ToString.ToUpper Then - Dim regex_expression = oProfileRow.Item("REGEX_EXPRESSION") - Dim regex As New System.Text.RegularExpressions.Regex(regex_expression) - Dim match As System.Text.RegularExpressions.Match = regex.Match(CLIPBOARD_TEXT) - If match.Success Then - + '### 2nd CHECK: MATCH ClipboardValue + Dim oRegex_expression = oProfileRow.Item("REGEX_EXPRESSION") + Dim oRegex As New System.Text.RegularExpressions.Regex(oRegex_expression) + Dim oMatch As System.Text.RegularExpressions.Match = oRegex.Match(CLIPBOARD_TEXT) + If oMatch.Success Then ' If match.Groups(0).Value <> CURR_MATCH_RESULT Then - CURR_MATCH_RESULT = match.Groups(0).Value + CURR_MATCH_RESULT = oMatch.Groups(0).Value If Not IsNothing(CURR_MATCH_RESULT) Then + '#### 3rd CHECK: WindowTitle Match + Dim oMatchWindow As Boolean = True + Dim oCountWindowDefinitions As Integer = 0 + For Each oWindowMatchRow As DataRow In DTPROFILE_REL_WINDOW.Rows + If oWindowMatchRow.Item("PROFILE_ID") = oProfileID Then + oCountWindowDefinitions += 1 + oRegex_expression = oWindowMatchRow.Item("REGEX") + oRegex = New System.Text.RegularExpressions.Regex(oRegex_expression) + oMatch = oRegex.Match(CURR_FOCUSED_WINDOWNAME) + oMatchWindow = oMatch.Success + If oMatchWindow = True Then + Logger.Debug($"Found a match on windowtitle [{CURR_FOCUSED_WINDOWNAME}]") + Exit For + End If + End If + Next + If oMatchWindow = False Then + Logger.Debug($"Found NO MATCH on windowtitle [{CURR_FOCUSED_WINDOWNAME}], but [{oCountWindowDefinitions}] definitions are configured") + Exit For + End If 'CURR_MATCH_WM_SEARCH = oProfileRow.Item("WD_SEARCH") Dim oSQL_COUNT As String = oProfileRow.Item("SQL_COUNT_RESULT") Dim oRESULTDocs As Integer If oSQL_COUNT <> String.Empty Then - oSQL_COUNT = clsPatterns.ReplaceAllValues(oSQL_COUNT, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfileRow.Item("GUID")) + oSQL_COUNT = clsPatterns.ReplaceAllValues(oSQL_COUNT, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfileID) Try oRESULTDocs = ClassDatabase.Execute_Scalar(oSQL_COUNT, MyConnectionString) Catch ex As Exception @@ -71,13 +93,16 @@ Public Class frmStart Else oRESULTDocs = 99998 End If - Dim onewMatchRow As DataRow = oDTMatchProfiles.NewRow - onewMatchRow("GUID") = oProfileRow.Item("GUID") - onewMatchRow("NAME") = oProfileRow.Item("NAME") - onewMatchRow("COMMENT") = oProfileRow.Item("COMMENT") - onewMatchRow("COUNT") = oRESULTDocs - oDTMatchProfiles.Rows.Add(onewMatchRow) - found = True + If (oRESULTDocs <> 99998 And oRESULTDocs <> 99998 And oRESULTDocs <> 0) Then + Dim onewMatchRow As DataRow = oDTMatchProfiles.NewRow + onewMatchRow("GUID") = oProfileID + onewMatchRow("NAME") = oProfileRow.Item("NAME") + onewMatchRow("COMMENT") = oProfileRow.Item("COMMENT") + onewMatchRow("COUNT") = oRESULTDocs + oDTMatchProfiles.Rows.Add(onewMatchRow) + oFound = True + End If + End If 'Else @@ -86,12 +111,12 @@ Public Class frmStart ' Exit For 'End If Else - Logger.Debug(String.Format(" >> {0} - No regex-match for cliboardtext '{1}'", Now.ToString, match.Groups(0).Value), False) + 'Logger.Debug(String.Format(" >> {0} - No regex-match for cliboardtext '{1}'", Now.ToString, oMatch.Groups(0).Value), False) End If End If Next - If found = False Then - Logger.Debug(String.Format(" >> {0} - Process '{1}' not configured!", Now.ToString, CurrPROC_Name), False) + If oFound = False Then + Logger.Debug(String.Format(" >> {0} - oFound is false - no match on Clipboardvalue '{1}'!", Now.ToString, CURR_MATCH_RESULT), False) CurrDT_PROFILE_MATCH = Nothing Else CurrDT_PROFILE_MATCH = oDTMatchProfiles @@ -198,7 +223,7 @@ Public Class frmStart End Sub Private Sub ReceiveHotKey(ByVal HotKeyID As String) Handles Hotkey.HotKeyPressed If HotKeyID = 354523017 Then - If Not IsNothing(CURR_MATCH_RESULT) Then + If Not IsNothing(CURR_MATCH_RESULT) And Not IsNothing(CurrDT_PROFILE_MATCH) Then CHECK_PROFILE_MATCH() End If 'If Not IsNothing(CURR_MATCH_RESULT) And Not IsNothing(CURR_MATCH_WM_SEARCH) Then diff --git a/app/DD_Clipboard_Searcher/modCurrent.vb b/app/DD_Clipboard_Searcher/modCurrent.vb index c240b19..90827b1 100644 --- a/app/DD_Clipboard_Searcher/modCurrent.vb +++ b/app/DD_Clipboard_Searcher/modCurrent.vb @@ -58,6 +58,8 @@ Module modCurrent Public CLIENT_SELECTED As Integer = 0 Public CurrDT_PROFILE_MATCH As DataTable + Public DTPROFILE_REL_WINDOW As DataTable + Public CURRENT_DT_DOC_SEARCHES As DataTable Public CURRENT_DT_DATA_SEARCHES As DataTable Public CurrDocSearch2Load As Object