289 lines
12 KiB
VB.net
289 lines
12 KiB
VB.net
Imports System.Threading
|
|
Imports System.IO
|
|
Imports DD_LIB_Standards
|
|
|
|
Public Class frmStart
|
|
Dim WithEvents Hotkey As New clsHotkey(Me)
|
|
Private WithEvents _Watcher As ClipboardWatcher = ClipboardWatcher.Singleton
|
|
|
|
Private Sub frmClipboardWatch_Disposed(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Disposed
|
|
_Watcher.Dispose()
|
|
End Sub
|
|
|
|
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.Profiles.AsEnumerable()
|
|
|
|
oProfiles = oProfileFilter.FilterProfilesByProcess(oProfiles, CurrPROC_Name)
|
|
oProfiles = oProfileFilter.FilterProfilesByClipboardRegex(oProfiles, ClipboardContents)
|
|
oProfiles = oProfileFilter.FilterWindowsByWindowTitleRegex(oProfiles, WindowTitle)
|
|
oProfiles = oProfileFilter.FilterProfilesByWindowClipboardRegex(oProfiles, ClipboardContents)
|
|
oProfiles = oProfileFilter.RemoveDuplicateProfiles()
|
|
oProfiles = oProfiles.ToList()
|
|
|
|
CURRENT_MATCHING_PROFILES = oProfiles
|
|
CURRENT_CLIPBOARD_CONTENTS = ClipboardContents
|
|
End Sub
|
|
|
|
Public Sub New()
|
|
Dim splash As New frmSplash()
|
|
splash.ShowDialog()
|
|
If ERROR_INIT <> "INVALID USER" Then
|
|
Dim cultureInfo As System.Globalization.CultureInfo
|
|
cultureInfo = New System.Globalization.CultureInfo(USER_LANGUAGE)
|
|
'cultureInfo.DateTimeFormat.ShortDatePattern = USER_DATE_FORMAT
|
|
Thread.CurrentThread.CurrentCulture = cultureInfo
|
|
Thread.CurrentThread.CurrentUICulture = cultureInfo
|
|
Globalization.CultureInfo.DefaultThreadCurrentCulture = cultureInfo
|
|
Globalization.CultureInfo.DefaultThreadCurrentUICulture = cultureInfo
|
|
End If
|
|
' Dieser Aufruf ist für den Designer erforderlich.
|
|
InitializeComponent()
|
|
|
|
' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
|
|
|
|
End Sub
|
|
|
|
Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
|
|
Logger.Info(">> Logout time: " & Now.ToString, False)
|
|
If ERROR_INIT = "INVALID USER" Or ERROR_INIT = "NO CLIENT" Then
|
|
Exit Sub
|
|
End If
|
|
Try
|
|
Dim sql = "DELETE FROM TBDD_USER_MODULE_LOG_IN WHERE USER_ID = " & USER_ID & " AND UPPER(MODULE) = UPPER('Clipboard-Watcher')"
|
|
clsDatabase.Execute_non_Query(sql, True)
|
|
ClassWindowLocation.SaveFormLocationSize(Me, "")
|
|
My.Settings.Save()
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
Try
|
|
Hotkey.RemoveHotKey(ClassConstants.HOTKEY_TOGGLE_WATCHER)
|
|
Hotkey.RemoveHotKey(ClassConstants.HOTKEY_TRIGGER_WATCHER)
|
|
Catch ex As Exception
|
|
Logger.Error(ex)
|
|
Logger.Warn("Hotkeys could not be removed")
|
|
End Try
|
|
|
|
'TempDateien löschen
|
|
For Each oFile In TEMP_FILES
|
|
Try
|
|
File.Delete(oFile)
|
|
Catch ex As Exception
|
|
Logger.Warn("Temp file {0} could not be deleted", oFile)
|
|
Logger.Error(ex)
|
|
End Try
|
|
Next
|
|
End Sub
|
|
|
|
Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles Me.Load
|
|
ClassWindowLocation.LoadFormLocationSize(Me)
|
|
If ERROR_INIT = "FAILED DBCONNECTION" Or ERROR_INIT = "DATABASE" Then
|
|
frmConfig_Basic.ShowDialog()
|
|
End If
|
|
|
|
If clsDatabase.DB_DEFAULT_INITIALIZED = True Then
|
|
If ERROR_INIT <> "" Then
|
|
If ERROR_INIT = "NO CLIENT" Then
|
|
MsgBox("You are not related to a client!" & vbNewLine & "Please contact the system administrator!", MsgBoxStyle.Exclamation)
|
|
Else
|
|
MsgBox("Sorry Something went wrong in user configuration!" & vbNewLine & "Reason: " & ERROR_INIT & vbNewLine & "Please contact the system administrator!", MsgBoxStyle.Exclamation)
|
|
End If
|
|
Exit Sub
|
|
End If
|
|
NotifyIconMain.Visible = True
|
|
clsHotkey.Refresh_Profile_Links()
|
|
Hotkey.AddHotKey(Keys.T, clsHotkey.MODKEY.MOD_CONTROL, ClassConstants.HOTKEY_TOGGLE_WATCHER)
|
|
Dim oKeyCode As Keys
|
|
Dim oConverter As New KeysConverter
|
|
Dim oObject As Object = oConverter.ConvertFromString(HotkeySearchKey.ToUpper)
|
|
oKeyCode = CType(oObject, Keys)
|
|
|
|
If HotkeyFunctionKey = ClassConstants.HOTKEY_CTRL Then
|
|
Hotkey.AddHotKey(oKeyCode, clsHotkey.MODKEY.MOD_CONTROL, ClassConstants.HOTKEY_TRIGGER_WATCHER)
|
|
ElseIf HotkeyFunctionKey = "SHIFT" Then
|
|
Hotkey.AddHotKey(oKeyCode, clsHotkey.MODKEY.MOD_SHIFT, ClassConstants.HOTKEY_TRIGGER_WATCHER)
|
|
End If
|
|
|
|
End If
|
|
tslblUser.Text = USER_USERNAME
|
|
labelHotkey.Text = $"STRG+C {HotkeyFunctionKey.ToUpper}+{HotkeySearchKey.ToUpper}"
|
|
End Sub
|
|
Private Sub ReceiveHotKey(ByVal HotKeyID As String) Handles Hotkey.HotKeyPressed
|
|
If HotKeyID = ClassConstants.HOTKEY_TRIGGER_WATCHER Then
|
|
If CURRENT_MATCHING_PROFILES.Count > 0 And MONITORING_ACTIVE = True Then
|
|
CHECK_PROFILE_MATCH()
|
|
End If
|
|
ElseIf HotKeyID = ClassConstants.HOTKEY_TOGGLE_WATCHER Then
|
|
Change_Monitoring_State()
|
|
End If
|
|
|
|
End Sub
|
|
Sub CHECK_PROFILE_MATCH()
|
|
Dim oProfiles = CURRENT_MATCHING_PROFILES
|
|
Dim oInvalidDocumentSQL = False
|
|
Dim oInvalidDataSQL = False
|
|
|
|
For Each oProfile In oProfiles
|
|
Dim oDocumentSQL = oProfile.SQLCountDocs
|
|
Dim oDataSQL = oProfile.SQLCountData
|
|
Dim oResultDocs As Integer = 0
|
|
Dim oResultData As Integer = 0
|
|
|
|
Dim oDataSearches As DataTable = clsDatabase.Return_Datatable($"SELECT COUNT_COMMAND FROM TBCW_PROF_DATA_SEARCH WHERE PROFILE_ID = {oProfile.Guid}")
|
|
Dim oDocSearches As DataTable = clsDatabase.Return_Datatable($"SELECT COUNT_COMMAND FROM TBCW_PROF_DOC_SEARCH WHERE PROFILE_ID = {oProfile.Guid}")
|
|
|
|
For Each oRow As DataRow In oDataSearches.Rows
|
|
Try
|
|
Dim oCountCommand = oRow.Item("COUNT_COMMAND")
|
|
|
|
If oCountCommand = String.Empty Then
|
|
Continue For
|
|
End If
|
|
|
|
oDataSQL = clsPatterns.ReplaceAllValues(oCountCommand, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfile.Guid)
|
|
oResultData += ClassDatabase.Execute_Scalar(oDataSQL, MyConnectionString)
|
|
Catch ex As Exception
|
|
Logger.Warn("Invalid SQL Query for Counting Data in Profile {0}: {1}", oProfile.Guid, oDataSQL)
|
|
oInvalidDataSQL = True
|
|
End Try
|
|
Next
|
|
|
|
For Each oRow As DataRow In oDocSearches.Rows
|
|
Try
|
|
Dim oCountCommand = oRow.Item("COUNT_COMMAND")
|
|
|
|
If oCountCommand = String.Empty Then
|
|
Continue For
|
|
End If
|
|
|
|
oDataSQL = clsPatterns.ReplaceAllValues(oCountCommand, USER_PRENAME, USER_SURNAME, USER_SHORTNAME, USER_EMAIL, USER_ID, oProfile.Guid)
|
|
oResultDocs += ClassDatabase.Execute_Scalar(oDataSQL, MyConnectionString)
|
|
Catch ex As Exception
|
|
oInvalidDocumentSQL = True
|
|
Logger.Warn("Invalid SQL Query for Counting Data in Profile {0}: {1}", oProfile.Guid, oDataSQL)
|
|
End Try
|
|
Next
|
|
|
|
oProfile.CountData = oResultData
|
|
oProfile.CountDocs = oResultDocs
|
|
Next
|
|
|
|
If oInvalidDocumentSQL Or oInvalidDataSQL Then
|
|
MsgBox("Ein oder mehrere Abfragen konnten nicht ausgeführt werden. Bitte überprüfen Sie das Log.", MsgBoxStyle.Exclamation, "Warnung")
|
|
End If
|
|
|
|
Dim oForm As New frmProfileMatch()
|
|
oForm.ShowDialog()
|
|
End Sub
|
|
Sub Change_Monitoring_State()
|
|
If MONITORING_ACTIVE = True Then
|
|
NotifyIconMain.ShowBalloonTip(30000, "Clipboard Watcher", "Clipboard-Watcher wurde inaktiviert!", ToolTipIcon.Info)
|
|
MONITORING_ACTIVE = False
|
|
Else
|
|
MONITORING_ACTIVE = True
|
|
NotifyIconMain.ShowBalloonTip(30000, "Clipboard Watcher", "Clipboard-Watcher wurde wieder aktiviert!", ToolTipIcon.Info)
|
|
End If
|
|
End Sub
|
|
Private Sub frmMain_Shown(sender As Object, e As EventArgs) Handles Me.Shown
|
|
If ERROR_INIT <> "INVALID USER" And LICENSE_COUNT > 0 Then
|
|
If DT_USER_PROFILES.Rows.Count >= 1 Then
|
|
Hide()
|
|
End If
|
|
Else
|
|
If USER_IS_ADMIN = True And ERROR_INIT = "NO LICENSE" Then
|
|
MsgBox("As an admin You have access! Please inform Digital Data to add a valid license!", MsgBoxStyle.Exclamation, "No valid License")
|
|
Else
|
|
If Not USER_IS_ADMIN Then
|
|
MsgBox("Application will close now!", MsgBoxStyle.Critical, "No valid License")
|
|
Close()
|
|
End If
|
|
|
|
End If
|
|
End If
|
|
If USER_IS_ADMIN = True Then
|
|
btnAdminConfig.Visible = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub NotifyIcon1_DoubleClick(sender As Object, e As EventArgs) Handles NotifyIconMain.DoubleClick
|
|
OpenClose()
|
|
End Sub
|
|
Sub OpenClose()
|
|
If Me.Visible = False Then
|
|
Me.BringToFront()
|
|
Me.Visible = True
|
|
TimerClose.Start()
|
|
Else
|
|
Me.Hide()
|
|
NotifyIconMain.Visible = True
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub frmMain_KeyUp(sender As Object, e As KeyEventArgs) Handles MyBase.KeyUp
|
|
If e.KeyCode = Keys.F12 And USER_IS_ADMIN = True Then
|
|
frmLicense.ShowDialog()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub tsmiChangeState_Click(sender As Object, e As EventArgs) Handles tsmiChangeState.Click
|
|
If tsmiChangeState.Tag = "stop" Then
|
|
tsmiChangeState.Tag = "start"
|
|
tsmiChangeState.Image = My.Resources.control_start_blue
|
|
tsmiChangeState.Text = "Überwachung Clipboard starten"
|
|
MONITORING_ACTIVE = False
|
|
NotifyIconMain.ShowBalloonTip(30000, "Clipboard Watcher", "Clipboard-Watcher wurde inaktiviert!", ToolTipIcon.Info)
|
|
Else
|
|
tsmiChangeState.Image = My.Resources.StatusAnnotations_Stop_16xLG
|
|
tsmiChangeState.Tag = "stop"
|
|
tsmiChangeState.Text = "Überwachung Clipboard stoppen"
|
|
MONITORING_ACTIVE = True
|
|
NotifyIconMain.ShowBalloonTip(30000, "Clipboard Watcher", "Clipboard-Watcher wurde wieder aktiviert!", ToolTipIcon.Info)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub TimerClose_Tick(sender As Object, e As EventArgs) Handles TimerClose.Tick
|
|
Hide()
|
|
End Sub
|
|
|
|
Private Sub frmMain_VisibleChanged(sender As Object, e As EventArgs) Handles Me.VisibleChanged
|
|
If TimerClose.Enabled = True Then
|
|
TimerClose.Stop()
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub MinimierenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles MinimierenToolStripMenuItem.Click
|
|
Hide()
|
|
End Sub
|
|
|
|
Private Sub ClientÖffnenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ClientÖffnenToolStripMenuItem.Click
|
|
OpenClose()
|
|
End Sub
|
|
|
|
Private Sub btnUserConfig_Click(sender As Object, e As EventArgs) Handles btnUserConfig.Click
|
|
frmConfig_Basic.ShowDialog()
|
|
End Sub
|
|
|
|
Private Sub btnAdminConfig_Click(sender As Object, e As EventArgs) Handles btnAdminConfig.Click
|
|
TimerClose.Stop()
|
|
MONITORING_ACTIVE = False
|
|
frmAdministration.ShowDialog()
|
|
TimerClose.Start()
|
|
MONITORING_ACTIVE = True
|
|
End Sub
|
|
|
|
End Class
|