check for control name, minor error checking

This commit is contained in:
Jonathan Jenne 2019-10-25 11:58:33 +02:00
parent 130c095056
commit 1f280b73a6

View File

@ -142,8 +142,8 @@ Public Class ProfileFilter
Catch ex As Exception Catch ex As Exception
_Logger.Warn("Unexpected error in FilterProfilesByProcess...") _Logger.Warn("Unexpected error in FilterProfilesByProcess...")
_Logger.Error(ex) _Logger.Error(ex)
Return Profiles
End Try End Try
End Function End Function
Public Function FilterWindowsByWindowTitleRegex(Profiles As List(Of ProfileData), WindowTitle As String) As List(Of ProfileData) Public Function FilterWindowsByWindowTitleRegex(Profiles As List(Of ProfileData), WindowTitle As String) As List(Of ProfileData)
Dim oProfiles As New List(Of ProfileData) Dim oProfiles As New List(Of ProfileData)
@ -219,29 +219,52 @@ Public Class ProfileFilter
Dim oControls As New List(Of ControlData) Dim oControls As New List(Of ControlData)
For Each oControl In oProfile.Controls For Each oControl In oProfile.Controls
Dim oControlBounds = oWindow.GetFocusedControlLocation(WindowHandle)
Dim oFound As Boolean = False Dim oFound As Boolean = False
For Each oItem As KeyValuePair(Of String, Window.RectangleInfo) In oControlBounds If oControl.ControlName Is Nothing OrElse oControl.ControlName = String.Empty Then
Select Case oItem.Key Dim oControlBounds As Dictionary(Of String, Window.RectangleInfo)
Case "TopLeft"
If oControl.TopLeft.Top = oItem.Value.Top And oControl.TopLeft.Left = oItem.Value.Left Then Try
oFound = True oControlBounds = oWindow.GetFocusedControlLocation(WindowHandle)
End If
Case "TopRight" For Each oItem As KeyValuePair(Of String, Window.RectangleInfo) In oControlBounds
If oControl.TopRight.Top = oItem.Value.Top And oControl.TopLeft.Right = oItem.Value.Right Then Select Case oItem.Key
oFound = True Case "TopLeft"
End If If oControl.TopLeft.Top = oItem.Value.Top And oControl.TopLeft.Left = oItem.Value.Left Then
Case "BottomLeft" oFound = True
If oControl.BottomLeft.Bottom = oItem.Value.Bottom And oControl.TopLeft.Left = oItem.Value.Left Then End If
oFound = True Case "TopRight"
End If If oControl.TopRight.Top = oItem.Value.Top And oControl.TopLeft.Right = oItem.Value.Right Then
Case "BottomRight" oFound = True
If oControl.BottomRight.Bottom = oItem.Value.Bottom And oControl.TopLeft.Right = oItem.Value.Right Then End If
oFound = True Case "BottomLeft"
End If If oControl.BottomLeft.Bottom = oItem.Value.Bottom And oControl.TopLeft.Left = oItem.Value.Left Then
End Select oFound = True
Next End If
Case "BottomRight"
If oControl.BottomRight.Bottom = oItem.Value.Bottom And oControl.TopLeft.Right = oItem.Value.Right Then
oFound = True
End If
End Select
Next
Catch ex As Exception
_Logger.Warn("Error while getting focused control location")
_Logger.Error(ex)
End Try
Else
Dim oControlName As String = oControl.ControlName
Try
Dim oFocusedControl = oWindow.GetFocusedControl(WindowHandle)
If oFocusedControl.ControlName = oControlName Then
oFound = True
End If
Catch ex As Exception
_Logger.Warn("Error while getting focused control name")
_Logger.Error(ex)
End Try
End If
If oFound Then If oFound Then
oControls.Add(oControl) oControls.Add(oControl)
@ -448,6 +471,7 @@ Public Class ProfileFilter
If oRow.Item("PROFILE_ID") = ProfileId Then If oRow.Item("PROFILE_ID") = ProfileId Then
oControlList.Add(New ControlData() With { oControlList.Add(New ControlData() With {
.Guid = oRow.Item("GUID"), .Guid = oRow.Item("GUID"),
.ControlName = NotNull(oRow.Item("CONTROL_NAME"), String.Empty),
.Description = NotNull(oRow.Item("DESCRIPTION"), String.Empty), .Description = NotNull(oRow.Item("DESCRIPTION"), String.Empty),
.WindowId = oRow.Item("WINDOW_ID"), .WindowId = oRow.Item("WINDOW_ID"),
.TopLeft = New ControlBounds() With { .TopLeft = New ControlBounds() With {