ZooFlow: Clean up, faster search

This commit is contained in:
Jonathan Jenne
2022-02-18 15:02:51 +01:00
parent c6c548afe4
commit 77597f0ef2
53 changed files with 326 additions and 818 deletions

View File

@@ -7,17 +7,18 @@ Imports DigitalData.Modules.Windows
Imports DigitalData.Modules.ZooFlow.Params
Imports DigitalData.Modules.ZooFlow.State
Imports DigitalData.Modules.Patterns
Imports DigitalData.Modules.Base
Public Class ProfileFilter
Private _ProfileMatch As ProfileMatch
Private _ProfileTable As DataTable
Private _ProcessTable As DataTable
Private _WindowTable As DataTable
Private _ControlTable As DataTable
Private _Profiles As List(Of ProfileData)
Private _TreeView As TreeView
Private _LogConfig As LogConfig
Private _Logger As Logger
Inherits BaseClass
Private ReadOnly _ProfileMatch As ProfileMatch
Private ReadOnly _ProfileTable As DataTable
Private ReadOnly _ProcessTable As DataTable
Private ReadOnly _WindowTable As DataTable
Private ReadOnly _ControlTable As DataTable
Private ReadOnly _Profiles As List(Of ProfileData)
Private ReadOnly _TreeView As TreeView
Public Enum ImageIndex
Root
@@ -44,25 +45,27 @@ Public Class ProfileFilter
End Property
Public Sub New(LogConfig As LogConfig, ProfileDatatable As DataTable, ProcessTable As DataTable, WindowDatatable As DataTable, ControlDatatable As DataTable, TreeView As TreeView)
Try
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger()
MyBase.New(LogConfig)
_Logger.Debug("Initializing Profile Filter")
_Logger.Debug("Initializing Profile Data")
Try
LogConfig = LogConfig
Logger = LogConfig.GetLogger()
Logger.Debug("Initializing Profile Filter")
Logger.Debug("Initializing Profile Data")
_ProfileTable = ProfileDatatable
_ProcessTable = ProcessTable
_WindowTable = WindowDatatable
_ControlTable = ControlDatatable
_Logger.Debug("Initializing Profile Debugging")
Logger.Debug("Initializing Profile Debugging")
_TreeView = TreeView
_ProfileMatch = New ProfileMatch(LogConfig)
_Logger.Debug("Transforming Profiles")
Logger.Debug("Transforming Profiles")
_Profiles = TransformProfiles()
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
Throw ex
End Try
End Sub
@@ -72,7 +75,7 @@ Public Class ProfileFilter
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)
Logger.Debug("Profiles remaining after Step {0}: {1}", StepDescription, Profiles.Count)
Return Profiles
End Function
@@ -88,7 +91,7 @@ Public Class ProfileFilter
_TreeView.Nodes.Add(oRootNode)
For Each oProfile In Profiles
_Logger.Debug("Current Profile: {0}", oProfile.Name)
Logger.Debug("Current Profile: {0}", oProfile.Name)
Dim oNode = _ProfileMatch.NewProfileNode(oProfile)
oRootNode.Nodes.Add(oNode)
@@ -97,8 +100,8 @@ Public Class ProfileFilter
Dim oRegex As New Regex(oProfile.Regex)
Dim oMatch = oRegex.Match(ClipboardContents)
If oMatch.Success Then
_Logger.Debug("FilterProfilesByClipboardRegex: Clipboard Regex Matched: {0}", ClipboardContents)
_Logger.Info("FilterProfilesByClipboardRegex: Profile {0} matched!", oProfile.Name)
Logger.Debug("FilterProfilesByClipboardRegex: Clipboard Regex Matched: {0}", ClipboardContents)
Logger.Info("FilterProfilesByClipboardRegex: Profile {0} matched!", oProfile.Name)
oFilteredProfiles.Add(oProfile)
oProfile.IsMatched = True
@@ -106,8 +109,8 @@ Public Class ProfileFilter
oNode.Nodes.Add(oSubnode)
End If
Catch ex As Exception
_Logger.Warn("Regex '{0}' could not be processed for input '{1}'", oProfile.Regex, ClipboardContents)
_Logger.Error(ex)
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", oProfile.Regex, ClipboardContents)
Logger.Error(ex)
End Try
Next
@@ -140,12 +143,12 @@ 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($"Processname Matched: {oProcess.ProcessName}")
Logger.Debug($"Processname Matched: {oProcess.ProcessName}")
oFilteredProfiles.Add(oProfile)
_Logger.Info("FilterProfilesByProcess: Profile {0} matched!", oProfile.Name)
Logger.Info("FilterProfilesByProcess: Profile {0} matched!", oProfile.Name)
' Set Process matched
oProcess.IsMatched = True
@@ -168,8 +171,8 @@ Public Class ProfileFilter
Return oFilteredProfiles
Catch ex As Exception
_Logger.Warn("Unexpected error in FilterProfilesByProcess...")
_Logger.Error(ex)
Logger.Warn("Unexpected error in FilterProfilesByProcess...")
Logger.Error(ex)
Return Profiles
End Try
End Function
@@ -177,7 +180,7 @@ Public Class ProfileFilter
Dim oProfiles As New List(Of ProfileData)
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 oFilteredWindows As New List(Of WindowData)
@@ -190,7 +193,7 @@ Public Class ProfileFilter
' If Profile has no windows at all, it automatically matches
If oFilteredWindows.Count = 0 Then
_Logger.Debug("Profile has no Windows assigned, automatic MATCH")
Logger.Debug("Profile has no Windows assigned, automatic MATCH")
oProfile.IsMatched = True
oProfiles.Add(oProfile)
@@ -214,12 +217,12 @@ Public Class ProfileFilter
Dim oMatch = oRegex.Match(WindowTitle)
If oMatch.Success Then
_Logger.Debug("MATCH on WindowTitle: {0}", WindowTitle)
Logger.Debug("MATCH on WindowTitle: {0}", WindowTitle)
oProfile.MatchedWindowID = oWindowDef.Guid
oWindowDef.IsMatched = True
oWindows.Add(oWindowDef)
Else
_Logger.Debug("NO MATCH on WindowTitle: {0} - REGEX: {2}", WindowTitle, oWindowDef.Regex)
Logger.Debug("NO MATCH on WindowTitle: {0} - REGEX: {2}", WindowTitle, oWindowDef.Regex)
End If
Dim oParent = _ProfileMatch.FindNodeByTag(_TreeView.Nodes, oWindowDef.WindowProcessID & "-PROCESS")
@@ -229,8 +232,8 @@ Public Class ProfileFilter
End If
Catch ex As Exception
_Logger.Warn("Regex '{0}' could not be processed for input '{1}'", oWindowDef.Regex, WindowTitle)
_Logger.Error(ex)
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", oWindowDef.Regex, WindowTitle)
Logger.Error(ex)
End Try
Next
@@ -240,14 +243,14 @@ Public Class ProfileFilter
oProfile.IsMatched = True
oProfiles.Add(oProfile)
_Logger.Info("FilterWindowsByWindowTitleRegex: Profile {0} matched!", oProfile.Name)
Logger.Info("FilterWindowsByWindowTitleRegex: Profile {0} matched!", oProfile.Name)
End If
If oProfile.IsCatchAll Then
oProfile.IsMatched = True
oProfiles.Add(oProfile)
_Logger.Info("FilterWindowsByWindowTitleRegex: Profile {0} is marked catchall!", oProfile.Name)
Logger.Info("FilterWindowsByWindowTitleRegex: Profile {0} is marked catchall!", oProfile.Name)
End If
Next
@@ -259,7 +262,7 @@ Public Class ProfileFilter
Public Function FilterProfilesByFocusedControl(Profiles As List(Of ProfileData), ClipboardContents As String, WindowHandle As IntPtr) As List(Of ProfileData)
Dim oProfiles As New List(Of ProfileData)
Dim oWindow As New Window(_LogConfig)
Dim oWindow As New Window(LogConfig)
Dim oFocusedWindow As Window.WindowInfo
Try
@@ -268,7 +271,7 @@ Public Class ProfileFilter
Throw New ApplicationException("Window Information is Empty")
End If
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
Return Profiles
End Try
@@ -284,7 +287,7 @@ Public Class ProfileFilter
' If Profile has no controls at all, it automatically matches
If oFilteredControls.Count = 0 Then
_Logger.Debug("Profile has no Controls assigned, automatic MATCH")
Logger.Debug("Profile has no Controls assigned, automatic MATCH")
oProfiles.Add(oProfile)
Continue For
End If
@@ -322,8 +325,8 @@ Public Class ProfileFilter
End Select
Next
Catch ex As Exception
_Logger.Warn("Error while getting focused control location")
_Logger.Error(ex)
Logger.Warn("Error while getting focused control location")
Logger.Error(ex)
End Try
Else
Dim oControlName As String = oControl.ControlName
@@ -335,13 +338,13 @@ Public Class ProfileFilter
oFound = True
End If
Catch ex As Exception
_Logger.Warn("Error while getting focused control name")
_Logger.Error(ex)
Logger.Warn("Error while getting focused control name")
Logger.Error(ex)
End Try
End If
If oFound Then
_Logger.Debug("Control {0} has MATCH", oControl.ControlName)
Logger.Debug("Control {0} has MATCH", oControl.ControlName)
oMatchingControls.Add(oControl)
End If
@@ -354,11 +357,11 @@ Public Class ProfileFilter
' If Profile has controls that matched, the profile matches
If oMatchingControls.Count > 0 Then
_Logger.Debug("Profile has {0} MATCHING Controls", oMatchingControls.Count)
Logger.Debug("Profile has {0} MATCHING Controls", oMatchingControls.Count)
oProfile.Controls = oMatchingControls
oProfiles.Add(oProfile)
_Logger.Info("FilterProfilesByFocusedControl: Profile {0} matched!", oProfile.Name)
Logger.Info("FilterProfilesByFocusedControl: Profile {0} matched!", oProfile.Name)
End If
Next
@@ -372,11 +375,11 @@ Public Class ProfileFilter
Dim oProfiles As New List(Of ProfileData)
For Each oProfile In Profiles
_Logger.Debug($"Checking SearchResults on ProfileID: {oProfile.Guid}")
Logger.Debug($"Checking SearchResults on ProfileID: {oProfile.Guid}")
Dim oResultDocs As Integer = 0
Dim oResultData As Integer = 0
Dim oPatterns As New ClassPatterns(_LogConfig)
Dim oPatterns As New ClassPatterns(LogConfig)
Dim oDTDataSearches As DataTable
Dim oDTDocSearches As DataTable
@@ -385,7 +388,7 @@ Public Class ProfileFilter
oDTDataSearches = Database.GetDatatable($"SELECT COUNT_COMMAND, CONN_ID FROM TBCW_PROF_DATA_SEARCH WHERE ACTIVE = 1 AND PROFILE_ID = {oProfile.Guid}")
Catch ex As Exception
oProfile.ErrorMessage = ERROR_LOADING_COUNT_SQL_FOR_DATA_SEARCH
_Logger.Error(ex)
Logger.Error(ex)
Continue For
End Try
@@ -393,7 +396,7 @@ Public Class ProfileFilter
oDTDocSearches = Database.GetDatatable($"SELECT COUNT_COMMAND, CONN_ID FROM TBCW_PROF_DOC_SEARCH WHERE ACTIVE = 1 AND PROFILE_ID = {oProfile.Guid}")
Catch ex As Exception
oProfile.ErrorMessage = ERROR_LOADING_COUNT_SQL_FOR_DOC_SEARCH
_Logger.Error(ex)
Logger.Error(ex)
Continue For
End Try
@@ -406,25 +409,25 @@ Public Class ProfileFilter
oCountConnectionId = NotNull(oRow.Item("CONN_ID"), 0)
If oCountCommand = String.Empty Then
_Logger.Debug("Data SQL Query is empty. Skipping.")
Logger.Debug("Data SQL Query is empty. Skipping.")
Continue For
End If
_Logger.Debug("Count-Command DATA BEFORE Replace: [{0}]", oCountCommand)
Logger.Debug("Count-Command DATA BEFORE Replace: [{0}]", oCountCommand)
oCountCommand = oPatterns.ReplaceInternalValues(oCountCommand)
oCountCommand = oPatterns.ReplaceUserValues(oCountCommand, User)
oCountCommand = oPatterns.ReplaceClipboardContents(oCountCommand, ClipboardContents)
_Logger.Debug("Count-Command DATA before execute: [{0}]", oCountCommand)
Logger.Debug("Count-Command DATA before execute: [{0}]", oCountCommand)
Dim oConnectionString = ProfileUtils.GetConnectionString(Database, oCountConnectionId)
oResultData += NotNull(Of Integer)(Database.GetScalarValueWithConnection(oCountCommand, oConnectionString), 0)
_Logger.Debug("Datarows returned from search: [{0}]", oResultData)
Logger.Debug("Datarows returned from search: [{0}]", oResultData)
Catch ex As Exception
oProfile.ErrorMessage = ERROR_EXECUTING_COUNT_SQL_FOR_DATA_SEARCH
_Logger.Error(ex)
_Logger.Warn("Invalid SQL Query for Counting Data in Profile [{0}]: [{1}]", oProfile.Guid, oCountCommand)
Logger.Error(ex)
Logger.Warn("Invalid SQL Query for Counting Data in Profile [{0}]: [{1}]", oProfile.Guid, oCountCommand)
End Try
Next
@@ -437,25 +440,25 @@ Public Class ProfileFilter
oCountConnectionId = NotNull(oRow.Item("CONN_ID"), 0)
If oCountCommand = String.Empty Then
_Logger.Debug("Document SQL Query is empty. Skipping.")
Logger.Debug("Document SQL Query is empty. Skipping.")
Continue For
End If
_Logger.Debug("Count-Command for Documents BEFORE Replace: [{0}]", oCountCommand)
Logger.Debug("Count-Command for Documents BEFORE Replace: [{0}]", oCountCommand)
oCountCommand = oPatterns.ReplaceInternalValues(oCountCommand)
oCountCommand = oPatterns.ReplaceUserValues(oCountCommand, User)
oCountCommand = oPatterns.ReplaceClipboardContents(oCountCommand, ClipboardContents)
_Logger.Debug("Count-Command for Documents BEFORE execute: [{0}]", oCountCommand)
Logger.Debug("Count-Command for Documents BEFORE execute: [{0}]", oCountCommand)
Dim oConnectionString = ProfileUtils.GetConnectionString(Database, oCountConnectionId)
oResultDocs += NotNull(Of Integer)(Database.GetScalarValueWithConnection(oCountCommand, oConnectionString), 0)
_Logger.Debug("Documents returned from search: [{0}]", oResultDocs)
Logger.Debug("Documents returned from search: [{0}]", oResultDocs)
Catch ex As Exception
oProfile.ErrorMessage = ERROR_EXECUTING_COUNT_SQL_FOR_DOC_SEARCH
_Logger.Error(ex)
_Logger.Warn("Invalid SQL Query for Counting Data in Profile [{0}]: [{1}]", oProfile.Guid, oCountCommand)
Logger.Error(ex)
Logger.Warn("Invalid SQL Query for Counting Data in Profile [{0}]: [{1}]", oProfile.Guid, oCountCommand)
End Try
Next
@@ -473,7 +476,7 @@ Public Class ProfileFilter
If oProfile.CountData > 0 Or oProfile.CountDocs > 0 Then
oProfiles.Add(oProfile)
_Logger.Info("Profile [{0}] matched in FilterProfilesBySearchResults!", oProfile.Name)
Logger.Info("Profile [{0}] matched in FilterProfilesBySearchResults!", oProfile.Name)
End If
Next
@@ -484,7 +487,7 @@ Public Class ProfileFilter
Dim oProfiles As New List(Of ProfileData)
For Each oProfile As ProfileData In Profiles
_Logger.Debug("Current Profile: {0}", oProfile.Name)
Logger.Debug("Current Profile: {0}", oProfile.Name)
Dim oWindows As New List(Of WindowData)
@@ -498,7 +501,7 @@ Public Class ProfileFilter
Dim oMatch = oRegex.Match(ClipboardContents)
If oMatch.Success Then
_Logger.Debug("Window Clipboard Regex Matched: {0}", ClipboardContents)
Logger.Debug("Window Clipboard Regex Matched: {0}", ClipboardContents)
oWindows.Add(w)
End If
@@ -510,8 +513,8 @@ Public Class ProfileFilter
oResult.Nodes.Add(oNode)
End If
Catch ex As Exception
_Logger.Warn("Regex '{0}' could not be processed for input '{1}'", w.Regex, ClipboardContents)
_Logger.Error(ex)
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", w.Regex, ClipboardContents)
Logger.Error(ex)
End Try
Next
@@ -519,7 +522,7 @@ Public Class ProfileFilter
oProfile.Windows = oWindows
oProfiles.Add(oProfile)
_Logger.Info("FilterWindowsByWindowClipboardRegex: Profile {0} matched!", oProfile.Name)
Logger.Info("FilterWindowsByWindowClipboardRegex: Profile {0} matched!", oProfile.Name)
End If
Next
@@ -589,7 +592,7 @@ Public Class ProfileFilter
Return oList
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
Throw ex
End Try
End Function
@@ -636,7 +639,7 @@ Public Class ProfileFilter
Return oControlList
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
Throw ex
End Try
End Function
@@ -660,7 +663,7 @@ Public Class ProfileFilter
Return oProcessList
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
Throw ex
End Try
End Function
@@ -682,7 +685,7 @@ Public Class ProfileFilter
Return oWindowList
Catch ex As Exception
_Logger.Error(ex)
Logger.Error(ex)
Throw ex
End Try
End Function