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

@ -0,0 +1,184 @@
Imports System.Text.RegularExpressions
Public Class ClassProfileFilter
Private _ProfileTable As DataTable
Private _WindowTable As DataTable
Private _Profiles As List(Of ProfileData)
Private _DebugData As DebugData
Class ProfileData
Public Guid As Integer
Public Regex As String
Public ProcessName As String
Public Name As String
Public Comment As String
Public CountSQL As String
Public Count As Integer = 0
Public Windows As List(Of WindowData)
End Class
Class WindowData
Public Title As String
Public Regex As String
Public Sequence As Integer
Public ClipboardRegex As String
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 Sub New(ProfileDatatable As DataTable, WindowDatatable As DataTable)
_DebugData = New DebugData()
_ProfileTable = ProfileDatatable
_WindowTable = WindowDatatable
_Profiles = TransformProfiles()
End Sub
Public Function ToList() As List(Of ProfileData)
Return _Profiles
End Function
Public Function FilterProfilesByProcess(CurrentProcessName As String) As ClassProfileFilter
_Profiles = _Profiles.
Where(Function(p)
If p.ProcessName.ToLower = CurrentProcessName.ToLower Then
'TODO: Add Debug Data
Return True
Else
Return False
End If
End Function).
ToList()
Return Me
End Function
Public Function FilterProfilesByClipboardRegex(ClipboardContents As String) As ClassProfileFilter
_Profiles = _Profiles.
Where(Function(p)
Try
Dim oRegex As New Regex(p.Regex)
Dim oMatch = oRegex.Match(ClipboardContents)
If oMatch.Success Then
'TODO: Add Debug Data
Return True
Else
Return False
End If
Catch ex As Exception
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", p.Regex, ClipboardContents)
Logger.Error(ex)
Return False
End Try
End Function).
ToList()
Return Me
End Function
Public Function FilterWindowsByWindowTitle(WindowTitle As String) As ClassProfileFilter
_Profiles = _Profiles.Select(Function(p)
Dim oWindows As List(Of WindowData) = p.Windows
p.Windows = oWindows.
Where(Function(w)
Try
If w.Regex = String.Empty Then Return True
Dim oRegex As New Regex(w.Regex)
Dim oMatch = oRegex.Match(WindowTitle)
If oMatch.Success Then
'TODO: Add Debug Data
Return True
Else
Return False
End If
Catch ex As Exception
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", w.Regex, WindowTitle)
Logger.Error(ex)
Return False
End Try
End Function).
ToList()
Return p
End Function).
ToList()
Return Me
End Function
Public Function FilterProfilesByWindowRegex(ClipboardContents As String) As ClassProfileFilter
_Profiles = _Profiles.Where(Function(p)
If p.Windows.Count = 0 Then Return True
Return p.Windows.
Any(Function(w)
Try
If w.ClipboardRegex = String.Empty Then Return True
Dim oRegex As New Regex(w.ClipboardRegex)
Dim oMatch = oRegex.Match(ClipboardContents)
If oMatch.Success Then
'TODO: Add Debug Data
Return True
Else
Return False
End If
Catch ex As Exception
Logger.Warn("Regex '{0}' could not be processed for input '{1}'", w.ClipboardRegex, ClipboardContents)
Logger.Error(ex)
Return False
End Try
End Function)
End Function).
ToList()
Return Me
End Function
Private Function TransformProfiles() As List(Of ProfileData)
Dim oList As New List(Of ProfileData)
For Each oRow As DataRow In _ProfileTable.Rows
Dim oProfileId = oRow.Item("GUID")
Dim oWindowList As List(Of WindowData) = TransformWindows(oProfileId, _WindowTable)
oList.Add(New ProfileData() With {
.Guid = oRow.Item("GUID"),
.ProcessName = oRow.Item("PROC_NAME"),
.Regex = oRow.Item("REGEX_EXPRESSION"),
.Name = oRow.Item("NAME"),
.Comment = oRow.Item("COMMENT"),
.CountSQL = oRow.Item("SQL_COUNT_RESULT"),
.Windows = oWindowList
})
Next
Return oList
End Function
Private Function TransformWindows(ProfileId As Integer, WindowDatatable As DataTable) As List(Of WindowData)
Dim oWindowList As New List(Of WindowData)
For Each oRow As DataRow In WindowDatatable.Rows
If oRow.Item("PROFILE_ID") = ProfileId Then
oWindowList.Add(New WindowData() With {
.Title = oRow.Item("DESCRIPTION"),
.Regex = oRow.Item("REGEX"),
.Sequence = oRow.Item("SEQUENCE"),
.ClipboardRegex = oRow.Item("REGEX_CLIPBOARD")
})
End If
Next
Return oWindowList
End Function
End Class

