improve profile match debugging
This commit is contained in:
parent
d55d77a426
commit
ca4683a05e
@ -241,7 +241,7 @@ Public Class ClassInit
|
|||||||
If DT_USER_PROFILES Is Nothing OrElse 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)
|
MsgBox("No profiles configured for this user so far!", MsgBoxStyle.Exclamation)
|
||||||
Else
|
Else
|
||||||
oSql = $"SELECT T.* FROM TBCW_PROFILE_PROCESS T, VWCW_USER_PROFILE T1 WHERE T.PROFILE_ID = T1.GUID AND T1.USER_ID = {USER_ID}"
|
oSql = $"SELECT DISTINCT T.GUID, T.PROFILE_ID,T.PROC_NAME FROM TBCW_PROFILE_PROCESS T, VWCW_USER_PROFILE T1 WHERE T.PROFILE_ID = T1.GUID AND T1.USER_ID = {USER_ID}"
|
||||||
DTPROFILE_REL_PROCESS = Database.GetDatatable(oSql)
|
DTPROFILE_REL_PROCESS = Database.GetDatatable(oSql)
|
||||||
|
|
||||||
oSql = $"SELECT * FROM VWCW_PROFILE_REL_WINDOW WHERE USER_ID = {USER_ID}"
|
oSql = $"SELECT * FROM VWCW_PROFILE_REL_WINDOW WHERE USER_ID = {USER_ID}"
|
||||||
|
|||||||
@ -1,7 +1,5 @@
|
|||||||
Imports System.Text.RegularExpressions
|
Imports System.Text.RegularExpressions
|
||||||
Imports DD_Clipboard_Watcher.ClassWindowAPI
|
|
||||||
Imports DigitalData.Modules.Language.Utils
|
Imports DigitalData.Modules.Language.Utils
|
||||||
Imports System.Windows.Automation
|
|
||||||
Imports DigitalData.Modules.Windows
|
Imports DigitalData.Modules.Windows
|
||||||
|
|
||||||
Public Class ClassProfileFilter
|
Public Class ClassProfileFilter
|
||||||
@ -10,7 +8,7 @@ Public Class ClassProfileFilter
|
|||||||
Private _WindowTable As DataTable
|
Private _WindowTable As DataTable
|
||||||
Private _ControlTable As DataTable
|
Private _ControlTable As DataTable
|
||||||
Private _Profiles As List(Of ProfileData)
|
Private _Profiles As List(Of ProfileData)
|
||||||
Private _DebugData As DebugData
|
Private _TreeView As TreeView
|
||||||
|
|
||||||
Class ProfileData
|
Class ProfileData
|
||||||
Public Guid As Integer
|
Public Guid As Integer
|
||||||
@ -31,12 +29,27 @@ Public Class ClassProfileFilter
|
|||||||
Public MatchedControlID As Integer = 0
|
Public MatchedControlID As Integer = 0
|
||||||
Public SelectCommand As String
|
Public SelectCommand As String
|
||||||
|
|
||||||
|
Public Overrides Function Equals(obj As Object) As Boolean
|
||||||
|
Return Guid = DirectCast(obj, ProfileData).Guid
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Overrides Function GetHashCode() As Integer
|
||||||
|
Return Guid.ToString.GetHashCode()
|
||||||
|
End Function
|
||||||
End Class
|
End Class
|
||||||
Class ProcessData
|
Class ProcessData
|
||||||
Public Guid As Integer
|
Public Guid As Integer
|
||||||
Public PROFILE_ID As Integer
|
Public PROFILE_ID As Integer
|
||||||
Public ProcessName As String
|
Public ProcessName As String
|
||||||
Public IsMatched As Boolean = False
|
Public IsMatched As Boolean = False
|
||||||
|
|
||||||
|
Public Overrides Function Equals(obj As Object) As Boolean
|
||||||
|
Return Guid = DirectCast(obj, ProcessData).Guid
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Public Overrides Function GetHashCode() As Integer
|
||||||
|
Return Guid.ToString.GetHashCode()
|
||||||
|
End Function
|
||||||
End Class
|
End Class
|
||||||
Class WindowData
|
Class WindowData
|
||||||
Public Guid As Integer
|
Public Guid As Integer
|
||||||
@ -47,7 +60,6 @@ Public Class ClassProfileFilter
|
|||||||
Public IsMatched As Boolean = False
|
Public IsMatched As Boolean = False
|
||||||
|
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
Class ControlData
|
Class ControlData
|
||||||
Public Guid As Integer
|
Public Guid As Integer
|
||||||
Public WindowId As Integer
|
Public WindowId As Integer
|
||||||
@ -61,36 +73,26 @@ Public Class ClassProfileFilter
|
|||||||
Public BottomLeft As ControlBounds
|
Public BottomLeft As ControlBounds
|
||||||
Public BottomRight As ControlBounds
|
Public BottomRight As ControlBounds
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
Class ControlBounds
|
Class ControlBounds
|
||||||
Public Top As Integer
|
Public Top As Integer
|
||||||
Public Bottom As Integer
|
Public Bottom As Integer
|
||||||
Public Left As Integer
|
Public Left As Integer
|
||||||
Public Right As Integer
|
Public Right As Integer
|
||||||
End Class
|
End Class
|
||||||
|
|
||||||
' TODO: Fill this Class!!!! :D
|
|
||||||
Class DebugData
|
|
||||||
Public ProcessMatch As List(Of String)
|
|
||||||
Public ClipboardMatch As List(Of String)
|
|
||||||
Public WindowMatch As List(Of String)
|
|
||||||
Public WindowRegexMatch As List(Of String)
|
|
||||||
End Class
|
|
||||||
|
|
||||||
Public ReadOnly Property Profiles As List(Of ProfileData)
|
Public ReadOnly Property Profiles As List(Of ProfileData)
|
||||||
Get
|
Get
|
||||||
Return _Profiles
|
Return _Profiles
|
||||||
End Get
|
End Get
|
||||||
End Property
|
End Property
|
||||||
|
|
||||||
Public Sub New(ProfileDatatable As DataTable, ProcessTable As DataTable, WindowDatatable As DataTable, ControlDatatable As DataTable)
|
Public Sub New(ProfileDatatable As DataTable, ProcessTable As DataTable, WindowDatatable As DataTable, ControlDatatable As DataTable, TreeView As TreeView)
|
||||||
Try
|
Try
|
||||||
_DebugData = New DebugData()
|
|
||||||
_ProfileTable = ProfileDatatable
|
_ProfileTable = ProfileDatatable
|
||||||
_ProcessTable = ProcessTable
|
_ProcessTable = ProcessTable
|
||||||
_WindowTable = WindowDatatable
|
_WindowTable = WindowDatatable
|
||||||
_ControlTable = ControlDatatable
|
_ControlTable = ControlDatatable
|
||||||
_Profiles = TransformProfiles()
|
_Profiles = TransformProfiles()
|
||||||
|
_TreeView = TreeView
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
Throw ex
|
Throw ex
|
||||||
@ -109,50 +111,117 @@ Public Class ClassProfileFilter
|
|||||||
End If
|
End If
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Private Function Node_Get_Lowest_Node(NodeTag As String) As TreeNode
|
Private Function FindNodeByTag(ByVal nodes As TreeNodeCollection, ByVal Tag As String) As TreeNode
|
||||||
Dim oExit = False
|
For Each node As TreeNode In nodes
|
||||||
Dim oParentNode As TreeNode
|
If (node.Tag.Equals(Tag)) Then
|
||||||
For Each oTreeNode As TreeNode In CurrMatchTreeView.Nodes
|
Return node
|
||||||
For Each oNodes As TreeNode In oTreeNode.Nodes
|
End If
|
||||||
If oExit = True Then Exit For
|
|
||||||
If oNodes.Tag = NodeTag Then
|
Dim oNext As TreeNode = FindNodeByTag(node.Nodes, Tag)
|
||||||
oParentNode = oNodes
|
If oNext IsNot Nothing Then
|
||||||
oExit = True
|
Return oNext
|
||||||
Exit For
|
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
Next
|
Return Nothing
|
||||||
Dim olowestNode As TreeNode = GetLowestNode(oParentNode)
|
End Function
|
||||||
|
|
||||||
Return olowestNode
|
Private Function GetMatchText(IsMatch As Boolean)
|
||||||
|
Return IIf(IsMatch, "MATCH", "NO MATCH")
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function GetMatchColor(IsMatch As Boolean)
|
||||||
|
Return IIf(IsMatch, Color.LightGreen, Color.LightCoral)
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function NewProfileNode(Profile As ProfileData) As TreeNode
|
||||||
|
Dim oNode As New TreeNode() With {
|
||||||
|
.Text = $"Profile: {Profile.Name}",
|
||||||
|
.ImageIndex = 0,
|
||||||
|
.Tag = Profile.Name & "-PROFILE"
|
||||||
|
}
|
||||||
|
|
||||||
|
Return oNode
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function NewClipboardRegexNode(Profile As ProfileData, IsMatch As Boolean) As TreeNode
|
||||||
|
Dim oText = $"{GetMatchText(IsMatch)} on Global Clipboard Regex {Profile.Regex}: {IsMatch.ToString}"
|
||||||
|
|
||||||
|
Dim oNode As New TreeNode() With {
|
||||||
|
.Text = oText,
|
||||||
|
.ImageIndex = 1,
|
||||||
|
.Tag = Profile.Name & "-REGEX",
|
||||||
|
.BackColor = GetMatchColor(IsMatch)
|
||||||
|
}
|
||||||
|
|
||||||
|
Return oNode
|
||||||
|
End Function
|
||||||
|
Private Function NewProcessNode(Profile As ProfileData, Process As ProcessData, IsMatch As Boolean) As TreeNode
|
||||||
|
Dim oMatchText = IIf(IsMatch, "MATCH", "NO MATCH")
|
||||||
|
Dim oText = $"{GetMatchText(IsMatch)} on ProcessName {Process.ProcessName}: {IsMatch.ToString}"
|
||||||
|
|
||||||
|
Dim oNode As New TreeNode() With {
|
||||||
|
.Text = oText,
|
||||||
|
.ImageIndex = 4,
|
||||||
|
.Tag = Process.Guid & "-PROCESS",
|
||||||
|
.BackColor = GetMatchColor(IsMatch)
|
||||||
|
}
|
||||||
|
|
||||||
|
Return oNode
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function NewWindowNode(Profile As ProfileData, Window As WindowData, IsMatch As Boolean) As TreeNode
|
||||||
|
Dim oMatchText = IIf(IsMatch, "MATCH", "NO MATCH")
|
||||||
|
Dim oText = $"{GetMatchText(IsMatch)} on WindowTitle {Window.Title}: {IsMatch.ToString}"
|
||||||
|
|
||||||
|
Dim oNode As New TreeNode() With {
|
||||||
|
.Text = oText,
|
||||||
|
.ImageIndex = 3,
|
||||||
|
.Tag = Window.Guid & "-WINDOW",
|
||||||
|
.BackColor = GetMatchColor(IsMatch)
|
||||||
|
}
|
||||||
|
|
||||||
|
Return oNode
|
||||||
|
End Function
|
||||||
|
|
||||||
|
Private Function NewControlNode(Profile As ProfileData, Control As ControlData, IsMatch As Boolean) As TreeNode
|
||||||
|
Dim oMatchText = IIf(IsMatch, "MATCH", "NO MATCH")
|
||||||
|
Dim oText = $"{GetMatchText(IsMatch)} on Control {Control.Description}: {IsMatch.ToString}"
|
||||||
|
|
||||||
|
Dim oNode As New TreeNode() With {
|
||||||
|
.Text = oText,
|
||||||
|
.ImageIndex = 2,
|
||||||
|
.Tag = Control.Guid & "-CONTROL",
|
||||||
|
.BackColor = GetMatchColor(IsMatch)
|
||||||
|
}
|
||||||
|
|
||||||
|
Return oNode
|
||||||
End Function
|
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)
|
||||||
|
|
||||||
|
Dim oRootNode As TreeNode = New TreeNode() With {
|
||||||
|
.Text = $"Suche nach '{ClipboardContents}'",
|
||||||
|
.Tag = "ROOT"
|
||||||
|
}
|
||||||
|
_TreeView.Nodes.Add(oRootNode)
|
||||||
|
|
||||||
For Each oProfile In Profiles
|
For Each oProfile In Profiles
|
||||||
Logger.Debug("Current Profile: {0}", oProfile.Name)
|
Logger.Debug("Current Profile: {0}", oProfile.Name)
|
||||||
|
|
||||||
Dim oNode As New TreeNode() With {
|
Dim oNode = NewProfileNode(oProfile)
|
||||||
.Text = $"Profile: {oProfile.Name}",
|
oRootNode.Nodes.Add(oNode)
|
||||||
.ImageIndex = 0,
|
|
||||||
.Tag = oProfile.Name & "-PROFILE"
|
|
||||||
}
|
|
||||||
CurrMatchTreeView.Nodes.Add(oNode)
|
|
||||||
|
|
||||||
Try
|
Try
|
||||||
Dim oRegex As New Regex(oProfile.Regex)
|
Dim oRegex As New Regex(oProfile.Regex)
|
||||||
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)
|
||||||
'TODO: Add Debug Data
|
|
||||||
oFilteredProfiles.Add(oProfile)
|
oFilteredProfiles.Add(oProfile)
|
||||||
oProfile.IsMatched = True
|
oProfile.IsMatched = True
|
||||||
|
|
||||||
Dim oSubnode As New TreeNode($"MATCH on Global Clipboard Regex: {oProfile.Regex}")
|
Dim oSubnode = NewClipboardRegexNode(oProfile, oMatch.Success)
|
||||||
oSubnode.ImageIndex = 1
|
|
||||||
oSubnode.Tag = oProfile.Name & "-REGEX"
|
|
||||||
oNode.Nodes.Add(oSubnode)
|
oNode.Nodes.Add(oSubnode)
|
||||||
|
|
||||||
End If
|
End If
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", oProfile.Regex, ClipboardContents)
|
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", oProfile.Regex, ClipboardContents)
|
||||||
@ -172,14 +241,21 @@ Public Class ClassProfileFilter
|
|||||||
Continue For
|
Continue For
|
||||||
End If
|
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
|
||||||
Continue For
|
Continue For
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
Dim oIsMatch = oProcessDef.ProcessName.ToLower = CurrentProcessName.ToLower
|
||||||
|
Dim oParent = FindNodeByTag(_TreeView.Nodes, oProfile.Name & "-REGEX")
|
||||||
|
If oParent IsNot Nothing Then
|
||||||
|
Dim oNode = NewProcessNode(oProfile, oProcessDef, oIsMatch)
|
||||||
|
oParent.Nodes.Add(oNode)
|
||||||
|
End If
|
||||||
|
|
||||||
Logger.Debug($"FilterProfilesByProcess: Checking Profile: {oProfile.Name} ...")
|
Logger.Debug($"FilterProfilesByProcess: Checking Profile: {oProfile.Name} ...")
|
||||||
If oProcessDef.ProcessName.ToLower = CurrentProcessName.ToLower Then
|
If oIsMatch Then
|
||||||
Logger.Debug($"Yes...Processname Matched: {oProcessDef.ProcessName}")
|
Logger.Debug($"Yes...Processname Matched: {oProcessDef.ProcessName}")
|
||||||
'oProfile.MATCH_PROCESSNAME = $"Processname Matched: {oProfile.ProcessName}"
|
'oProfile.MATCH_PROCESSNAME = $"Processname Matched: {oProfile.ProcessName}"
|
||||||
'TODO: Add Debug Data
|
'TODO: Add Debug Data
|
||||||
@ -189,25 +265,7 @@ Public Class ClassProfileFilter
|
|||||||
oProcesses.Add(oProcessDef)
|
oProcesses.Add(oProcessDef)
|
||||||
oProfile.IsMatched = True
|
oProfile.IsMatched = True
|
||||||
oProfile.MatchedProcessID = oProcessDef.Guid
|
oProfile.MatchedProcessID = oProcessDef.Guid
|
||||||
Dim oParentNode As TreeNode
|
|
||||||
Dim oExit = False
|
|
||||||
For Each oTreeNode As TreeNode In CurrMatchTreeView.Nodes
|
|
||||||
For Each oNodes As TreeNode In oTreeNode.Nodes
|
|
||||||
If oExit = True Then Exit For
|
|
||||||
If oNodes.Tag = oProfile.Name & "-REGEX" Then
|
|
||||||
oParentNode = oNodes
|
|
||||||
oExit = True
|
|
||||||
Exit For
|
|
||||||
End If
|
|
||||||
Next
|
|
||||||
Next
|
|
||||||
|
|
||||||
If Not IsNothing(oParentNode) Then
|
|
||||||
Dim oNode As New TreeNode($"MATCH on Process: {oProcessDef.ProcessName}")
|
|
||||||
oNode.ImageIndex = 4
|
|
||||||
oNode.Tag = oProfile.Name & "-PROCESS"
|
|
||||||
oParentNode.Nodes.Add(oNode)
|
|
||||||
End If
|
|
||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
If oFilteredProfiles.Count > 0 Then
|
If oFilteredProfiles.Count > 0 Then
|
||||||
@ -245,19 +303,17 @@ Public Class ClassProfileFilter
|
|||||||
|
|
||||||
If oMatch.Success Then
|
If oMatch.Success Then
|
||||||
Logger.Debug("MATCH on WindowTitle: {0}", WindowTitle)
|
Logger.Debug("MATCH on WindowTitle: {0}", WindowTitle)
|
||||||
'TODO: Add Debug Data
|
|
||||||
oProfile.MatchedWindowID = oWindowDef.Guid
|
oProfile.MatchedWindowID = oWindowDef.Guid
|
||||||
oWindowDef.IsMatched = True
|
oWindowDef.IsMatched = True
|
||||||
oWindows.Add(oWindowDef)
|
oWindows.Add(oWindowDef)
|
||||||
Dim olowestNode As TreeNode = Node_Get_Lowest_Node(oProfile.Name & "-REGEX")
|
|
||||||
If Not IsNothing(olowestNode) Then
|
|
||||||
Dim oNode As New TreeNode($"MATCH on WindowTitle: [{WindowTitle}]")
|
|
||||||
oNode.ImageIndex = 3
|
|
||||||
oNode.Tag = oProfile.Name & "-WINDOW"
|
|
||||||
olowestNode.Nodes.Add(oNode)
|
|
||||||
End If
|
End If
|
||||||
Exit For
|
|
||||||
|
Dim oParent = FindNodeByTag(_TreeView.Nodes, oWindowDef.WindowProcessID & "-PROCESS")
|
||||||
|
If oParent IsNot Nothing Then
|
||||||
|
Dim oNode = NewWindowNode(oProfile, oWindowDef, oMatch.Success)
|
||||||
|
oParent.Nodes.Add(oNode)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", oWindowDef.Regex, WindowTitle)
|
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", oWindowDef.Regex, WindowTitle)
|
||||||
Logger.Error(ex)
|
Logger.Error(ex)
|
||||||
@ -290,27 +346,38 @@ Public Class ClassProfileFilter
|
|||||||
|
|
||||||
For Each oControl In oProfile.Controls
|
For Each oControl In oProfile.Controls
|
||||||
Dim oControlBounds = oWindow.GetFocusedControlLocation(WindowHandle)
|
Dim oControlBounds = oWindow.GetFocusedControlLocation(WindowHandle)
|
||||||
|
Dim oFound As Boolean = False
|
||||||
|
|
||||||
For Each oItem As KeyValuePair(Of String, Window.RectangleInfo) In oControlBounds
|
For Each oItem As KeyValuePair(Of String, Window.RectangleInfo) In oControlBounds
|
||||||
Select Case oItem.Key
|
Select Case oItem.Key
|
||||||
Case "TOPLEFT"
|
Case "TOPLEFT"
|
||||||
If oControl.TopLeft.Top = oItem.Value.Top And oControl.TopLeft.Left = oItem.Value.Left Then
|
If oControl.TopLeft.Top = oItem.Value.Top And oControl.TopLeft.Left = oItem.Value.Left Then
|
||||||
oFilteredProfiles.Add(oProfile)
|
oFound = True
|
||||||
End If
|
End If
|
||||||
Case "TOPRIGHT"
|
Case "TOPRIGHT"
|
||||||
If oControl.TopRight.Top = oItem.Value.Top And oControl.TopLeft.Right = oItem.Value.Right Then
|
If oControl.TopRight.Top = oItem.Value.Top And oControl.TopLeft.Right = oItem.Value.Right Then
|
||||||
oFilteredProfiles.Add(oProfile)
|
oFound = True
|
||||||
End If
|
End If
|
||||||
Case "BOTTOMLEFT"
|
Case "BOTTOMLEFT"
|
||||||
If oControl.BottomLeft.Bottom = oItem.Value.Bottom And oControl.TopLeft.Left = oItem.Value.Left Then
|
If oControl.BottomLeft.Bottom = oItem.Value.Bottom And oControl.TopLeft.Left = oItem.Value.Left Then
|
||||||
oFilteredProfiles.Add(oProfile)
|
oFound = True
|
||||||
End If
|
End If
|
||||||
Case "BOTTOMRIGHT"
|
Case "BOTTOMRIGHT"
|
||||||
If oControl.BottomRight.Bottom = oItem.Value.Bottom And oControl.TopLeft.Right = oItem.Value.Right Then
|
If oControl.BottomRight.Bottom = oItem.Value.Bottom And oControl.TopLeft.Right = oItem.Value.Right Then
|
||||||
oFilteredProfiles.Add(oProfile)
|
oFound = True
|
||||||
End If
|
End If
|
||||||
End Select
|
End Select
|
||||||
Next
|
Next
|
||||||
|
|
||||||
|
If oFound Then
|
||||||
|
oFilteredProfiles.Add(oProfile)
|
||||||
|
End If
|
||||||
|
|
||||||
|
Dim oParent = FindNodeByTag(_TreeView.Nodes, oControl.WindowId & "-WINDOW")
|
||||||
|
If oParent IsNot Nothing Then
|
||||||
|
Dim oNode = NewControlNode(oProfile, oControl, oFound)
|
||||||
|
oParent.Nodes.Add(oNode)
|
||||||
|
End If
|
||||||
Next
|
Next
|
||||||
|
|
||||||
If oControls.Count > 0 Then
|
If oControls.Count > 0 Then
|
||||||
@ -342,24 +409,15 @@ Public Class ClassProfileFilter
|
|||||||
|
|
||||||
If oMatch.Success Then
|
If oMatch.Success Then
|
||||||
Logger.Debug("Window Clipboard Regex Matched: {0}", ClipboardContents)
|
Logger.Debug("Window Clipboard Regex Matched: {0}", ClipboardContents)
|
||||||
Dim oResult As TreeNode
|
oWindows.Add(w)
|
||||||
For Each oTreeNode In CurrMatchTreeView.Nodes
|
|
||||||
If Not IsNothing(oResult) Then Exit For
|
|
||||||
If oTreeNode.Tag = oProfile.Name & "-REGEX" Then
|
|
||||||
oResult = oTreeNode
|
|
||||||
End If
|
End If
|
||||||
Next
|
|
||||||
|
Dim oResult As TreeNode = FindNodeByTag(_TreeView.Nodes, oProfile.Name & "-REGEX")
|
||||||
If Not IsNothing(oResult) Then
|
If Not IsNothing(oResult) Then
|
||||||
Dim oNode As New TreeNode($"MATCH on WINDOW Clipboard Regex: [{w.Regex}]")
|
Dim oNode As New TreeNode($"MATCH on WINDOW Clipboard Regex [{w.Regex}]: {oMatch.Success}")
|
||||||
oNode.ImageIndex = 2
|
oNode.ImageIndex = 2
|
||||||
oNode.Tag = oProfile.Name & "-WINDOW_REGEX"
|
oNode.Tag = oProfile.Name & "-WINDOW_REGEX"
|
||||||
Dim olowestNode As TreeNode = GetLowestNode(oResult)
|
oResult.Nodes.Add(oNode)
|
||||||
olowestNode.Nodes.Add(oNode)
|
|
||||||
End If
|
|
||||||
|
|
||||||
oWindows.Add(w)
|
|
||||||
|
|
||||||
|
|
||||||
End If
|
End If
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", w.Regex, ClipboardContents)
|
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", w.Regex, ClipboardContents)
|
||||||
@ -376,147 +434,6 @@ Public Class ClassProfileFilter
|
|||||||
Return oProfiles
|
Return oProfiles
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
Public Function FilterProfilesByFocusedControl(Profiles As List(Of ProfileData), ClipboardContents As String, ControlFocusresult As String) As List(Of ProfileData)
|
|
||||||
Dim oWindow As WindowInfo
|
|
||||||
Dim oFocusedControl As WindowInfo
|
|
||||||
Dim oFocusedControlName As String = String.Empty
|
|
||||||
|
|
||||||
Try
|
|
||||||
oWindow = GetWindowInfo()
|
|
||||||
oFocusedControl = GetFocusedControl(oWindow.hWnd)
|
|
||||||
|
|
||||||
If oFocusedControl Is Nothing Then
|
|
||||||
Logger.Info("Could not get FocusedControl in Window (Old method) {0}", oWindow.WindowTitle)
|
|
||||||
oFocusedControlName = String.Empty
|
|
||||||
Else
|
|
||||||
oFocusedControlName = oFocusedControl.ControlName
|
|
||||||
End If
|
|
||||||
Catch ex As Exception
|
|
||||||
Logger.Warn("Error while getting Focused control (Old method)")
|
|
||||||
Logger.Error(ex)
|
|
||||||
oFocusedControlName = String.Empty
|
|
||||||
End Try
|
|
||||||
|
|
||||||
Dim oFilteredProfiles As New List(Of ProfileData)
|
|
||||||
|
|
||||||
For Each oProfileMatchedSofar In Profiles
|
|
||||||
If oProfileMatchedSofar.IsMatched = False Then Continue For
|
|
||||||
|
|
||||||
Logger.Debug("Checking ControlDefinition on profile: {0}", oProfileMatchedSofar.Name)
|
|
||||||
Logger.Debug("Profile has {0} configured controls", oProfileMatchedSofar.Controls.Count)
|
|
||||||
|
|
||||||
Dim oControlsForMatchedWindow As New List(Of ControlData)
|
|
||||||
|
|
||||||
For Each oControl In oProfileMatchedSofar.Controls
|
|
||||||
If oControl.WindowId = oProfileMatchedSofar.MatchedWindowID Then
|
|
||||||
oControlsForMatchedWindow.Add(oControl)
|
|
||||||
End If
|
|
||||||
Next
|
|
||||||
|
|
||||||
If oControlsForMatchedWindow.Count = 0 Then
|
|
||||||
Logger.Debug("Profile has no configured controls. Skipping.")
|
|
||||||
oFilteredProfiles.Add(oProfileMatchedSofar)
|
|
||||||
|
|
||||||
Dim oNode As New TreeNode($"No Controls configured!") With {
|
|
||||||
.ImageIndex = 2,
|
|
||||||
.ForeColor = Color.Blue,
|
|
||||||
.Tag = oProfileMatchedSofar.Name & "-NOCONTROLCONFIG",
|
|
||||||
.NodeFont = New Font("Tahoma", 10, FontStyle.Bold)
|
|
||||||
}
|
|
||||||
|
|
||||||
CurrMatchTreeView.Nodes.Add(oNode)
|
|
||||||
|
|
||||||
Continue For
|
|
||||||
End If
|
|
||||||
|
|
||||||
Dim oControls As New List(Of ControlData)
|
|
||||||
|
|
||||||
For Each oControlDefinition In oControlsForMatchedWindow
|
|
||||||
Try
|
|
||||||
If oControlDefinition.WindowId <> oProfileMatchedSofar.MatchedWindowID Then
|
|
||||||
Logger.Debug("Current WindowId {0} does not match Control WindowId {1}. Skipping.", oProfileMatchedSofar.MatchedWindowID, oControlDefinition.WindowId)
|
|
||||||
Continue For
|
|
||||||
End If
|
|
||||||
|
|
||||||
Logger.Debug($"Working on ControlDefinition: {oControlDefinition.Guid}-{oControlDefinition.ControlName}...")
|
|
||||||
If oControlDefinition.Regex = String.Empty Then
|
|
||||||
oProfileMatchedSofar.MatchedControlID = oControlDefinition.Guid
|
|
||||||
oControlDefinition.IsMatched = True
|
|
||||||
oControls.Add(oControlDefinition)
|
|
||||||
Exit For
|
|
||||||
End If
|
|
||||||
'Dim oResult As TreeNode
|
|
||||||
'For Each oTreeNode In CurrMatchTreeView.Nodes
|
|
||||||
' oResult = NodeFind(oTreeNode, $"Global Clipboard Regex Matched [{oProfile.Regex}]")
|
|
||||||
'Next
|
|
||||||
'Dim oNode As TreeNode
|
|
||||||
Dim oNodeCaption As String
|
|
||||||
'Dim oAddNode As Boolean = False
|
|
||||||
Dim oRegex As New Regex(oControlDefinition.Regex)
|
|
||||||
|
|
||||||
Dim oFocusedControlResult As String = ""
|
|
||||||
|
|
||||||
If oControlDefinition.AutomationId <> String.Empty And oControlDefinition.ControlName = String.Empty Then
|
|
||||||
Logger.Debug($"AutomationID should be used...")
|
|
||||||
If Not IsNothing(ControlFocusresult) Then
|
|
||||||
If ControlFocusresult <> String.Empty Then
|
|
||||||
Logger.Debug($"AutomationID will be used...")
|
|
||||||
oFocusedControlResult = ControlFocusresult
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
ElseIf oControlDefinition.AutomationId = String.Empty And oControlDefinition.ControlName <> String.Empty Then
|
|
||||||
Logger.Debug($"ControlName should be used...")
|
|
||||||
If Not IsNothing(oFocusedControlName) Then
|
|
||||||
If oFocusedControlName <> String.Empty Then
|
|
||||||
Logger.Debug($"ControlName will be used...")
|
|
||||||
oFocusedControlResult = oFocusedControlName
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
|
|
||||||
End If
|
|
||||||
If oFocusedControlResult <> String.Empty Then
|
|
||||||
Dim oControlRegex As New Regex(oControlDefinition.Regex)
|
|
||||||
Dim oControlMatch = oRegex.Match(oFocusedControlResult)
|
|
||||||
|
|
||||||
If oControlMatch.Success Then
|
|
||||||
Logger.Debug($"MATCH on Focused Control [{oFocusedControlResult}] with Regex [{oControlDefinition.Regex}]")
|
|
||||||
oProfileMatchedSofar.IsMatched = True
|
|
||||||
oProfileMatchedSofar.MatchedControlID = oControlDefinition.Guid
|
|
||||||
oControlDefinition.IsMatched = True
|
|
||||||
oControls.Add(oControlDefinition)
|
|
||||||
Dim olowestNode As TreeNode = Node_Get_Lowest_Node(oProfileMatchedSofar.Name & "-REGEX")
|
|
||||||
If Not IsNothing(olowestNode) Then
|
|
||||||
Dim oNode As New TreeNode($"MATCH on Focused Control [{oFocusedControlResult}] with Regex [{oControlDefinition.Regex}]")
|
|
||||||
oNode.ImageIndex = 2
|
|
||||||
oNode.Tag = oProfileMatchedSofar.Name & "-CONTROL"
|
|
||||||
olowestNode.Nodes.Add(oNode)
|
|
||||||
End If
|
|
||||||
Exit For
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
Catch ex As Exception
|
|
||||||
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", oControlDefinition.Regex, oFocusedControlName)
|
|
||||||
Logger.Error(ex)
|
|
||||||
End Try
|
|
||||||
Next
|
|
||||||
|
|
||||||
If oControls.Count > 0 Then
|
|
||||||
oProfileMatchedSofar.Controls = oControls
|
|
||||||
oFilteredProfiles.Add(oProfileMatchedSofar)
|
|
||||||
Else
|
|
||||||
Dim olowestNode As TreeNode = Node_Get_Lowest_Node(oProfileMatchedSofar.Name & "-REGEX")
|
|
||||||
If Not IsNothing(olowestNode) Then
|
|
||||||
Dim oNode As New TreeNode($"NO MATCHES on Focused Control, Please check the Config")
|
|
||||||
oNode.ImageIndex = 2
|
|
||||||
oNode.Tag = oProfileMatchedSofar.Name & "-CONTROLNoMatch"
|
|
||||||
olowestNode.Nodes.Add(oNode)
|
|
||||||
End If
|
|
||||||
End If
|
|
||||||
Next
|
|
||||||
|
|
||||||
Return oFilteredProfiles
|
|
||||||
End Function
|
|
||||||
|
|
||||||
Public Function ClearNotMatchedProfiles(Profiles As List(Of ProfileData)) As List(Of ProfileData)
|
Public Function ClearNotMatchedProfiles(Profiles As List(Of ProfileData)) As List(Of ProfileData)
|
||||||
Dim oFilteredProfiles As New List(Of ProfileData)
|
Dim oFilteredProfiles As New List(Of ProfileData)
|
||||||
For Each oProfile In Profiles
|
For Each oProfile In Profiles
|
||||||
@ -545,6 +462,7 @@ Public Class ClassProfileFilter
|
|||||||
|
|
||||||
oList.Add(New ProfileData() With {
|
oList.Add(New ProfileData() With {
|
||||||
.Guid = oRow.Item("GUID"),
|
.Guid = oRow.Item("GUID"),
|
||||||
|
.Regex = oRow.Item("REGEX_EXPRESSION"),
|
||||||
.Name = NotNull(oRow.Item("NAME"), String.Empty),
|
.Name = NotNull(oRow.Item("NAME"), String.Empty),
|
||||||
.Comment = NotNull(oRow.Item("COMMENT"), String.Empty),
|
.Comment = NotNull(oRow.Item("COMMENT"), String.Empty),
|
||||||
.ProfileType = NotNull(oRow.Item("PROFILE_TYPE"), String.Empty),
|
.ProfileType = NotNull(oRow.Item("PROFILE_TYPE"), String.Empty),
|
||||||
@ -554,6 +472,10 @@ Public Class ClassProfileFilter
|
|||||||
})
|
})
|
||||||
Next
|
Next
|
||||||
|
|
||||||
|
oList = oList.
|
||||||
|
Distinct().
|
||||||
|
ToList()
|
||||||
|
|
||||||
Return oList
|
Return oList
|
||||||
End Function
|
End Function
|
||||||
|
|
||||||
@ -609,6 +531,10 @@ Public Class ClassProfileFilter
|
|||||||
End If
|
End If
|
||||||
Next
|
Next
|
||||||
|
|
||||||
|
oProcessList = oProcessList.
|
||||||
|
Distinct().
|
||||||
|
ToList()
|
||||||
|
|
||||||
Return oProcessList
|
Return oProcessList
|
||||||
End Function
|
End Function
|
||||||
Private Function TransformWindows(ProfileId As Integer, WindowDatatable As DataTable) As List(Of WindowData)
|
Private Function TransformWindows(ProfileId As Integer, WindowDatatable As DataTable) As List(Of WindowData)
|
||||||
|
|||||||
@ -102,18 +102,22 @@ Public Class frmStart
|
|||||||
End If
|
End If
|
||||||
|
|
||||||
If DT_USER_PROFILES Is Nothing OrElse DT_USER_PROFILES.Rows.Count = 0 Then
|
If DT_USER_PROFILES Is Nothing OrElse DT_USER_PROFILES.Rows.Count = 0 Then
|
||||||
|
Logger.Warn("DT_USER_PROFILES is empty!")
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If DTPROFILE_REL_PROCESS Is Nothing OrElse DTPROFILE_REL_PROCESS.Rows.Count = 0 Then
|
If DTPROFILE_REL_PROCESS Is Nothing OrElse DTPROFILE_REL_PROCESS.Rows.Count = 0 Then
|
||||||
|
Logger.Warn("DTPROFILE_REL_PROCESS is empty!")
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If DTPROFILE_REL_WINDOW Is Nothing OrElse DTPROFILE_REL_WINDOW.Rows.Count = 0 Then
|
If DTPROFILE_REL_WINDOW Is Nothing OrElse DTPROFILE_REL_WINDOW.Rows.Count = 0 Then
|
||||||
|
Logger.Warn("DTPROFILE_REL_WINDOW is empty!")
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
If DTPROFILE_REL_CONTROL Is Nothing OrElse DTPROFILE_REL_CONTROL.Rows.Count = 0 Then
|
If DTPROFILE_REL_CONTROL Is Nothing OrElse DTPROFILE_REL_CONTROL.Rows.Count = 0 Then
|
||||||
|
Logger.Warn("DTPROFILE_REL_CONTROL is empty!")
|
||||||
Exit Sub
|
Exit Sub
|
||||||
End If
|
End If
|
||||||
|
|
||||||
@ -122,7 +126,12 @@ Public Class frmStart
|
|||||||
Dim oProfileFilter As ClassProfileFilter
|
Dim oProfileFilter As ClassProfileFilter
|
||||||
Dim oFocusedControl As IntPtr = FocusedControlinActiveWindow(Handle)
|
Dim oFocusedControl As IntPtr = FocusedControlinActiveWindow(Handle)
|
||||||
Try
|
Try
|
||||||
oProfileFilter = New ClassProfileFilter(DT_USER_PROFILES, DTPROFILE_REL_PROCESS, DTPROFILE_REL_WINDOW, DTPROFILE_REL_CONTROL)
|
oProfileFilter = New ClassProfileFilter(
|
||||||
|
DT_USER_PROFILES,
|
||||||
|
DTPROFILE_REL_PROCESS,
|
||||||
|
DTPROFILE_REL_WINDOW,
|
||||||
|
DTPROFILE_REL_CONTROL,
|
||||||
|
CurrMatchTreeView)
|
||||||
Catch ex As Exception
|
Catch ex As Exception
|
||||||
MsgBox("Fehler beim Laden der Profile. Möglicherweise liegt ein Konfigurationsfehler vor.", MsgBoxStyle.Critical, Text)
|
MsgBox("Fehler beim Laden der Profile. Möglicherweise liegt ein Konfigurationsfehler vor.", MsgBoxStyle.Critical, Text)
|
||||||
Exit Sub
|
Exit Sub
|
||||||
@ -133,8 +142,6 @@ Public Class frmStart
|
|||||||
CurrMatchTreeView.ImageList = ImageList1
|
CurrMatchTreeView.ImageList = ImageList1
|
||||||
CurrMatchTreeView.SelectedImageIndex = 0
|
CurrMatchTreeView.SelectedImageIndex = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
oProfiles = oProfileFilter.FilterProfilesByClipboardRegex(oProfiles, ClipboardContents)
|
oProfiles = oProfileFilter.FilterProfilesByClipboardRegex(oProfiles, ClipboardContents)
|
||||||
oProfiles = oProfileFilter.FilterProfilesByProcess(oProfiles, oWindowInfo.ProcessName)
|
oProfiles = oProfileFilter.FilterProfilesByProcess(oProfiles, oWindowInfo.ProcessName)
|
||||||
oProfiles = oProfileFilter.FilterWindowsByWindowTitleRegex(oProfiles, oWindowInfo.WindowTitle)
|
oProfiles = oProfileFilter.FilterWindowsByWindowTitleRegex(oProfiles, oWindowInfo.WindowTitle)
|
||||||
@ -158,7 +165,6 @@ Public Class frmStart
|
|||||||
ElseIf HotKeyID = HOTKEY_TOGGLE_WATCHER Then
|
ElseIf HotKeyID = HOTKEY_TOGGLE_WATCHER Then
|
||||||
Change_Monitoring_State()
|
Change_Monitoring_State()
|
||||||
End If
|
End If
|
||||||
|
|
||||||
End Sub
|
End Sub
|
||||||
Sub CHECK_PROFILE_MATCH()
|
Sub CHECK_PROFILE_MATCH()
|
||||||
Dim oProfiles = CURRENT_MATCHING_PROFILES
|
Dim oProfiles = CURRENT_MATCHING_PROFILES
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user