From 660231325c50107d4563bf6af9f4477295d0be86 Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Thu, 24 Oct 2019 16:34:32 +0200 Subject: [PATCH] improve logging in profile filter --- GUIs.ClipboardWatcher/ProfileFilter.vb | 44 ++++++++++++++++++-------- GUIs.ClipboardWatcher/ProfileMatch.vb | 13 ++++++-- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/GUIs.ClipboardWatcher/ProfileFilter.vb b/GUIs.ClipboardWatcher/ProfileFilter.vb index 161dc4cb..0c9954dd 100644 --- a/GUIs.ClipboardWatcher/ProfileFilter.vb +++ b/GUIs.ClipboardWatcher/ProfileFilter.vb @@ -84,6 +84,7 @@ Public Class ProfileFilter Dim oMatch = oRegex.Match(ClipboardContents) If oMatch.Success Then _Logger.Debug("FilterProfilesByClipboardRegex: Clipboard Regex Matched: {0}", ClipboardContents) + _Logger.Info("Profile {0} matched!", oProfile.Name) oFilteredProfiles.Add(oProfile) oProfile.IsMatched = True @@ -104,10 +105,6 @@ Public Class ProfileFilter For Each oProfile In Profiles Dim oGuid = oProfile.Guid - If oProfile.IsMatched = False Then - Continue For - End If - Dim oProcesses As New List(Of ProcessData) For Each oProcessDef As ProcessData In oProfile.Processes If oProcessDef.PROFILE_ID <> oGuid Then @@ -121,11 +118,13 @@ Public Class ProfileFilter oParent.Nodes.Add(oNode) End If - _Logger.Debug($"FilterProfilesByProcess: Checking Profile: {oProfile.Name} ...") + _Logger.Debug($"FilterProfilesByProcess: Checking Profile: {oProfile.Name}") If oIsMatch Then - _Logger.Debug($"Yes...Processname Matched: {oProcessDef.ProcessName}") - 'TODO: Add Debug Data + _Logger.Debug($"Processname Matched: {oProcessDef.ProcessName}") + oFilteredProfiles.Add(oProfile) + _Logger.Info("Profile {0} matched!", oProfile.Name) + oProfile.MatchedProcessID = oProcessDef.Guid oProcessDef.IsMatched = True oProcesses.Add(oProcessDef) @@ -151,9 +150,16 @@ Public Class ProfileFilter For Each oProfile As ProfileData In Profiles _Logger.Debug("Checking WindowDefinition for profile: {0}...", oProfile.Name) - If oProfile.IsMatched = False Then Continue For Dim oWindows As New List(Of WindowData) + ' If Profile has no windows at all, it automatically matches + If oProfile.Windows.Count = 0 Then + oProfile.IsMatched = True + oProfiles.Add(oProfile) + + Continue For + End If + For Each oWindowDef As WindowData In oProfile.Windows If oWindowDef.WindowProcessID <> oProfile.MatchedProcessID Then Continue For Try @@ -186,10 +192,13 @@ Public Class ProfileFilter End Try Next + ' If Profile has windows that matched, the profile matches If oWindows.Count > 0 Then oProfile.Windows = oWindows oProfile.IsMatched = True oProfiles.Add(oProfile) + + _Logger.Info("Profile {0} matched!", oProfile.Name) End If Next @@ -201,8 +210,7 @@ Public Class ProfileFilter Dim oWindow As New Window(_LogConfig) For Each oProfile In Profiles - If oProfile.IsMatched = False Then Continue For - + ' If Profile has no controls at all, it automatically matches If oProfile.Controls.Count = 0 Then oFilteredProfiles.Add(oProfile) Continue For @@ -246,13 +254,15 @@ Public Class ProfileFilter End If Next + ' If Profile has controls that matched, the profile matches If oControls.Count > 0 Then oProfile.Controls = oControls oFilteredProfiles.Add(oProfile) + + _Logger.Info("Profile {0} matched!", oProfile.Name) End If Next - Return oFilteredProfiles End Function @@ -320,10 +330,14 @@ Public Class ProfileFilter End Try Next - If oResultData > 0 Or oResultDocs > 0 Then - oProfile.CountData = oResultData - oProfile.CountDocs = oResultDocs + oProfile.CountData = oResultData + oProfile.CountDocs = oResultDocs + Next + + For Each oProfile In Profiles + If oProfile.CountData > 0 Or oProfile.CountDocs > 0 Then oProfiles.Add(oProfile) + _Logger.Info("Profile {0} matched!", oProfile.Name) End If Next @@ -368,6 +382,8 @@ Public Class ProfileFilter If oWindows.Count > 0 Then oProfile.Windows = oWindows oProfiles.Add(oProfile) + + _Logger.Info("Profile {0} matched!", oProfile.Name) End If Next diff --git a/GUIs.ClipboardWatcher/ProfileMatch.vb b/GUIs.ClipboardWatcher/ProfileMatch.vb index 52d68bd1..8f36bf4f 100644 --- a/GUIs.ClipboardWatcher/ProfileMatch.vb +++ b/GUIs.ClipboardWatcher/ProfileMatch.vb @@ -25,6 +25,8 @@ Public Class ProfileMatch End Function Public Function NewProfileNode(Profile As ProfileData) As TreeNode + _Logger.Debug("New Profile Node for Profile {0}", Profile.Name) + Dim oNode As New TreeNode() With { .Text = $"Profile: {Profile.Name}", .ImageIndex = ProfileFilter.ImageIndex.Profile, @@ -35,8 +37,9 @@ Public Class ProfileMatch End Function Public Function NewClipboardRegexNode(Profile As ProfileData, IsMatch As Boolean) As TreeNode - Dim oText = $"{GetMatchText(IsMatch)} on Global Clipboard Regex {Profile.Regex}" + _Logger.Debug("New Clipboard Regex Node for Profile {0}", Profile.Name) + Dim oText = $"{GetMatchText(IsMatch)} on Global Clipboard Regex {Profile.Regex}" Dim oNode As New TreeNode() With { .Text = oText, .ImageIndex = ProfileFilter.ImageIndex.Clipboard, @@ -47,9 +50,10 @@ Public Class ProfileMatch Return oNode End Function Public Function NewProcessNode(Profile As ProfileData, Process As ProcessData, IsMatch As Boolean) As TreeNode + _Logger.Debug("New Process Node for Profile {0} and ProcessName {1}", Profile.Name, Process.ProcessName) + Dim oMatchText = IIf(IsMatch, "MATCH", "NO MATCH") Dim oText = $"{GetMatchText(IsMatch)} on ProcessName {Process.ProcessName}" - Dim oNode As New TreeNode() With { .Text = oText, .ImageIndex = ProfileFilter.ImageIndex.Process, @@ -61,9 +65,10 @@ Public Class ProfileMatch End Function Public Function NewWindowNode(Profile As ProfileData, Window As WindowData, IsMatch As Boolean) As TreeNode + _Logger.Debug("New Window Node for Profile {0} and WindowTitle {1}", Profile.Name, Window.Title) + Dim oMatchText = IIf(IsMatch, "MATCH", "NO MATCH") Dim oText = $"{GetMatchText(IsMatch)} on WindowTitle {Window.Title}" - Dim oNode As New TreeNode() With { .Text = oText, .ImageIndex = ProfileFilter.ImageIndex.Window, @@ -75,6 +80,8 @@ Public Class ProfileMatch End Function Public Function NewControlNode(Profile As ProfileData, Control As ControlData, IsMatch As Boolean) As TreeNode + _Logger.Debug("New Control Node for Profile {0} and Control {1}", Profile.Name, Control.Description) + Dim oMatchText = IIf(IsMatch, "MATCH", "NO MATCH") Dim oText = $"{GetMatchText(IsMatch)} on Control {Control.Description}: {IsMatch.ToString}"