View File

@ -120,6 +120,7 @@
<Compile Include="ClassDatabase.vb" /> <Compile Include="ClassDatabase.vb" />
<Compile Include="ClassInit.vb" /> <Compile Include="ClassInit.vb" />
<Compile Include="ClassLayout.vb" /> <Compile Include="ClassLayout.vb" />
<Compile Include="ClassProfileFilter.vb" />
<Compile Include="clsHotkey.vb" /> <Compile Include="clsHotkey.vb" />
<Compile Include="clsLicense.vb" /> <Compile Include="clsLicense.vb" />
<Compile Include="clsPatterns.vb" /> <Compile Include="clsPatterns.vb" />

View File

@ -140,6 +140,7 @@ Public Class clsHotkey
RaiseEvent HotKeyPressed(mHotKeyList(CShort(m.WParam)).HotKeyID) RaiseEvent HotKeyPressed(mHotKeyList(CShort(m.WParam)).HotKeyID)
End If End If
End Function End Function
Public Shared Function GetCaption() As String Public Shared Function GetCaption() As String
Dim Caption As New System.Text.StringBuilder(256) Dim Caption As New System.Text.StringBuilder(256)
Dim hWnd As IntPtr = GetForegroundWindow() Dim hWnd As IntPtr = GetForegroundWindow()

View File

