198 lines
8.0 KiB
VB.net
198 lines
8.0 KiB
VB.net
Imports DevExpress.XtraSplashScreen
|
|
Imports DigitalData.Modules.Logging
|
|
Imports DigitalData.Modules.Windows
|
|
Imports DigitalData.Modules.ZooFlow
|
|
Imports DevExpress.LookAndFeel
|
|
Imports DigitalData.Products.ClipboardWatcher
|
|
Imports DigitalData.Modules.ZooFlow.Params
|
|
Imports System.Threading.Tasks
|
|
Imports DigitalData.Modules.Messaging
|
|
|
|
Partial Public Class frmMain
|
|
Private WithEvents FlowForm As frmFlowForm
|
|
|
|
Private Init As ClassInit
|
|
Private Loading As Boolean = True
|
|
Private Logger As Logger = My.LogConfig.GetLogger
|
|
Private MatchingProfiles As List(Of ProfileData)
|
|
|
|
Public Sub New()
|
|
InitializeComponent()
|
|
End Sub
|
|
|
|
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
' === Initialization ===
|
|
Init = New ClassInit(My.LogConfig, Me)
|
|
AddHandler Init.Completed, AddressOf Init_Completed
|
|
Init.InitializeApplication()
|
|
|
|
' === Layout and Skin ===
|
|
UserLookAndFeel.Default.SetSkinStyle(My.UIConfig.SkinName)
|
|
|
|
' === Register As Event Listener ===
|
|
EventBus.Instance.Register(Me)
|
|
End Sub
|
|
|
|
Private Sub frmMain_FormClosed(sender As Object, e As FormClosedEventArgs) Handles Me.FormClosed
|
|
EventBus.Instance.Unregister(Me)
|
|
End Sub
|
|
|
|
Public Sub OnEvent(e As OnFlowFormInteractionEvent)
|
|
Select Case e.Interaction
|
|
Case OnFlowFormInteractionEvent.FlowFormInteraction.Click
|
|
Dim oEnvironment As New Environment() With {
|
|
.User = My.Application.User,
|
|
.Modules = My.Application.Modules
|
|
}
|
|
Dim oParams As New ClipboardWatcherParams() With {
|
|
.MatchingProfiles = MatchingProfiles
|
|
}
|
|
Dim oForm As New frmMatch(My.LogConfig, oEnvironment, oParams)
|
|
oForm.Show()
|
|
End Select
|
|
End Sub
|
|
|
|
Private Sub Init_Completed(sender As Object, e As EventArgs)
|
|
' === Initialization Complete ===
|
|
Loading = False
|
|
SplashScreenManager.CloseForm(False)
|
|
|
|
' === Setup Timers ===
|
|
AddHandler TimerRefreshData.Tick, AddressOf TimerRefreshData_Tick
|
|
TimerRefreshData.Enabled = True
|
|
|
|
' === Setup Flow Form ===
|
|
FlowForm = New frmFlowForm(My.Application.ModulesActive)
|
|
FlowForm.Show()
|
|
|
|
' === Load Data ===
|
|
RefreshData()
|
|
End Sub
|
|
|
|
Private Sub TimerRefreshData_Tick(sender As Object, e As EventArgs)
|
|
RefreshData()
|
|
End Sub
|
|
|
|
Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown
|
|
Hide()
|
|
End Sub
|
|
|
|
Private Async Sub FlowForm_ClipboardChangedAsync(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
|
|
End If
|
|
|
|
Dim oProfileFilter As ClassProfileFilter
|
|
Dim oMatchingProfiles As List(Of ProfileData)
|
|
Dim oWindow As New Window(My.LogConfig)
|
|
Dim oWindowInfo = oWindow.GetWindowInfo()
|
|
Dim oFocusedControl As IntPtr = oWindow.FocusedControlinActiveWindow(Handle)
|
|
Dim oClipboardContents As String = Clipboard.GetText()
|
|
|
|
Try
|
|
oProfileFilter = New ClassProfileFilter(My.LogConfig,
|
|
My.Application.ClipboardWatcher.UserProfiles,
|
|
My.Application.ClipboardWatcher.ProfileProcesses,
|
|
My.Application.ClipboardWatcher.ProfileWindows,
|
|
My.Application.ClipboardWatcher.ProfileControls)
|
|
|
|
oMatchingProfiles = oProfileFilter.Profiles
|
|
Logger.Debug("Profiles before filtering: {0}", oMatchingProfiles.Count)
|
|
oMatchingProfiles = oProfileFilter.FilterProfilesByClipboardRegex(oMatchingProfiles, oClipboardContents)
|
|
Logger.Debug("Profiles after FilterProfilesByClipboardRegex: {0}", oMatchingProfiles.Count)
|
|
oMatchingProfiles = oProfileFilter.FilterProfilesByProcess(oMatchingProfiles, oWindowInfo.ProcessName)
|
|
Logger.Debug("Profiles after FilterProfilesByProcess: {0}", oMatchingProfiles.Count)
|
|
oMatchingProfiles = oProfileFilter.FilterWindowsByWindowTitleRegex(oMatchingProfiles, oWindowInfo.WindowTitle)
|
|
Logger.Debug("Profiles after FilterWindowsByWindowTitleRegex: {0}", oMatchingProfiles.Count)
|
|
oMatchingProfiles = oProfileFilter.FilterProfilesByFocusedControl(oMatchingProfiles, oClipboardContents, oFocusedControl.ToString)
|
|
Logger.Debug("Profiles after FilterProfilesByFocusedControl: {0}", oMatchingProfiles.Count)
|
|
oMatchingProfiles = Await Task.Run(Function() oProfileFilter.FilterProfilesBySearchResults(oMatchingProfiles))
|
|
Logger.Debug("Profiles after FilterProfilesBySearchResults: {0}", oMatchingProfiles.Count)
|
|
oMatchingProfiles = oProfileFilter.ClearNotMatchedProfiles(oMatchingProfiles)
|
|
Logger.Debug("Profiles after ClearNotMatchedProfiles: {0}", oMatchingProfiles.Count)
|
|
|
|
oMatchingProfiles = oMatchingProfiles.ToList()
|
|
Catch ex As Exception
|
|
MsgBox("Fehler beim Laden der Profile. Möglicherweise liegt ein Konfigurationsfehler vor.", MsgBoxStyle.Critical, Text)
|
|
Exit Sub
|
|
End Try
|
|
|
|
If oMatchingProfiles.Count = 0 Then
|
|
Logger.Warn("No matching Profiles found")
|
|
Exit Sub
|
|
End If
|
|
|
|
MatchingProfiles = oMatchingProfiles
|
|
|
|
EventBus.Instance.PostEvent(New OnFlowFormStateChangedEvent(OnFlowFormStateChangedEvent.FlowFormState.HasSearchResults))
|
|
End Sub
|
|
|
|
#Region "Notify Icon Menu"
|
|
Private Sub BeendenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles BeendenToolStripMenuItem.Click
|
|
Application.Exit()
|
|
End Sub
|
|
|
|
Private Sub NotifyIconMain_DoubleClick(sender As Object, e As EventArgs) Handles NotifyIconMain.DoubleClick
|
|
ToggleVisibility()
|
|
End Sub
|
|
|
|
Private Sub AnzeigenVersteckenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AnzeigenVersteckenToolStripMenuItem.Click
|
|
ToggleVisibility()
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
#End Region
|
|
|
|
Private Sub ToggleVisibility()
|
|
If Visible Then
|
|
Hide()
|
|
Else
|
|
Show()
|
|
BringToFront()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub ButtonSettings_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles ButtonSettings.ItemClick
|
|
frmSettings.ShowDialog()
|
|
End Sub
|
|
|
|
Private Sub ButtonExit_ItemClick(sender As Object, e As DevExpress.XtraBars.ItemClickEventArgs) Handles ButtonExit.ItemClick
|
|
|
|
End Sub
|
|
|
|
Private Sub frmMain_StyleChanged(sender As Object, e As EventArgs) Handles Me.StyleChanged
|
|
If Loading = False Then
|
|
My.UIConfig.SkinName = LookAndFeel.ActiveSkinName
|
|
My.UIConfigManager.Save()
|
|
End If
|
|
End Sub
|
|
|
|
Public Sub RefreshData()
|
|
Try
|
|
Dim oUserId As Integer = My.Application.User.UserId
|
|
Dim oSql As String = My.Queries.ClipboardWatcher.VWCW_USER_PROFILE(oUserId)
|
|
My.Application.ClipboardWatcher.UserProfiles = My.Database.GetDatatable(oSql)
|
|
|
|
If My.Application.ClipboardWatcher.UserProfiles.Rows.Count = 0 Then
|
|
MsgBox("No profiles configured for this user so far!", MsgBoxStyle.Exclamation)
|
|
Else
|
|
oSql = My.Queries.ClipboardWatcher.TBCW_PROFILE_PROCESS(oUserId)
|
|
My.Application.ClipboardWatcher.ProfileProcesses = My.Database.GetDatatable(oSql)
|
|
|
|
oSql = My.Queries.ClipboardWatcher.VWCW_PROFILE_REL_WINDOW(oUserId)
|
|
My.Application.ClipboardWatcher.ProfileWindows = My.Database.GetDatatable(oSql)
|
|
|
|
oSql = My.Queries.ClipboardWatcher.VWCW_PROFILE_REL_CONTROL(oUserId)
|
|
My.Application.ClipboardWatcher.ProfileControls = My.Database.GetDatatable(oSql)
|
|
End If
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
End Try
|
|
End Sub
|
|
|
|
|
|
End Class
|