This commit is contained in:
Jonathan Jenne
2019-09-24 16:53:31 +02:00
parent 16a7d5b915
commit cc2d8cbe33
22 changed files with 655 additions and 70 deletions

View File

@@ -94,21 +94,15 @@ Public Class ClassFlowForm
Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs)
AddHandler MouseDown, New MouseEventHandler(AddressOf Form_MouseDown)
'AddHandler MouseDown, New MouseEventHandler(AddressOf Form_MouseDown)
End Sub
Private Sub Form_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
Win32.ReleaseCapture()
Win32.SendMessage(Handle, Win32.WM_NCLBUTTONDOWN, Win32.HTCAPTION, 0)
End If
End Sub
Private Sub Form_click(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseClick
If e.Button = MouseButtons.Left Then
MsgBox("LOL")
End If
End Sub
'Private Sub Form_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
' If e.Button = MouseButtons.Left Then
' Win32.ReleaseCapture()
' Win32.SendMessage(Handle, Win32.WM_NCLBUTTONDOWN, Win32.HTCAPTION, 0)
' End If
'End Sub
Public Sub SetBitmap(ByVal bitmap As Bitmap)
SetBitmap(bitmap, 255, bitmap.Width, bitmap.Height)

View File

@@ -1,302 +0,0 @@
Imports System.Text.RegularExpressions
Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.ZooFlow
''' <summary>
''' Defines common Functions for Checking for and replacing placeholders.
''' This Class also includes a child class `Pattern` for passing around Patterns.
'''
''' The format of all placeholders is:
''' {#TYPE#VALUE}
'''
''' Some Examples:
''' {#INT#USERNAME}
''' {#CTRL#CMB_2}
''' {#WMI#String 39}
''' </summary>
Public Class ClassPatterns
' Complex patterns that rely on a datasource like a Database or Windream
Public Const PATTERN_WMI = "WMI"
Public Const PATTERN_CTRL = "CTRL"
' Simple patterns that only rely on .NET functions
Public Const PATTERN_INT = "INT"
' Simple patterns that rely on Data from the TBDD_USER table
Public Const PATTERN_USER = "USER"
Public Const USER_VALUE_PRENAME = "PRENAME"
Public Const USER_VALUE_SURNAME = "SURNAME"
Public Const USER_VALUE_EMAIL = "EMAIL"
Public Const USER_VALUE_SHORTNAME = "SHORTNAME"
Public Const USER_VALUE_USER_ID = "USER_ID"
Public Const USER_VALUE_PROFILE_ID = "PROFILE_ID"
Public Const INT_VALUE_USERNAME = "USERNAME"
Public Const INT_VALUE_MACHINE = "MACHINE"
Public Const INT_VALUE_DOMAIN = "DOMAIN"
Public Const INT_VALUE_DATE = "DATE"
Public Const CLIPBOARD_VALUE_DE = "@Zwischenablage"
Public Const CLIPBOARD_VALUE_EN = "@Clipboard"
Public Const MAX_TRY_COUNT = 100
Private _Logger As Logger
Private _LogConfig As LogConfig
Private _Regex As Regex = New Regex("{#(\w+)#([\w\s_-]+)}+")
Private _AllPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL, PATTERN_USER, PATTERN_INT}
Private _ComplexPatterns As New List(Of String) From {PATTERN_WMI, PATTERN_CTRL}
Private _SimplePatterns As New List(Of String) From {PATTERN_USER, PATTERN_INT}
''' <summary>
''' Wraps a pattern-type and -value in the common format: {#type#value}
''' </summary>
Public Function WrapPatternValue(type As String, value As String) As String
Return New Pattern(type, value).ToString
End Function
Public Sub New(LogConfig As LogConfig)
_LogConfig = LogConfig
_Logger = LogConfig.GetLogger
End Sub
Public Function ReplaceAllValues(input As String, User As State.UserState) As String
Try
Dim result = input
result = ReplaceInternalValues(result)
result = ReplaceUserValues(result, User)
Return result
Catch ex As Exception
_Logger.Error(ex)
_Logger.Warn("Error in ReplaceAllValues:" & ex.Message)
Return input
End Try
End Function
Public Function ReplaceClipboardContents(Input As String, ClipboardContents As String) As String
Dim oResult = Input
oResult = oResult.Replace(CLIPBOARD_VALUE_DE.ToLower, ClipboardContents)
oResult = oResult.Replace(CLIPBOARD_VALUE_DE.ToUpper, ClipboardContents)
oResult = oResult.Replace(CLIPBOARD_VALUE_EN.ToLower, ClipboardContents)
oResult = oResult.Replace(CLIPBOARD_VALUE_EN.ToUpper, ClipboardContents)
Return oResult
End Function
Public Function ReplaceInternalValues(Input As String) As String
Try
Dim oResult = Input
' Replace Username(s)
While ContainsPatternAndValue(oResult, PATTERN_INT, INT_VALUE_USERNAME)
oResult = ReplacePattern(oResult, PATTERN_INT, System.Environment.UserName)
End While
' Replace Machinename(s)
While ContainsPatternAndValue(oResult, PATTERN_INT, INT_VALUE_MACHINE)
oResult = ReplacePattern(oResult, PATTERN_INT, System.Environment.MachineName)
End While
' Replace Domainname(s)
While ContainsPatternAndValue(oResult, PATTERN_INT, INT_VALUE_DOMAIN)
oResult = ReplacePattern(oResult, PATTERN_INT, System.Environment.UserDomainName)
End While
' Replace CurrentDate(s)
While ContainsPatternAndValue(oResult, PATTERN_INT, INT_VALUE_DATE)
oResult = ReplacePattern(oResult, PATTERN_INT, Now.ToShortDateString)
End While
Return oResult
Catch ex As Exception
_Logger.Error(ex)
_Logger.Warn("Error in ReplaceInternalValues:" & ex.Message)
Return Input
End Try
End Function
Public Function ReplaceUserValues(Input As String, User As State.UserState) As String
Try
Dim oResult = Input
While ContainsPatternAndValue(oResult, PATTERN_USER, USER_VALUE_PRENAME)
oResult = ReplacePattern(Input, PATTERN_USER, User.GivenName)
End While
While ContainsPatternAndValue(oResult, PATTERN_USER, USER_VALUE_USER_ID)
oResult = ReplacePattern(Input, PATTERN_USER, User.UserId.ToString)
End While
While ContainsPatternAndValue(oResult, PATTERN_USER, USER_VALUE_SURNAME)
oResult = ReplacePattern(Input, PATTERN_USER, User.Surname)
End While
While ContainsPatternAndValue(oResult, PATTERN_USER, USER_VALUE_SHORTNAME)
oResult = ReplacePattern(Input, PATTERN_USER, User.ShortName)
End While
While ContainsPatternAndValue(oResult, PATTERN_USER, USER_VALUE_EMAIL)
oResult = ReplacePattern(Input, PATTERN_USER, User.Email)
End While
Return oResult
Catch ex As Exception
_Logger.Error(ex)
_Logger.Warn("Error in ReplaceUserValues:" & ex.Message)
Return Input
End Try
End Function
Public Function ReplaceControlValues(Input As String, Panel As Panel) As String
Try
Dim oResult = Input
Dim oTryCounter = 0
While ContainsPattern(oResult, PATTERN_CTRL)
If oTryCounter > MAX_TRY_COUNT Then
Throw New Exception("Max tries in ReplaceControlValues exceeded.")
End If
Dim controlName As String = GetNextPattern(oResult, PATTERN_CTRL).Value
Dim control As Control = Panel.Controls.Find(controlName, False).FirstOrDefault()
If control IsNot Nothing Then
Dim value As String = control.Text
oResult = ReplacePattern(oResult, PATTERN_CTRL, value)
End If
oTryCounter += 1
End While
Return oResult
Catch ex As Exception
_Logger.Error(ex)
_Logger.Warn("Error in ReplaceControlValues:" & ex.Message)
Return Input
End Try
End Function
Private Function ContainsPattern(input As String, type As String) As Boolean
Dim elements As MatchCollection = _Regex.Matches(input)
For Each element As Match In elements
Dim t As String = element.Groups(1).Value
If t = type Then
Return True
End If
Next
Return False
End Function
Public Function GetNextPattern(Input As String, Type As String) As Pattern
Dim oElements As MatchCollection = _Regex.Matches(Input)
For Each oElement As Match In oElements
' Pattern in input
Dim oType As String = oElement.Groups(1).Value
Dim oValue As String = oElement.Groups(2).Value
If oType = Type Then
Return New Pattern(oType, oValue)
End If
Next
Return Nothing
End Function
Public Function GetAllPatterns(Input As String) As List(Of Pattern)
Dim elements As MatchCollection = _Regex.Matches(Input)
Dim results As New List(Of Pattern)
For Each element As Match In elements
' Pattern in input
Dim t As String = element.Groups(1).Value
Dim v As String = element.Groups(2).Value
results.Add(New Pattern(t, v))
Next
Return results
End Function
Public Function ReplacePattern(Input As String, Type As String, Replacement As String) As String
Dim oElements As MatchCollection = _Regex.Matches(Input)
If IsNothing(Replacement) Or Replacement = String.Empty Then
Return Input
End If
For Each element As Match In oElements
' if group 1 contains the 'pattern' the replace whole group with 'replacement'
' and return it
If element.Groups(1).Value = Type Then
Return Regex.Replace(Input, element.Groups(0).Value, Replacement)
End If
Next
' no replacement made
Return Input
End Function
Private Function ContainsPatternAndValue(Input As String, Type As String, Value As String) As Boolean
Dim oElements As MatchCollection = _Regex.Matches(Input)
For Each oElement As Match In oElements
' Pattern in input
Dim oType As String = oElement.Groups(1).Value
Dim oValue As String = oElement.Groups(2).Value
If oType = Type And oValue = Value Then
Return True
End If
Next
Return False
End Function
Public Function HasAnyPatterns(Input As String) As Boolean
Return _AllPatterns.Any(Function(p)
Return HasPattern(Input, p)
End Function)
End Function
Public Function HasOnlySimplePatterns(Input As String) As Boolean
Return Not HasComplexPatterns(Input)
End Function
Public Function HasComplexPatterns(Input As String) As Boolean
Return _ComplexPatterns.Any(Function(oPattern)
Return HasPattern(Input, oPattern)
End Function)
End Function
Public Function HasPattern(Input As String, Type As String) As Boolean
Dim oMatches = _Regex.Matches(Input)
For Each oMatch As Match In oMatches
For Each oGroup As Group In oMatch.Groups
If oGroup.Value = Type Then
Return True
End If
Next
Next
Return False
End Function
Public Class Pattern
Public ReadOnly Property Type As String
Public ReadOnly Property Value As String
Public Sub New(Type As String, Value As String)
Me.Type = Type
Me.Value = Value
End Sub
Public Overrides Function ToString() As String
Return $"{{#{Type}#{Value}}}"
End Function
End Class
End Class

View File

@@ -7,6 +7,14 @@
Return $"SELECT T.* FROM TBCW_PROFILE_PROCESS T, VWCW_USER_PROFILE T1 WHERE T.PROFILE_ID = T1.GUID AND T1.USER_ID = {UserId}"
End Function
Public Function TBCW_PROF_DATA_SEARCH(ProfileId As Integer) As String
Return $"SELECT COUNT_COMMAND FROM TBCW_PROF_DATA_SEARCH WHERE ACTIVE = 1 AND PROFILE_ID = {ProfileId}"
End Function
Public Function TBCW_PROF_DOC_SEARCH(ProfileId As Integer) As String
Return $"SELECT COUNT_COMMAND FROM TBCW_PROF_DOC_SEARCH WHERE ACTIVE = 1 AND PROFILE_ID = {ProfileId}"
End Function
Public Function VWCW_PROFILE_REL_WINDOW(UserId As Integer) As String
Return $"SELECT * FROM VWCW_PROFILE_REL_WINDOW WHERE USER_ID = {UserId}"
End Function

View File

@@ -89,7 +89,6 @@
<Compile Include="Base\BaseClass.vb" />
<Compile Include="ClassClipboardWatcher.vb" />
<Compile Include="ClassInit.vb" />
<Compile Include="ClassPatterns.vb" />
<Compile Include="ClipboardWatcher\State.vb" />
<Compile Include="Events\OnFlowFormInteractionEvent.vb" />
<Compile Include="Events\OnFlowFormStateChangedEvent.vb" />

View File

@@ -4,6 +4,8 @@ Public Class frmFlowForm
Private WithEvents Watcher As ClassClipboardWatcher = ClassClipboardWatcher.Singleton
Private ActiveModules As List(Of String)
Private CurrentState As OnFlowFormStateChangedEvent.FlowFormState = OnFlowFormStateChangedEvent.FlowFormState.Default
Public Event ClipboardChanged As EventHandler(Of IDataObject)
Public Sub New(ActiveModules As List(Of String))
@@ -20,6 +22,9 @@ Public Class frmFlowForm
ShowInTaskbar = False
SetFlowFormState(OnFlowFormStateChangedEvent.FlowFormState.Default)
' === Register Events ===
AddHandler Click, AddressOf frmFlowForm_Click
' === Register As Event Listener ===
EventBus.Instance.Register(Me)
End Sub
@@ -28,10 +33,15 @@ Public Class frmFlowForm
EventBus.Instance.Unregister(Me)
End Sub
Private Sub frmFlowForm_Click(sender As Object, e As EventArgs) Handles Me.MouseClick
EventBus.Instance.PostEvent(New OnFlowFormInteractionEvent(OnFlowFormInteractionEvent.FlowFormInteraction.Click))
Private Sub frmFlowForm_Click(sender As Object, e As EventArgs)
If CurrentState = OnFlowFormStateChangedEvent.FlowFormState.HasSearchResults Then
SetFlowFormState(OnFlowFormStateChangedEvent.FlowFormState.Default)
EventBus.Instance.PostEvent(New OnFlowFormInteractionEvent(OnFlowFormInteractionEvent.FlowFormInteraction.Click))
End If
End Sub
Public Sub OnEvent(e As OnFlowFormStateChangedEvent)
CurrentState = e.State
SetFlowFormState(e.State)
End Sub

View File

@@ -78,7 +78,7 @@ Partial Public Class frmMain
Hide()
End Sub
Private Sub FlowForm_ClipboardChanged(sender As Object, e As IDataObject) Handles FlowForm.ClipboardChanged
Private Async Sub FlowForm_ClipboardChanged(sender As Object, e As IDataObject) Handles FlowForm.ClipboardChanged
If My.Application.ClipboardWatcher.UserProfiles.Rows.Count = 0 Then
Logger.Warn("Clipboard Changed but no profiles configured!")
Exit Sub
@@ -88,14 +88,6 @@ Partial Public Class frmMain
Dim oMatchingProfiles As List(Of ProfileData)
Dim oWindow As New Window(My.LogConfig)
Dim oWindowInfo = oWindow.GetWindowInfo()
Dim oControls As New Dictionary(Of String, Window.RectangleInfo) From {
{"TOPLEFT", New Window.RectangleInfo() With {.Left = 20, .Top = 43}}
}
Dim oControl = oWindow.GetFocusedControlLocation(Handle, Window.Anchor.TopLeft)
Dim oFocusedControl As Window.WindowInfo = oWindow.GetFocusedControl(Handle)
Dim oClipboardContents As String = Clipboard.GetText()
Try
@@ -113,7 +105,12 @@ Partial Public Class frmMain
oMatchingProfiles = oProfileFilter.FilterProfilesByProcess(oMatchingProfiles, oWindowInfo.ProcessName)
oMatchingProfiles = oProfileFilter.FilterWindowsByWindowTitleRegex(oMatchingProfiles, oWindowInfo.WindowTitle)
oMatchingProfiles = oProfileFilter.FilterProfilesByFocusedControlLocation(oMatchingProfiles, oClipboardContents, Handle)
'oMatchingProfiles = Await Task.Run(Function() oProfileFilter.FilterProfilesBySearchResults(oMatchingProfiles))
oMatchingProfiles = Await Task.Run(Function()
Return oProfileFilter.FilterProfilesBySearchResults(
oMatchingProfiles,
My.Database,
My.Application.User)
End Function)
oMatchingProfiles = oProfileFilter.ClearNotMatchedProfiles(oMatchingProfiles)
oMatchingProfiles = oMatchingProfiles.ToList()