@ -1,6 +1,10 @@
Imports DevExpress.XtraEditors Imports DevExpress.XtraEditors
Public Class frmProfileMatch Public Class frmProfileMatch
Private PrimaryFont As New Font("Segoe UI", 12, FontStyle.Bold)
Private SecondaryFont As New Font("Segoe UI", 10)
Private Sub frmProfileMatch_Load(sender As Object, e As EventArgs) Handles Me.Load Private Sub frmProfileMatch_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not ConfigManager.Config.MatchWindowLocation.IsEmpty Then If Not ConfigManager.Config.MatchWindowLocation.IsEmpty Then
Location = ConfigManager.Config.MatchWindowLocation Location = ConfigManager.Config.MatchWindowLocation
@ -21,38 +25,35 @@ Public Class frmProfileMatch
Sub CreateTiles() Sub CreateTiles()
Try Try
Dim oPrimaryFont As New Font("Segoe UI", 12, FontStyle.Bold)
Dim oSecondaryFont As New Font("Segoe UI", 10)
Dim oGroup = TileControl1.Groups.Item("TileGroupDocuments") Dim oGroup = TileControl1.Groups.Item("TileGroupDocuments")
oGroup.Items.Clear() oGroup.Items.Clear()
For Each oRow As DataRow In CurrDT_PROFILE_MATCH.Rows For Each oProfile As ClassProfileFilter.ProfileData In CURRENT_MATCHING_PROFILES
Dim oItem As New TileItem() With {.Tag = oRow.Item("GUID")} Dim oItem As New TileItem() With {.Tag = oProfile.Guid}
oItem.Elements.Clear() oItem.Elements.Clear()
Dim oNameElement = New TileItemElement() Dim oNameElement = New TileItemElement()
oNameElement.Text = oRow.Item("NAME") oNameElement.Text = oProfile.Name
oNameElement.TextAlignment = TileItemContentAlignment.TopLeft oNameElement.TextAlignment = TileItemContentAlignment.TopLeft
oNameElement.Appearance.Normal.Font = oPrimaryFont oNameElement.Appearance.Normal.Font = PrimaryFont
oItem.Elements.Add(oNameElement) oItem.Elements.Add(oNameElement)
Dim oCommentElement = New TileItemElement() Dim oCommentElement = New TileItemElement()
oCommentElement.Text = oRow.Item("COMMENT") oCommentElement.Text = oProfile.Comment
oCommentElement.TextAlignment = TileItemContentAlignment.MiddleLeft oCommentElement.TextAlignment = TileItemContentAlignment.MiddleLeft
oCommentElement.Appearance.Normal.Font = oSecondaryFont oCommentElement.Appearance.Normal.Font = SecondaryFont
oItem.Elements.Add(oCommentElement) oItem.Elements.Add(oCommentElement)
Dim oCountElement = New TileItemElement() Dim oCountElement = New TileItemElement()
oCountElement.TextAlignment = TileItemContentAlignment.BottomRight oCountElement.TextAlignment = TileItemContentAlignment.BottomRight
oCountElement.Appearance.Normal.Font = oSecondaryFont oCountElement.Appearance.Normal.Font = SecondaryFont
Dim oText As String Dim oText As String
If oRow.Item("COUNT") = 99999 Then If oProfile.Count = 99999 Then
oText = "DocCount 0 = Check Your MatchCountConfig in Profiles!" oText = "DocCount 0 = Check Your MatchCountConfig in Profiles!"
ElseIf oRow.Item("COUNT") = 99998 Then ElseIf oProfile.Count = 99998 Then
oText = "DocCount (MatchCountConfig has not been configured)" oText = "DocCount (MatchCountConfig has not been configured)"
Else Else
oText = $"{oRow.Item("COUNT")} files!" oText = $"{oProfile.Count} files!"
End If End If
oCountElement.Text = oText oCountElement.Text = oText
@ -61,19 +62,11 @@ Public Class frmProfileMatch
oGroup.Items.Add(oItem) oGroup.Items.Add(oItem)
Next Next
Catch ex As Exception Catch ex As Exception
Logger.Error(ex)
MsgBox("Error while creating profile tiles!" & vbNewLine & ex.Message)
End Try End Try
End Sub End Sub
Sub OpenResults_Doc()
Dim oFrmResultDoc As Form = New frmResultDoc
oFrmResultDoc.Show()
End Sub
Sub OpenResults_Data()
Dim oFrmResultData As Form = New frmResultSQL
oFrmResultData.Show()
End Sub
Private Sub frmProfileMatch_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing Private Sub frmProfileMatch_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try Try
ConfigManager.Config.MatchWindowSize = Size ConfigManager.Config.MatchWindowSize = Size
@ -99,11 +92,11 @@ Public Class frmProfileMatch
If oProfileId Is Nothing Then If oProfileId Is Nothing Then
Dim oResult As String = "" Dim oResult As String = ""
For Each oRow As DataRow In CurrDT_PROFILE_MATCH.Rows For Each oProfile As ClassProfileFilter.ProfileData In CURRENT_MATCHING_PROFILES
If oResult = "" Then If oResult = "" Then
oResult = oRow.Item("GUID") oResult = oProfile.Guid
Else Else
oResult &= "," & oRow.Item("GUID") oResult &= "," & oProfile.Guid
End If End If
Next Next
CurrDocSearch2Load = oResult CurrDocSearch2Load = oResult
@ -113,20 +106,11 @@ Public Class frmProfileMatch
CurrDataSearch2Load = oProfileId CurrDataSearch2Load = oProfileId
End If End If
OpenResults_Doc() ' Show Result Document Form
OpenResults_Data() Dim oFrmResultDoc As Form = New frmResultDoc(Me)
Me.Hide() oFrmResultDoc.Show()
End Sub
Private Sub frmProfileMatch_VisibleChanged(sender As Object, e As EventArgs) Handles Me.VisibleChanged ' ..and hide myself
If Me.Visible = True Then Hide()
If CurrSearchOpen = True Then
End If
Else
If CurrSearchOpen = True Then
End If
End If
End Sub End Sub
End Class End Class

