improve logging in profile filter

This commit is contained in:
Jonathan Jenne 2019-10-24 16:34:32 +02:00
parent 8239883b47
commit 660231325c
2 changed files with 40 additions and 17 deletions

View File

@ -84,6 +84,7 @@ Public Class ProfileFilter
Dim oMatch = oRegex.Match(ClipboardContents) Dim oMatch = oRegex.Match(ClipboardContents)
If oMatch.Success Then If oMatch.Success Then
_Logger.Debug("FilterProfilesByClipboardRegex: Clipboard Regex Matched: {0}", ClipboardContents) _Logger.Debug("FilterProfilesByClipboardRegex: Clipboard Regex Matched: {0}", ClipboardContents)
_Logger.Info("Profile {0} matched!", oProfile.Name)
oFilteredProfiles.Add(oProfile) oFilteredProfiles.Add(oProfile)
oProfile.IsMatched = True oProfile.IsMatched = True
@ -104,10 +105,6 @@ Public Class ProfileFilter
For Each oProfile In Profiles For Each oProfile In Profiles
Dim oGuid = oProfile.Guid Dim oGuid = oProfile.Guid
If oProfile.IsMatched = False Then
Continue For
End If
Dim oProcesses As New List(Of ProcessData) Dim oProcesses As New List(Of ProcessData)
For Each oProcessDef As ProcessData In oProfile.Processes For Each oProcessDef As ProcessData In oProfile.Processes
If oProcessDef.PROFILE_ID <> oGuid Then If oProcessDef.PROFILE_ID <> oGuid Then
@ -121,11 +118,13 @@ Public Class ProfileFilter
oParent.Nodes.Add(oNode) oParent.Nodes.Add(oNode)
End If End If
_Logger.Debug($"FilterProfilesByProcess: Checking Profile: {oProfile.Name} ...") _Logger.Debug($"FilterProfilesByProcess: Checking Profile: {oProfile.Name}")
If oIsMatch Then If oIsMatch Then
_Logger.Debug($"Yes...Processname Matched: {oProcessDef.ProcessName}") _Logger.Debug($"Processname Matched: {oProcessDef.ProcessName}")
'TODO: Add Debug Data
oFilteredProfiles.Add(oProfile) oFilteredProfiles.Add(oProfile)
_Logger.Info("Profile {0} matched!", oProfile.Name)
oProfile.MatchedProcessID = oProcessDef.Guid oProfile.MatchedProcessID = oProcessDef.Guid
oProcessDef.IsMatched = True oProcessDef.IsMatched = True
oProcesses.Add(oProcessDef) oProcesses.Add(oProcessDef)
@ -151,9 +150,16 @@ Public Class ProfileFilter
For Each oProfile As ProfileData In Profiles For Each oProfile As ProfileData In Profiles
_Logger.Debug("Checking WindowDefinition for profile: {0}...", oProfile.Name) _Logger.Debug("Checking WindowDefinition for profile: {0}...", oProfile.Name)
If oProfile.IsMatched = False Then Continue For
Dim oWindows As New List(Of WindowData) 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 For Each oWindowDef As WindowData In oProfile.Windows
If oWindowDef.WindowProcessID <> oProfile.MatchedProcessID Then Continue For If oWindowDef.WindowProcessID <> oProfile.MatchedProcessID Then Continue For
Try Try
@ -186,10 +192,13 @@ Public Class ProfileFilter
End Try End Try
Next Next
' If Profile has windows that matched, the profile matches
If oWindows.Count > 0 Then If oWindows.Count > 0 Then
oProfile.Windows = oWindows oProfile.Windows = oWindows
oProfile.IsMatched = True oProfile.IsMatched = True
oProfiles.Add(oProfile) oProfiles.Add(oProfile)
_Logger.Info("Profile {0} matched!", oProfile.Name)
End If End If
Next Next
@ -201,8 +210,7 @@ Public Class ProfileFilter
Dim oWindow As New Window(_LogConfig) Dim oWindow As New Window(_LogConfig)
For Each oProfile In Profiles 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 If oProfile.Controls.Count = 0 Then
oFilteredProfiles.Add(oProfile) oFilteredProfiles.Add(oProfile)
Continue For Continue For
@ -246,13 +254,15 @@ Public Class ProfileFilter
End If End If
Next Next
' If Profile has controls that matched, the profile matches
If oControls.Count > 0 Then If oControls.Count > 0 Then
oProfile.Controls = oControls oProfile.Controls = oControls
oFilteredProfiles.Add(oProfile) oFilteredProfiles.Add(oProfile)
_Logger.Info("Profile {0} matched!", oProfile.Name)
End If End If
Next Next
Return oFilteredProfiles Return oFilteredProfiles
End Function End Function
@ -320,10 +330,14 @@ Public Class ProfileFilter
End Try End Try
Next Next
If oResultData > 0 Or oResultDocs > 0 Then oProfile.CountData = oResultData
oProfile.CountData = oResultData oProfile.CountDocs = oResultDocs
oProfile.CountDocs = oResultDocs Next
For Each oProfile In Profiles
If oProfile.CountData > 0 Or oProfile.CountDocs > 0 Then
oProfiles.Add(oProfile) oProfiles.Add(oProfile)
_Logger.Info("Profile {0} matched!", oProfile.Name)
End If End If
Next Next
@ -368,6 +382,8 @@ Public Class ProfileFilter
If oWindows.Count > 0 Then If oWindows.Count > 0 Then
oProfile.Windows = oWindows oProfile.Windows = oWindows
oProfiles.Add(oProfile) oProfiles.Add(oProfile)
_Logger.Info("Profile {0} matched!", oProfile.Name)
End If End If
Next Next

