WIP: Profile Matching

This commit is contained in:
Jonathan Jenne
2019-07-18 16:04:03 +02:00
parent 1652a4fb96
commit f7ff19afeb
8 changed files with 376 additions and 164 deletions

View File

@@ -1,18 +1,45 @@
Imports System.ComponentModel
Imports System.Threading
Imports System.Text.RegularExpressions
Imports DD_LIB_Standards
Public Class frmStart
Dim WithEvents Hotkey As New clsHotkey(Me)
Private PID As Integer
Private WithEvents _Watcher As ClipboardWatcher = ClipboardWatcher.Singleton
Private Sub frmClipboardWatch_Disposed(ByVal sender As Object,
ByVal e As EventArgs) Handles Me.Disposed
Private Sub frmClipboardWatch_Disposed(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Disposed
_Watcher.Dispose()
End Sub
Private Sub _Watcher_Changed(ByVal sender As Object,
ByVal e As EventArgs) Handles _Watcher.Changed
Private Sub WatcherChanged_New(ByVal sender As Object, ByVal e As EventArgs) Handles _Watcher.Changed
If MONITORING_ACTIVE = False Then
NotifyIconMain.ShowBalloonTip(20000, "Clipboard Watcher", "Clipboard-watcher is inactive.", ToolTipIcon.Info)
Exit Sub
End If
If DT_USER_PROFILES Is Nothing OrElse DT_USER_PROFILES.Rows.Count = 0 Then
Exit Sub
End If
Dim ClipboardContents As String = Clipboard.GetText()
Dim WindowTitle As String = clsHotkey.GetCaption()
Dim oProfileFilter As New ClassProfileFilter(DT_USER_PROFILES, DTPROFILE_REL_WINDOW)
Dim oProfiles = oProfileFilter.
FilterProfilesByProcess(CurrPROC_Name).
FilterProfilesByClipboardRegex(ClipboardContents).
FilterWindowsByWindowTitle(WindowTitle).
FilterProfilesByWindowRegex(ClipboardContents).
ToList()
CURRENT_MATCHING_PROFILES = oProfiles
CURR_MATCH_RESULT = ClipboardContents
End Sub
Private Sub _Watcher_Changed(ByVal sender As Object, ByVal e As EventArgs) ' Handles _Watcher.Changed
clsHotkey.GetCaption()
@@ -71,8 +98,19 @@ Public Class frmStart
oMatch = oRegex.Match(CURR_FOCUSED_WINDOWNAME)
oMatchWindow = oMatch.Success
If oMatchWindow = True Then
Dim oMatchRegexWindowClipboard As Boolean = False
Logger.Debug($"Found a match on windowtitle [{CURR_FOCUSED_WINDOWNAME}]")
Exit For
If oWindowMatchRow.Item("REGEX_CLIPBOARD") <> String.Empty Then
oRegex_expression = oWindowMatchRow.Item("REGEX_CLIPBOARD")
oRegex = New System.Text.RegularExpressions.Regex(oRegex_expression)
oMatch = oRegex.Match(CLIPBOARD_TEXT)
oMatchRegexWindowClipboard = oMatch.Success
If oMatchRegexWindowClipboard = True Then
Logger.Debug($"Found a match on oMatchRegexWindowClipboard [{oRegex_expression}]")
Exit For
End If
End If
End If
End If
Next
@@ -80,6 +118,12 @@ Public Class frmStart
Logger.Debug($"Found NO MATCH on windowtitle [{CURR_FOCUSED_WINDOWNAME}], but [{oCountWindowDefinitions}] definitions are configured")
Exit For
End If
' ================= MOVE TO CTRL + F =================
'CURR_MATCH_WM_SEARCH = oProfileRow.Item("WD_SEARCH")
Dim oSQL_COUNT As String = oProfileRow.Item("SQL_COUNT_RESULT")
Dim oRESULTDocs As Integer
@@ -103,6 +147,8 @@ Public Class frmStart
oFound = True
End If
' ================= MOVE TO CTRL + F =================
End If
'Else
@@ -222,33 +268,50 @@ Public Class frmStart
End Sub
Private Sub ReceiveHotKey(ByVal HotKeyID As String) Handles Hotkey.HotKeyPressed
If HotKeyID = 354523017 Then
If Not IsNothing(CURR_MATCH_RESULT) And Not IsNothing(CurrDT_PROFILE_MATCH) And MONITORING_ACTIVE = True Then
If CURRENT_MATCHING_PROFILES.Count > 0 And MONITORING_ACTIVE = True Then
CHECK_PROFILE_MATCH()
End If
'If Not IsNothing(CURR_MATCH_RESULT) And Not IsNothing(CURR_MATCH_WM_SEARCH) Then
' clsSearch.RUN_WD_SEARCH(CURR_MATCH_WM_SEARCH)
' 'Close Wait Form
'End If
ElseIf HotKeyID = 354522017 Then
Change_Monitoring_State()
End If
End Sub
Sub CHECK_PROFILE_MATCH()
If CurrDT_PROFILE_MATCH.Rows.Count = 1 Then
If CurrDT_PROFILE_MATCH.Rows(0).Item("COUNT") = 99999 Then
NotifyIconMain.ShowBalloonTip(20000, "Clipboard Watcher", "Found match but check is wrong - Check Your MatchCountConfig in Profiles!", ToolTipIcon.Info)
Exit Sub
ElseIf CurrDT_PROFILE_MATCH.Rows(0).Item("COUNT") = 99998 Then
NotifyIconMain.ShowBalloonTip(10000, "Clipboard Watcher", "Found match but MatchCountConfig is not configured!", ToolTipIcon.Info)
Dim oProfiles = CURRENT_MATCHING_PROFILES
For Each oProfile In oProfiles
Dim oSQL = oProfile.CountSQL
Dim oResultDocs As Integer = 0
If oSQL = String.Empty Then
oProfile.CountSQL = 99998
End If
Try
oSQL = clsPatterns.ReplaceAllValues(oSQL, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfile.Guid)
oResultDocs = ClassDatabase.Execute_Scalar(oSQL, MyConnectionString)
Catch ex As Exception
oResultDocs = 99999
End Try
CurrDocSearch2Load = CurrDT_PROFILE_MATCH.Rows(0).Item("GUID")
If (oResultDocs <> 99998 And oResultDocs <> 99998 And oResultDocs <> 0) Then
oProfile.Count = oResultDocs
End If
Next
If oProfiles.Count = 1 Then
If oProfiles.First().Count = 99999 Then
NotifyIconMain.ShowBalloonTip(20000, "Clipboard Watcher", "Found match but check is wrong - Check Your MatchCountConfig in Profiles!", ToolTipIcon.Info)
Exit Sub
End If
If oProfiles.First().Count = 99998 Then
NotifyIconMain.ShowBalloonTip(10000, "Clipboard Watcher", "Found match but MatchCountConfig is not configured!", ToolTipIcon.Info)
Exit Sub
End If
CurrDocSearch2Load = oProfiles.First().Guid
frmResultDoc.Show()
'frmProfileMatch.ShowDialog()
'clsSearch.RUN_WD_SEARCH(CURR_MATCH_WM_SEARCH)
Else
frmProfileMatch.ShowDialog()
End If