This commit is contained in:
2021-01-19 13:11:09 +01:00
parent f78f3f84b0
commit f6862cccc2
42 changed files with 3308 additions and 390 deletions

View File

@@ -6,6 +6,8 @@ Imports DigitalData.Modules.Logging
Imports DigitalData.Modules.Messaging
Imports DigitalData.GUIs.ClipboardWatcher
Imports DigitalData.GUIs.ZooFlow.ClassConstants
Imports DigitalData.Modules
Imports System.Runtime.InteropServices
Public Class frmFlowForm
' Constants
@@ -21,6 +23,8 @@ Public Class frmFlowForm
Private FileDrop As ClassFileDrop
Private FileHandle As ClassFilehandle
Private ProfileFilter As ProfileFilter
Private clsFW As ClassFolderwatcher
Private _DataASorDB As ClassDataASorDB
' Runtime Flags
Private ApplicationLoading As Boolean = True
@@ -28,8 +32,9 @@ Public Class frmFlowForm
' Runtime Variables
Private ESCHitCount As Integer = 0
Private IndexForm As frmGlobix_Index
Private Const mSnapOffset As Integer = 35
Private Const WM_WINDOWPOSCHANGING As Integer = &H46
' Events
Public Event ClipboardChanged As EventHandler(Of IDataObject)
@@ -41,12 +46,23 @@ Public Class frmFlowForm
' === Hide form initially ===
Opacity = OPACITY_INITIAL
End Sub
<StructLayout(LayoutKind.Sequential)>
Public Structure WINDOWPOS
Public hwnd As IntPtr
Public hwndInsertAfter As IntPtr
Public x As Integer
Public y As Integer
Public cx As Integer
Public cy As Integer
Public flags As Integer
End Structure
Private Sub frmFlowForm_Load(sender As Object, e As EventArgs) Handles Me.Load
' === Initialize Logger ===
Logger = My.LogConfig.GetLogger()
' === Show Splash Screen ===
SplashScreenManager.ShowForm(Me, GetType(frmSplash), False, False)
Try
@@ -74,8 +90,100 @@ Public Class frmFlowForm
AddHandler Init.Completed, AddressOf Init_Completed
Init.InitializeApplication()
_DataASorDB = New ClassDataASorDB(My.LogConfig)
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
' Listen for operating system messages
Select Case m.Msg
Case WM_WINDOWPOSCHANGING
SnapToDesktopBorder(Me, m.LParam, 0)
End Select
MyBase.WndProc(m)
End Sub
Public Shared Sub SnapToDesktopBorder(ByVal clientForm _
As Form, ByVal LParam As IntPtr, ByVal widthAdjustment As Integer)
If clientForm Is Nothing Then
' Satisfies rule: Validate parameters
Throw New ArgumentNullException("clientForm")
End If
' Snap client to the top, left, bottom or right desktop border
' as the form is moved near that border.
Try
' Marshal the LPARAM value which is a WINDOWPOS struct
Dim NewPosition As New WINDOWPOS
NewPosition = CType(Runtime.InteropServices.Marshal.PtrToStructure(
LParam, GetType(WINDOWPOS)), WINDOWPOS)
If NewPosition.y = 0 OrElse NewPosition.x = 0 Then
Return ' Nothing to do!
End If
' Adjust the client size for borders and caption bar
Dim ClientRect As Rectangle =
clientForm.RectangleToScreen(clientForm.ClientRectangle)
ClientRect.Width +=
SystemInformation.FrameBorderSize.Width - widthAdjustment
ClientRect.Height += (SystemInformation.FrameBorderSize.Height +
SystemInformation.CaptionHeight)
' Now get the screen working area (without taskbar)
Dim WorkingRect As Rectangle =
Screen.GetWorkingArea(clientForm.ClientRectangle)
' Left border
If NewPosition.x >= WorkingRect.X - mSnapOffset AndAlso
NewPosition.x <= WorkingRect.X + mSnapOffset Then
NewPosition.x = WorkingRect.X
End If
' Get screen bounds and taskbar height
' (when taskbar is horizontal)
Dim ScreenRect As Rectangle =
Screen.GetBounds(Screen.PrimaryScreen.Bounds)
Dim TaskbarHeight As Integer =
ScreenRect.Height - WorkingRect.Height
' Top border (check if taskbar is on top
' or bottom via WorkingRect.Y)
If NewPosition.y >= -mSnapOffset AndAlso
(WorkingRect.Y > 0 AndAlso NewPosition.y <=
(TaskbarHeight + mSnapOffset)) OrElse
(WorkingRect.Y <= 0 AndAlso NewPosition.y <=
(mSnapOffset)) Then
If TaskbarHeight > 0 Then
NewPosition.y = WorkingRect.Y ' Horizontal Taskbar
Else
NewPosition.y = 0 ' Vertical Taskbar
End If
End If
' Right border
If NewPosition.x + ClientRect.Width <=
WorkingRect.Right + mSnapOffset AndAlso
NewPosition.x + ClientRect.Width >=
WorkingRect.Right - mSnapOffset Then
NewPosition.x = WorkingRect.Right - (ClientRect.Width +
SystemInformation.FrameBorderSize.Width)
End If
' Bottom border
If NewPosition.y + ClientRect.Height <=
WorkingRect.Bottom + mSnapOffset AndAlso
NewPosition.y + ClientRect.Height >=
WorkingRect.Bottom - mSnapOffset Then
NewPosition.y = WorkingRect.Bottom - (ClientRect.Height +
SystemInformation.FrameBorderSize.Height)
End If
' Marshal it back
Runtime.InteropServices.Marshal.StructureToPtr(NewPosition,
LParam, True)
Catch ex As ArgumentException
End Try
End Sub
Private Sub Init_Completed(sender As Object, e As EventArgs)
Me.Cursor = Cursors.WaitCursor
' === Initialization Complete ===
@@ -105,7 +213,6 @@ Public Class frmFlowForm
AddHandler oControl.MouseLeave, AddressOf frmFlowForm_MouseLeave
Next
' TODO: Clean up
Dim oSQL = My.Queries.Common.FNIDB_GET_SEARCH_PROFILES(My.Application.User.UserId, My.Application.User.Language)
Dim oDatatable As DataTable = My.DatabaseIDB.GetDatatable(oSQL)
PictureBoxSearch.Visible = False
@@ -117,13 +224,94 @@ Public Class frmFlowForm
End If
If My.Application.ModulesActive.Contains(ClassConstants.MODULE_GLOBAL_INDEXER) Then
FileDrop = New ClassFileDrop(My.LogConfig)
FileHandle = New ClassFilehandle(My.LogConfig)
FileHandle = New ClassFilehandle()
clsFW = New ClassFolderwatcher
Refresh_RegexTable()
If My.Application.Globix.LoadFileExclusion = False Then
If My.Application.User.Language = "de-DE" Then
MsgBox("Die Ausschlusskriterien für Dateien in Folderwatch konnten nicht angelegt werden!", MsgBoxStyle.Information)
Else
MsgBox("File-Exclusions in Folderwatch could not be created!", MsgBoxStyle.Information)
End If
End If
My.Application.Globix.LoadFileExclusion()
Init_Folderwatch()
Start_Folderwatch()
GlobixToolStripMenuItem.Visible = True
End If
My.DTAttributes = My.DatabaseIDB.GetDatatable("SELECT * FROM TBIDB_ATTRIBUTE")
oSQL = "SELECT * FROM TBIDB_ATTRIBUTE"
My.DTAttributes = _DataASorDB.GetDatatable("IDB", oSQL, "TBIDB_ATTRIBUTE", "", "")
Me.Cursor = Cursors.Default
End Sub
Public Sub Init_Folderwatch()
Try
Dim oSql As String = "SELECT FOLDER_PATH FROM TBGI_FOLDERWATCH_USER WHERE FOLDER_TYPE = 'DEFAULT' AND USER_ID = " & My.Application.User.UserId
Dim folderwatchPath = My.Database.GetScalarValue(oSql)
folderwatchPath = IIf(IsDBNull(folderwatchPath), "", folderwatchPath)
If folderwatchPath = String.Empty Then
Logger.Info("Init_Folderwatch: folderwatchPath is empty")
My.Application.Globix.Folderwatchstarted = False
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "False")
My.UIConfig.Globix.FolderWatchStarted = False
My.UIConfigManager.Save()
End If
If Not IO.Directory.Exists(folderwatchPath) Then
Logger.Info("Init_Folderwatch: folderwatchPath does not exists or is invalid path")
My.Application.Globix.Folderwatchstarted = False
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "False")
My.UIConfig.Globix.FolderWatchStarted = False
My.UIConfigManager.Save()
End If
My.Application.Globix.CURRENT_FOLDERWATCH = folderwatchPath
My.Application.Globix.Folderwatchstarted = True
'FWFunction_STARTED = True
clsFW.StartStop_FolderWatch()
Catch ex As Exception
MsgBox($"Init_Folderwatch: Unexpected error while starting FolderWatch: {ex.Message}", MsgBoxStyle.Critical)
Logger.Info($"Init_Folderwatch: Unexpected error: {ex.Message}")
End Try
Try
Dim oSql As String = "SELECT FOLDER_PATH FROM TBGI_FOLDERWATCH_USER WHERE FOLDER_TYPE = 'SCAN' AND USER_ID = " & My.Application.User.UserId
Dim oFolderwatchScanPath = My.Database.GetScalarValue(oSql)
oFolderwatchScanPath = IIf(IsDBNull(oFolderwatchScanPath), "", oFolderwatchScanPath)
If oFolderwatchScanPath = String.Empty Then
Logger.Info("Init_Folderwatch: folderwatchScanPath is empty")
My.UIConfig.Globix.FolderWatchStarted = False
My.UIConfigManager.Save()
Exit Sub
End If
If Not IO.Directory.Exists(oFolderwatchScanPath) Then
Logger.Info("Init_Folderwatch: folderwatchScanPath does not exists or is invalid path")
My.UIConfig.Globix.FolderWatchStarted = False
My.UIConfigManager.Save()
Exit Sub
End If
My.Application.Globix.CURRENT_SCAN_FOLDERWATCH = oFolderwatchScanPath
'FWFunction_STARTED = True
clsFW.StartStop_FolderWatchSCAN()
Catch ex As Exception
MsgBox($"Init_Folderwatch: Unexpected error while starting FolderWatchScan: {ex.Message}", MsgBoxStyle.Critical)
Logger.Info($"Init_Folderwatch: Unexpected error: {ex.Message}")
End Try
End Sub
Private Sub TimerRefreshData_Tick(sender As Object, e As EventArgs)
'TODO: Refresh Data
@@ -356,17 +544,17 @@ Public Class frmFlowForm
End If
TimerCheckDroppedFiles.Stop()
Check_Dropped_Files()
Globix_Check_Dropped_Files()
Me.Cursor = Cursors.Default
End Sub
Sub Check_Dropped_Files()
Sub Globix_Check_Dropped_Files()
Try
My.Database.ExecuteNonQuery("DELETE FROM TBGI_FILES_USER WHERE WORKED = 1 AND UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')")
Dim i As Integer
For Each Str As Object In FileDrop.files_dropped
If Not Str Is Nothing Then
Logger.Info(">> Check Drop-File: " & Str.ToString)
Logger.Info(" Check Drop-File: " & Str.ToString)
Dim handleType As String = Str.Substring(0, Str.LastIndexOf("|") + 1)
Dim filename As String = Str.Substring(Str.LastIndexOf("|") + 1)
If My.Application.Globix.FileExistsinDropTable(filename) = False Then
@@ -403,7 +591,7 @@ Public Class frmFlowForm
My.Application.Globix.CURRENT_FILENAME = oFileRow.Item("FILENAME2WORK").ToString
My.Application.Globix.CURRENT_WORKFILE_GUID = oFileRow.Item(0)
My.Application.Globix.CURRENT_WORKFILE = oFileRow.Item("FILENAME2WORK").ToString
Logger.Info(">> CURRENT_WORKFILE: " & My.Application.Globix.CURRENT_WORKFILE)
Logger.Info(" CURRENT_WORKFILE: " & My.Application.Globix.CURRENT_WORKFILE)
If File.Exists(My.Application.Globix.CURRENT_WORKFILE) = True And My.Application.Globix.DTACTUAL_FILES.Rows.Count > 0 Then
Globix_Open_IndexDialog()
End If
@@ -418,6 +606,8 @@ Public Class frmFlowForm
Sub Globix_Open_IndexDialog()
Try
IndexForm = New frmGlobix_Index(My.LogConfig)
NotifyIconReset()
AddHandler IndexForm.FormClosed, AddressOf GlobixClosed
IndexForm.Show()
Cursor = Cursors.Default
If TimerCheckActiveForms.Enabled = False Then
@@ -428,12 +618,196 @@ Public Class frmFlowForm
MsgBox(ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
Sub NotifyIconReset()
NI_TYPE = "INFO"
NI_MESSAGE = String.Empty
End Sub
Sub GlobixClosed()
Try
If NI_MESSAGE = String.Empty Then
Exit Sub
End If
Dim oNIType = 1
Select Case NI_TYPE
Case "INFO"
oNIType = 1
Case "ERROR"
oNIType = 3
End Select
NotifyIcon.ShowBalloonTip(30000, NI_TITLE, NI_MESSAGE, oNIType)
Catch ex As Exception
End Try
End Sub
Sub Start_Folderwatch()
If My.Application.Globix.CURRENT_FOLDERWATCH = String.Empty Then
My.Application.Globix.Folderwatchstarted = False
End If
If My.Application.Globix.CURRENT_SCAN_FOLDERWATCH = String.Empty Then
My.UIConfigManager.Config.Globix.FolderWatchScanStarted = False
My.UIConfigManager.Save()
End If
If My.Application.Globix.CURRENT_FOLDERWATCH <> "" Or My.Application.Globix.CURRENT_SCAN_FOLDERWATCH <> "" Then
'If My.Application.Globix.Folderwatchstarted = True Then
' tslblFW.Visible = True
'Else
' tslblFW.Visible = False
'End If
Try
If My.UIConfigManager.Config.Globix.FolderWatchScanStarted = True Then
Logger.Info("FWSCAN started - Checking file:" & My.Application.Globix.CURRENT_SCAN_FOLDERWATCH)
Dim fileEntries As String() = Directory.GetFiles(My.Application.Globix.CURRENT_SCAN_FOLDERWATCH)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
Logger.Info("Scanfolder after startup: Checking file:" & fileName)
For Each row As DataRow In My.Application.Globix.DTEXCLUDE_FILES.Rows
Dim content As String = row.Item(0).ToString.ToLower
If fileName.ToLower.Contains(content) Then
Exit Sub
End If
Next
Dim handleType As String
If fileName.ToLower.EndsWith(".msg") Then
handleType = "|FW_OUTLOOK_MESSAGE|"
Else
handleType = "|FW_SIMPLEINDEXER|"
End If
'Die Datei übergeben
Logger.Info(" Adding file from Scanfolder after startup:" & fileName)
If My.Application.Globix.FileExistsinDropTable(fileName) = False Then
FileHandle.Decide_FileHandle(fileName, handleType)
Else
Logger.Info("Scanfolder Startup: File already exists:" & fileName)
End If
Next fileName
Else
Logger.Info("FWSCAN not started")
End If
Catch ex As Exception
Logger.Info("Error while starting folderwatch scan: " & ex.Message)
Logger.Error(ex.Message)
End Try
Try
If My.Application.Globix.Folderwatchstarted = True Then
Logger.Info("Folderwatchstarted - Checking file:" & My.Application.Globix.CURRENT_FOLDERWATCH)
Dim fileEntries As String() = Directory.GetFiles(My.Application.Globix.CURRENT_FOLDERWATCH)
' Process the list of files found in the directory.
Dim fileName As String
For Each fileName In fileEntries
Logger.Info("Folderwach after startup: Checking file:" & fileName)
For Each row As DataRow In My.Application.Globix.DTEXCLUDE_FILES.Rows
Dim content As String = row.Item(0).ToString.ToLower
If fileName.ToLower.Contains(content) Then
Exit Sub
End If
Next
Dim handleType As String
If fileName.ToLower.EndsWith(".msg") Then
handleType = "|FW_OUTLOOK_MESSAGE|"
Else
handleType = "|FW_SIMPLEINDEXER|"
End If
'Die Datei übergeben
Logger.Info("Adding file from Folderwatch after startup:" & fileName)
If My.Application.Globix.FileExistsinDropTable(fileName) = False Then
FileHandle.Decide_FileHandle(fileName, handleType)
Else
Logger.Info("Folderwatch Startup: File already exists:" & fileName)
End If
Next fileName
Else
Logger.Info("Folderwatch not started")
End If
Catch ex As Exception
Logger.Info("Error while starting folderwatch: " & ex.Message)
Logger.Error(ex.Message)
End Try
If TimerFolderwatch.Enabled = False Then
TimerFolderwatch.Start()
End If
End If
End Sub
Private Sub frmFlowForm_ResizeEnd(sender As Object, e As EventArgs) Handles Me.ResizeEnd
My.UIConfig.FlowForm.Location = Location
My.UIConfigManager.Save()
End Sub
Private Sub TimerFolderwatch_Tick_1(sender As Object, e As EventArgs) Handles TimerFolderwatch.Tick
Try
' JenneJ, 11.02.2019:
' Keine Folderwatch Dateien verarbeiten, wenn gerade Indexiert wird,
' dadurch würden die Globalen Variablen überschrieben
' und in Folge die falschen Dateien Indexiert!
If My.Application.Globix.INDEXING_ACTIVE Or My.Application.Globix.MULTIINDEXING_ACTIVE Then
Exit Sub
End If
If My.Application.Globix.Folderwatchstarted = True Or My.UIConfig.Globix.FolderWatchScanStarted = True Then
'Prüfen ob alle Files abgearbeitet wurden
Dim sql = "SELECT * FROM TBGI_FILES_USER WHERE WORKED = 0 AND HANDLE_TYPE like '%|FW%' AND UPPER(USER@WORK) = UPPER('" & Environment.UserName & "')"
My.Application.Globix.DTACTUAL_FILES = My.Database.GetDatatable(sql)
If My.Application.Globix.DTACTUAL_FILES.Rows.Count > 0 Then
My.Application.Globix.ABORT_INDEXING = False
' Dim fil As String
Me.TimerFolderwatch.Stop()
For Each row As DataRow In My.Application.Globix.DTACTUAL_FILES.Rows
Dim FILEGUID = row.Item("GUID")
If My.Application.Globix.ABORT_INDEXING = True Then
Exit For
End If
Dim FileForWork As String = row.Item(1)
Logger.Info(" In Timer Folderwatch - File: " & FileForWork)
Dim fileInUse As Boolean = FileHandle.IsFileInUse(FileForWork)
Dim fileexists As Boolean = System.IO.File.Exists(FileForWork)
If fileInUse = False Then
If fileexists = True Then
My.Application.Globix.CURRENT_WORKFILE = FileForWork
My.Application.Globix.CURRENT_FILENAME = FileForWork
My.Application.Globix.CURRENT_WORKFILE_GUID = row.Item("GUID")
Globix_Open_IndexDialog()
Else
Logger.Info(" File not existing - Row will be deleted!")
Dim oDel = String.Format("DELETE FROM TBGI_FILES_USER WHERE GUID = {0}", FILEGUID)
My.Database.ExecuteNonQuery(oDel)
End If
Else
Logger.Info(" file '" & row.Item(1) & "' could not be opened exclusively - fileInUse!")
End If
Next
Me.TimerFolderwatch.Start()
End If
'tslblFW.Visible = True
Else
'tslblFW.Visible = False
End If
Catch ex As Exception
If ex.Message.Contains("Sammlung wurde geändert") Or ex.Message.Contains("Enumeration") Then
Else
MsgBox("Error in Work FolderWatch-File:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End If
End Try
End Sub
Private Sub TsiGlobixConfig_Click(sender As Object, e As EventArgs) Handles TsiGlobixConfig.Click
frmGlobixBasicConfig.ShowDialog()
End Sub
End Class