profile filter

This commit is contained in:
Jonathan Jenne
2019-10-29 10:39:59 +01:00
parent dccc1820f9
commit c173432b94
2 changed files with 62 additions and 33 deletions

View File

@@ -62,6 +62,11 @@ Public Class ProfileFilter
Return _Profiles Return _Profiles
End Function End Function
Public Function LogRemainingProfiles(Profiles As List(Of ProfileData), StepDescription As String) As List(Of ProfileData)
_Logger.Debug("Profiles remaining after Step {0}: {1}", StepDescription, Profiles.Count)
Return Profiles
End Function
Public Function FilterProfilesByClipboardRegex(Profiles As List(Of ProfileData), ClipboardContents As String) As List(Of ProfileData) Public Function FilterProfilesByClipboardRegex(Profiles As List(Of ProfileData), ClipboardContents As String) As List(Of ProfileData)
Dim oFilteredProfiles As New List(Of ProfileData) Dim oFilteredProfiles As New List(Of ProfileData)
@@ -99,37 +104,37 @@ Public Class ProfileFilter
Return oFilteredProfiles Return oFilteredProfiles
End Function End Function
Public Function FilterProfilesByProcess(Profiles As List(Of ProfileData), CurrentProcessName As String) As List(Of ProfileData) Public Function FilterProfilesByProcess(Profiles As List(Of ProfileData), ProcessName As String) As List(Of ProfileData)
Dim oFilteredProfiles As New List(Of ProfileData) Dim oFilteredProfiles As New List(Of ProfileData)
Try Try
For Each oProfile In Profiles For Each oProfile As ProfileData In Profiles
Dim oGuid = oProfile.Guid Dim oGuid = oProfile.Guid
Dim oProcesses As New List(Of ProcessData) Dim oProcesses As New List(Of ProcessData)
For Each oProcessDef As ProcessData In oProfile.Processes For Each oProcess As ProcessData In oProfile.Processes
If oProcessDef.PROFILE_ID <> oGuid Then If oProcess.PROFILE_ID <> oGuid Then
Continue For Continue For
End If End If
Dim oIsMatch = oProcessDef.ProcessName.ToLower = CurrentProcessName.ToLower Dim oIsMatch = oProcess.ProcessName.ToLower = ProcessName.ToLower
Dim oParent = _ProfileMatch.FindNodeByTag(_TreeView.Nodes, oProfile.Name & "-REGEX") Dim oParent = _ProfileMatch.FindNodeByTag(_TreeView.Nodes, oProfile.Name & "-REGEX")
If oParent IsNot Nothing Then If oParent IsNot Nothing Then
Dim oNode = _ProfileMatch.NewProcessNode(oProfile, oProcessDef, oIsMatch) Dim oNode = _ProfileMatch.NewProcessNode(oProfile, oProcess, oIsMatch)
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($"Processname Matched: {oProcessDef.ProcessName}") _Logger.Debug($"Processname Matched: {oProcess.ProcessName}")
oFilteredProfiles.Add(oProfile) oFilteredProfiles.Add(oProfile)
_Logger.Info("Profile {0} matched!", oProfile.Name) _Logger.Info("Profile {0} matched!", oProfile.Name)
oProfile.MatchedProcessID = oProcessDef.Guid oProfile.MatchedProcessID = oProcess.Guid
oProcessDef.IsMatched = True oProcess.IsMatched = True
oProcesses.Add(oProcessDef) oProcesses.Add(oProcess)
oProfile.IsMatched = True oProfile.IsMatched = True
oProfile.MatchedProcessID = oProcessDef.Guid oProfile.MatchedProcessID = oProcess.Guid
End If End If
Next Next
@@ -150,17 +155,29 @@ 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)
Dim oWindows As New List(Of WindowData)
Dim oFilteredWindows As New List(Of WindowData)
' Create list of all controls that match the current process and matched window
For Each oWindow As WindowData In oProfile.Windows
If oWindow.WindowProcessID = oProfile.MatchedProcessID Then
oFilteredWindows.Add(oWindow)
End If
Next
' If Profile has no windows at all, it automatically matches ' If Profile has no windows at all, it automatically matches
If oProfile.Windows.Count = 0 Then If oFilteredWindows.Count = 0 Then
_Logger.Debug("Profile has no Windows assigned, automatic MATCH")
oProfile.IsMatched = True oProfile.IsMatched = True
oProfiles.Add(oProfile) oProfiles.Add(oProfile)
Continue For Continue For
End If End If
For Each oWindowDef As WindowData In oProfile.Windows Dim oWindows As New List(Of WindowData)
For Each oWindowDef As WindowData In oFilteredWindows
If oWindowDef.WindowProcessID <> oProfile.MatchedProcessID Then Continue For If oWindowDef.WindowProcessID <> oProfile.MatchedProcessID Then Continue For
Try Try
If oWindowDef.Regex = String.Empty Then If oWindowDef.Regex = String.Empty Then
@@ -208,30 +225,40 @@ Public Class ProfileFilter
Public Function FilterProfilesByFocusedControl(Profiles As List(Of ProfileData), ClipboardContents As String, WindowHandle As IntPtr) As List(Of ProfileData) Public Function FilterProfilesByFocusedControl(Profiles As List(Of ProfileData), ClipboardContents As String, WindowHandle As IntPtr) As List(Of ProfileData)
Dim oFilteredProfiles As New List(Of ProfileData) Dim oFilteredProfiles As New List(Of ProfileData)
Dim oWindow As New Window(_LogConfig) Dim oWindow As New Window(_LogConfig)
Dim oFocusedWindow As Window.WindowInfo
Try
oFocusedWindow = oWindow.GetWindowInfo()
If oFocusedWindow Is Nothing Then
Throw New ApplicationException("Window Information is Empty")
End If
Catch ex As Exception
_Logger.Error(ex)
Return Profiles
End Try
For Each oProfile As ProfileData In Profiles
Dim oFilteredControls As New List(Of ControlData)
' Create list of all controls that match the current process and matched window
For Each oControl As ControlData In oProfile.Controls
If oProfile.MatchedWindowID = oControl.WindowId And oFocusedWindow.ProcessName = oControl.ProcessName Then
oFilteredControls.Add(oControl)
End If
Next
For Each oProfile In Profiles
' If Profile has no controls at all, it automatically matches ' If Profile has no controls at all, it automatically matches
If oProfile.Controls.Count = 0 Then If oFilteredControls.Count = 0 Then
_Logger.Debug("Profile has no Controls assigned, automatic MATCH")
oFilteredProfiles.Add(oProfile) oFilteredProfiles.Add(oProfile)
Continue For Continue For
End If End If
Dim oControls As New List(Of ControlData) Dim oMatchingControls As New List(Of ControlData)
For Each oControl In oProfile.Controls For Each oControl In oFilteredControls
Dim oFound As Boolean = False Dim oFound As Boolean = False
' If current control does not belong to the current process, skip it
Try
Dim oFocusedWindow As Window.WindowInfo = oWindow.GetWindowInfo()
If oFocusedWindow.ProcessName <> oControl.ProcessName Then
Continue For
End If
Catch ex As Exception
_Logger.Error(ex)
End Try
' If control name is empty, use coordinates ' If control name is empty, use coordinates
If oControl.ControlName Is Nothing OrElse oControl.ControlName = String.Empty Then If oControl.ControlName Is Nothing OrElse oControl.ControlName = String.Empty Then
Dim oControlBounds As Dictionary(Of String, Window.RectangleInfo) Dim oControlBounds As Dictionary(Of String, Window.RectangleInfo)
@@ -279,7 +306,8 @@ Public Class ProfileFilter
End If End If
If oFound Then If oFound Then
oControls.Add(oControl) _Logger.Debug("Control {0} has MATCH", oControl.ControlName)
oMatchingControls.Add(oControl)
End If End If
Dim oParent = _ProfileMatch.FindNodeByTag(_TreeView.Nodes, oControl.WindowId & "-WINDOW") Dim oParent = _ProfileMatch.FindNodeByTag(_TreeView.Nodes, oControl.WindowId & "-WINDOW")
@@ -290,8 +318,9 @@ Public Class ProfileFilter
Next Next
' If Profile has controls that matched, the profile matches ' If Profile has controls that matched, the profile matches
If oControls.Count > 0 Then If oMatchingControls.Count > 0 Then
oProfile.Controls = oControls _Logger.Debug("Profile has {0} MATCHING Controls", oMatchingControls.Count)
oProfile.Controls = oMatchingControls
oFilteredProfiles.Add(oProfile) oFilteredProfiles.Add(oProfile)
_Logger.Info("Profile {0} matched!", oProfile.Name) _Logger.Info("Profile {0} matched!", oProfile.Name)

View File

@@ -83,7 +83,7 @@ Public Class ProfileMatch
_Logger.Debug("New Control Node for Profile {0} and Control {1}", Profile.Name, Control.Description) _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}"
Dim oNode As New TreeNode() With { Dim oNode As New TreeNode() With {
.Text = oText, .Text = oText,