View File

@ -64,8 +64,6 @@ Public Class frmResultDoc
Dim oSearches = Await LoadSearchesAsync() Dim oSearches = Await LoadSearchesAsync()
Await Task.Delay(1000) 'DEBUG
For Each oSearch As DocSearch In oSearches For Each oSearch As DocSearch In oSearches
RefreshTabDoc(oSearch.ProfileId, oSearch.DataTable, oSearch.TabIndex, oSearch.TabCaption) RefreshTabDoc(oSearch.ProfileId, oSearch.DataTable, oSearch.TabIndex, oSearch.TabCaption)
Next Next
@ -73,6 +71,28 @@ Public Class frmResultDoc
GridViewDocSearch1.HideLoadingPanel() GridViewDocSearch1.HideLoadingPanel()
End Sub End Sub
Private Sub frmResultDoc_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try
ConfigManager.Config.ResultDocWindowSize = Size
ConfigManager.Config.ResultDocWindowLocation = Location
ConfigManager.Save()
Catch ex As Exception
Logger.Error(ex)
Logger.Warn("Error in Save FormLayout: " & ex.Message)
End Try
_frmDocView?.Close()
_frmSQL?.Close()
If CURRENT_MATCHING_PROFILES.Count > 1 Then
_frmProfileMatch?.Show()
_frmProfileMatch?.BringToFront()
End If
CURR_MATCH_RESULT = Nothing
CLIPBOARD_TEXT = ""
End Sub
Private Async Function LoadSearchesAsync() As Task(Of List(Of DocSearch)) Private Async Function LoadSearchesAsync() As Task(Of List(Of DocSearch))
Return Await Task.Run(AddressOf DoLoadSearches) Return Await Task.Run(AddressOf DoLoadSearches)
End Function End Function
@ -474,52 +494,6 @@ Public Class frmResultDoc
Show_File_Properties() Show_File_Properties()
End Sub End Sub
Private Sub frmResultDoc_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try
ConfigManager.Config.ResultDocWindowSize = Size
ConfigManager.Config.ResultDocWindowLocation = Location
ConfigManager.Save()
Catch ex As Exception
Logger.Error(ex)
Logger.Info("Error in Save FormLayout: " & ex.Message)
End Try
Try
Dim frmCollection As New FormCollection()
frmCollection = Application.OpenForms()
Try
If frmCollection.Item("frmDocView").IsHandleCreated Then
_frmDocView.Close()
End If
Catch ex As Exception
End Try
Try
If frmCollection.Item("frmResultSQL").IsHandleCreated Then
frmResultSQL.Close()
End If
Catch ex As Exception
End Try
If frmCollection.Item("frmProfileMatch")?.IsHandleCreated Then
frmProfileMatch.Show()
frmProfileMatch.BringToFront()
End If
Catch ex As Exception
If Not IsNothing(CurrDT_PROFILE_MATCH) Then
If CurrDT_PROFILE_MATCH.Rows.Count > 1 Then
_frmProfileMatch.Show()
_frmProfileMatch.BringToFront()
CURR_MATCH_RESULT = Nothing
CLIPBOARD_TEXT = ""
End If
End If
End Try
End Sub
Private Sub ToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem1.Click Private Sub ToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem1.Click
ReLoad_Active_DocTab() ReLoad_Active_DocTab()
End Sub End Sub

View File