View File

@ -25,6 +25,8 @@ Public Class ProfileMatch
End Function End Function
Public Function NewProfileNode(Profile As ProfileData) As TreeNode Public Function NewProfileNode(Profile As ProfileData) As TreeNode
_Logger.Debug("New Profile Node for Profile {0}", Profile.Name)
Dim oNode As New TreeNode() With { Dim oNode As New TreeNode() With {
.Text = $"Profile: {Profile.Name}", .Text = $"Profile: {Profile.Name}",
.ImageIndex = ProfileFilter.ImageIndex.Profile, .ImageIndex = ProfileFilter.ImageIndex.Profile,
@ -35,8 +37,9 @@ Public Class ProfileMatch
End Function End Function
Public Function NewClipboardRegexNode(Profile As ProfileData, IsMatch As Boolean) As TreeNode 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 { Dim oNode As New TreeNode() With {
.Text = oText, .Text = oText,
.ImageIndex = ProfileFilter.ImageIndex.Clipboard, .ImageIndex = ProfileFilter.ImageIndex.Clipboard,
@ -47,9 +50,10 @@ Public Class ProfileMatch
Return oNode Return oNode
End Function End Function
Public Function NewProcessNode(Profile As ProfileData, Process As ProcessData, IsMatch As Boolean) As TreeNode 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 oMatchText = IIf(IsMatch, "MATCH", "NO MATCH")
Dim oText = $"{GetMatchText(IsMatch)} on ProcessName {Process.ProcessName}" Dim oText = $"{GetMatchText(IsMatch)} on ProcessName {Process.ProcessName}"
Dim oNode As New TreeNode() With { Dim oNode As New TreeNode() With {
.Text = oText, .Text = oText,
.ImageIndex = ProfileFilter.ImageIndex.Process, .ImageIndex = ProfileFilter.ImageIndex.Process,
@ -61,9 +65,10 @@ Public Class ProfileMatch
End Function End Function
Public Function NewWindowNode(Profile As ProfileData, Window As WindowData, IsMatch As Boolean) As TreeNode 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 oMatchText = IIf(IsMatch, "MATCH", "NO MATCH")
Dim oText = $"{GetMatchText(IsMatch)} on WindowTitle {Window.Title}" Dim oText = $"{GetMatchText(IsMatch)} on WindowTitle {Window.Title}"
Dim oNode As New TreeNode() With { Dim oNode As New TreeNode() With {
.Text = oText, .Text = oText,
.ImageIndex = ProfileFilter.ImageIndex.Window, .ImageIndex = ProfileFilter.ImageIndex.Window,
@ -75,6 +80,8 @@ Public Class ProfileMatch
End Function End Function
Public Function NewControlNode(Profile As ProfileData, Control As ControlData, IsMatch As Boolean) As TreeNode 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 oMatchText = IIf(IsMatch, "MATCH", "NO MATCH")
Dim oText = $"{GetMatchText(IsMatch)} on Control {Control.Description}: {IsMatch.ToString}" Dim oText = $"{GetMatchText(IsMatch)} on Control {Control.Description}: {IsMatch.ToString}"