@ -1,23 +1,24 @@
Imports System.ComponentModel Imports System.IO
Imports System.IO
Imports System.Runtime.InteropServices
Imports DevExpress.Utils
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Columns
Imports DevExpress.XtraGrid.Views.Grid
Imports DD_LIB_Standards
Imports DevExpress.XtraGrid.Views.Base
Imports DevExpress.XtraTab Imports DevExpress.XtraTab
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Base
Imports DD_LIB_Standards
Public Class frmResultSQL Public Class frmResultSQL
#Region "Laufzeitvariablen & Konstanten"
Private Shared BW_DocPath As String Private Shared BW_DocPath As String
Private Shared BW_DocID As Integer Private Shared BW_DocID As Integer
Private Shared CurrSearchID As Integer Private Shared CurrSearchID As Integer
Private DTDataSearchDefinition As DataTable Private DTDataSearchDefinition As DataTable
Private _activeGridView As GridView Private _activeGridView As GridView
#End Region
Private Class SQLSearch
Public DataTable As DataTable
Public TabIndex As Integer
Public TabCaption As String
Public ProfileId As Integer
End Class
Private Sub frmResultDoc_Load(sender As Object, e As EventArgs) Handles Me.Load Private Sub frmResultDoc_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not ConfigManager.Config.ResultDataWindowSize.IsEmpty Then If Not ConfigManager.Config.ResultDataWindowSize.IsEmpty Then
@ -31,6 +32,21 @@ Public Class frmResultSQL
Load_Searches() Load_Searches()
End Sub End Sub
Private Sub frmResultSQL_Shown(sender As Object, e As EventArgs) Handles Me.Shown
BringToFront()
End Sub
Private Sub frmResultDoc_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try
ConfigManager.Config.ResultDataWindowSize = Size
ConfigManager.Config.ResultDataWindowLocation = Location
ConfigManager.Save()
Catch ex As Exception
Logger.Error(ex)
Logger.Info("Error in Save FormLayout: " & ex.Message)
End Try
End Sub
Sub RefreshTabData(PROFILE_ID As Integer, ConID As Integer, SQLCommand As String, TabIndex As Integer, TabCaption As String) Sub RefreshTabData(PROFILE_ID As Integer, ConID As Integer, SQLCommand As String, TabIndex As Integer, TabCaption As String)
Try Try
SQLCommand = clsPatterns.ReplaceAllValues(SQLCommand, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, PROFILE_ID) SQLCommand = clsPatterns.ReplaceAllValues(SQLCommand, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, PROFILE_ID)
@ -88,24 +104,41 @@ Public Class frmResultSQL
End Sub End Sub
Private Function Get_Grid_Layout_Filename(oIndex As Integer) Private Function Get_Grid_Layout_Filename(oIndex As Integer)
Dim oFilename As String = String.Format("GridViewData_Search-{0}-{1}-UserLayout.xml", oIndex, CurrSearchID) Dim oFilename As String = String.Format("GridViewData_Search-{0}-{1}-UserLayout.xml", oIndex, CurrSearchID)
Dim oPath = System.IO.Path.Combine(Application.UserAppDataPath(), oFilename) Dim oPath = Path.Combine(Application.UserAppDataPath(), oFilename)
Return oPath Return oPath
End Function End Function
Private Sub GridControlDocSearch_Leave(sender As Object, e As EventArgs) Handles GridControlDocSearch1.Leave, GridControlDocSearch2.Leave, GridControlDocSearch3.Leave, GridControlDocSearch4.Leave, GridControlDocSearch5.Leave Private Sub GridControlDocSearch_Leave(sender As Object, e As EventArgs) Handles GridControlDocSearch1.Leave, GridControlDocSearch2.Leave, GridControlDocSearch3.Leave, GridControlDocSearch4.Leave, GridControlDocSearch5.Leave
SaveDocGridLayout() SaveDocGridLayout()
End Sub End Sub
Private Sub GridViewDocSearch1_FocusedRowChanged(sender As GridView, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch1.FocusedRowChanged, GridViewDataSearch2.FocusedRowChanged, GridViewDataSearch3.FocusedRowChanged, GridViewDataSearch4.FocusedRowChanged, GridViewDataSearch5.FocusedRowChanged
_activeGridView = sender
End Sub
Private Sub GridViewDocSearch1_ColumnWidthChanged(sender As GridView, e As Views.Base.ColumnEventArgs) Handles GridViewDataSearch1.ColumnWidthChanged, GridViewDataSearch2.ColumnWidthChanged, GridViewDataSearch3.ColumnWidthChanged, GridViewDataSearch4.ColumnWidthChanged, GridViewDataSearch5.ColumnWidthChanged
_activeGridView = sender
SaveDocGridLayout()
End Sub
Sub SaveDocGridLayout() Sub SaveDocGridLayout()
Dim oXMLPath = Get_Grid_Layout_Filename(XtraTabControlData.SelectedTabPageIndex) Dim oXMLPath = Get_Grid_Layout_Filename(XtraTabControlData.SelectedTabPageIndex)
_activeGridView.SaveLayoutToXml(oXMLPath) _activeGridView.SaveLayoutToXml(oXMLPath)
End Sub End Sub
Private Sub GridViewDocSearch1_ColumnWidthChanged(sender As Object, e As Views.Base.ColumnEventArgs) Handles GridViewDataSearch1.ColumnWidthChanged Private Async Function LoadSearchesAsync() As Task(Of List(Of SQLSearch))
_activeGridView = GridViewDataSearch1 Return Await Task.Run(AddressOf DoLoadSearches)
SaveDocGridLayout() End Function
End Sub
Private Function DoLoadSearches() As List(Of SQLSearch)
If IsNothing(CurrDocSearch2Load) Then
Throw New ApplicationException("CurrDataSearch2Load is empty")
End If
Dim oSQL = $"SELECT * FROM TBCW_PROF_DATA_SEARCH WHERE ACTIVE = 1 AND PROFILE_ID in ({CurrDataSearch2Load}) ORDER BY TAB_INDEX"
Dim oSearchesDataTable = clsDatabase.Return_Datatable(oSQL)
End Function
Sub Load_Searches() Sub Load_Searches()
If Not IsNothing(CurrDataSearch2Load) Then If Not IsNothing(CurrDataSearch2Load) Then
@ -121,33 +154,23 @@ Public Class frmResultSQL
Next Next
Else Else
MsgBox("Sorry but the selection of profile went wrong. (CurrSearch2Load is nothing)", MsgBoxStyle.Critical) MsgBox("Sorry but the selection of profile went wrong. (CurrSearch2Load is nothing)", MsgBoxStyle.Critical)
Me.Close() Close()
End If End If
End Sub End Sub
Private Sub frmResultDoc_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
Try Private Sub MenuItemReload_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem1.Click
ConfigManager.Config.ResultDataWindowSize = Size Reload_Active_DocumentTab()
ConfigManager.Config.ResultDataWindowLocation = Location
ConfigManager.Save()
Catch ex As Exception
Logger.Error(ex)
Logger.Info("Error in Save FormLayout: " & ex.Message)
End Try
End Sub End Sub
Private Sub ToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem1.Click Private Sub MenuItemResetLayout_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem2.Click
ReLoad_Active_DocTab() Reset_Layout()
End Sub End Sub
Sub Reset_Layout()
Private Sub ToolStripMenuItem2_Click(sender As Object, e As EventArgs) Handles ToolStripMenuItem2.Click
Set_DoclayoutBack()
End Sub
Sub Set_DoclayoutBack()
Dim oXMLPath = Get_Grid_Layout_Filename(XtraTabControlData.SelectedTabPageIndex) Dim oXMLPath = Get_Grid_Layout_Filename(XtraTabControlData.SelectedTabPageIndex)
Try Try
If File.Exists(oXMLPath) Then If File.Exists(oXMLPath) Then
File.Delete(oXMLPath) File.Delete(oXMLPath)
ReLoad_Active_DocTab() Reload_Active_DocumentTab()
tslblState.Text = "Layout has been set back!" tslblState.Text = "Layout has been set back!"
Else Else
tslblState.Text = "" tslblState.Text = ""
@ -156,7 +179,7 @@ Public Class frmResultSQL
tslblState.Text = "" tslblState.Text = ""
End Try End Try
End Sub End Sub
Sub ReLoad_Active_DocTab() Sub Reload_Active_DocumentTab()
Dim oTabIndex = XtraTabControlData.SelectedTabPageIndex Dim oTabIndex = XtraTabControlData.SelectedTabPageIndex
Dim oConID = DTDataSearchDefinition.Rows(oTabIndex).Item("CONN_ID") Dim oConID = DTDataSearchDefinition.Rows(oTabIndex).Item("CONN_ID")
Dim oCommand = DTDataSearchDefinition.Rows(oTabIndex).Item("SQL_COMMAND") Dim oCommand = DTDataSearchDefinition.Rows(oTabIndex).Item("SQL_COMMAND")
@ -175,24 +198,4 @@ Public Class frmResultSQL
Dim oTabCaption = DTDataSearchDefinition.Rows(XtraTabControlData.SelectedTabPageIndex).Item("TAB_TITLE") Dim oTabCaption = DTDataSearchDefinition.Rows(XtraTabControlData.SelectedTabPageIndex).Item("TAB_TITLE")
RefreshTabData(oProfileID, oConID, oCommand, oTabIndex, oTabCaption) RefreshTabData(oProfileID, oConID, oCommand, oTabIndex, oTabCaption)
End Sub End Sub
Private Sub GridViewDocSearch1_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch1.FocusedRowChanged
_activeGridView = GridViewDataSearch1
End Sub
Private Sub GridViewDocSearch2_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch2.FocusedRowChanged
_activeGridView = GridViewDataSearch2
End Sub
Private Sub GridViewDocSearch3_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch3.FocusedRowChanged
_activeGridView = GridViewDataSearch3
End Sub
Private Sub GridViewDocSearch4_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch4.FocusedRowChanged
_activeGridView = GridViewDataSearch4
End Sub
Private Sub GridViewDocSearch5_FocusedRowChanged(sender As Object, e As FocusedRowChangedEventArgs) Handles GridViewDataSearch5.FocusedRowChanged
_activeGridView = GridViewDataSearch5
End Sub
Private Sub frmResultSQL_Shown(sender As Object, e As EventArgs) Handles Me.Shown
Me.BringToFront()
End Sub
End Class End Class

View File

@ -1,18 +1,45 @@
Imports System.ComponentModel Imports System.ComponentModel
Imports System.Threading Imports System.Threading
Imports System.Text.RegularExpressions
Imports DD_LIB_Standards Imports DD_LIB_Standards
Public Class frmStart Public Class frmStart
Dim WithEvents Hotkey As New clsHotkey(Me) Dim WithEvents Hotkey As New clsHotkey(Me)
Private PID As Integer Private PID As Integer
Private WithEvents _Watcher As ClipboardWatcher = ClipboardWatcher.Singleton 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() _Watcher.Dispose()
End Sub End Sub
Private Sub _Watcher_Changed(ByVal sender As Object, Private Sub WatcherChanged_New(ByVal sender As Object, ByVal e As EventArgs) Handles _Watcher.Changed
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() clsHotkey.GetCaption()
@ -71,15 +98,32 @@ Public Class frmStart
oMatch = oRegex.Match(CURR_FOCUSED_WINDOWNAME) oMatch = oRegex.Match(CURR_FOCUSED_WINDOWNAME)
oMatchWindow = oMatch.Success oMatchWindow = oMatch.Success
If oMatchWindow = True Then If oMatchWindow = True Then
Dim oMatchRegexWindowClipboard As Boolean = False
Logger.Debug($"Found a match on windowtitle [{CURR_FOCUSED_WINDOWNAME}]") Logger.Debug($"Found a match on windowtitle [{CURR_FOCUSED_WINDOWNAME}]")
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 Exit For
End If End If
End If End If
End If
End If
Next Next
If oMatchWindow = False Then If oMatchWindow = False Then
Logger.Debug($"Found NO MATCH on windowtitle [{CURR_FOCUSED_WINDOWNAME}], but [{oCountWindowDefinitions}] definitions are configured") Logger.Debug($"Found NO MATCH on windowtitle [{CURR_FOCUSED_WINDOWNAME}], but [{oCountWindowDefinitions}] definitions are configured")
Exit For Exit For
End If End If
' ================= MOVE TO CTRL + F =================
'CURR_MATCH_WM_SEARCH = oProfileRow.Item("WD_SEARCH") 'CURR_MATCH_WM_SEARCH = oProfileRow.Item("WD_SEARCH")
Dim oSQL_COUNT As String = oProfileRow.Item("SQL_COUNT_RESULT") Dim oSQL_COUNT As String = oProfileRow.Item("SQL_COUNT_RESULT")
Dim oRESULTDocs As Integer Dim oRESULTDocs As Integer
@ -103,6 +147,8 @@ Public Class frmStart
oFound = True oFound = True
End If End If
' ================= MOVE TO CTRL + F =================
End If End If
'Else 'Else
@ -222,33 +268,50 @@ Public Class frmStart
End Sub End Sub
Private Sub ReceiveHotKey(ByVal HotKeyID As String) Handles Hotkey.HotKeyPressed Private Sub ReceiveHotKey(ByVal HotKeyID As String) Handles Hotkey.HotKeyPressed
If HotKeyID = 354523017 Then 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() CHECK_PROFILE_MATCH()
End If 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 ElseIf HotKeyID = 354522017 Then
Change_Monitoring_State() Change_Monitoring_State()
End If End If
End Sub End Sub
Sub CHECK_PROFILE_MATCH() Sub CHECK_PROFILE_MATCH()
If CurrDT_PROFILE_MATCH.Rows.Count = 1 Then Dim oProfiles = CURRENT_MATCHING_PROFILES
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) For Each oProfile In oProfiles
Exit Sub Dim oSQL = oProfile.CountSQL
ElseIf CurrDT_PROFILE_MATCH.Rows(0).Item("COUNT") = 99998 Then Dim oResultDocs As Integer = 0
NotifyIconMain.ShowBalloonTip(10000, "Clipboard Watcher", "Found match but MatchCountConfig is not configured!", ToolTipIcon.Info)
If oSQL = String.Empty Then
oProfile.CountSQL = 99998
End If 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() frmResultDoc.Show()
'frmProfileMatch.ShowDialog()
'clsSearch.RUN_WD_SEARCH(CURR_MATCH_WM_SEARCH)
Else Else
frmProfileMatch.ShowDialog() frmProfileMatch.ShowDialog()
End If End If

View File

@ -47,6 +47,8 @@ Module modCurrent
Public DT_USER_PROFILES As DataTable Public DT_USER_PROFILES As DataTable
Public CLIPBOARD_TEXT As String Public CLIPBOARD_TEXT As String
Public CURRENT_MATCHING_PROFILES As List(Of ClassProfileFilter.ProfileData)
Public CURR_MATCH_RESULT Public CURR_MATCH_RESULT
'Public CURR_MATCH_WM_SEARCH 'Public CURR_MATCH_WM_SEARCH
Public CURR_FOCUSED_WINDOWNAME Public CURR_FOCUSED_WINDOWNAME