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

@@ -0,0 +1,201 @@
Imports System.IO
Imports DigitalData.Modules.Logging
Public Class ClassFolderwatcher
Public Shared FWFolderWatcher As FileSystemWatcher
Public Shared FWScan As FileSystemWatcher
Private clsFilehandle As ClassFilehandle
Private Logger As Logger
Public Sub New()
Logger = My.LogConfig.GetLogger()
clsFilehandle = New ClassFilehandle()
End Sub
Public Function Restart_FolderWatch()
Try
If FWFolderWatcher.EnableRaisingEvents = True Then
'Gestartet also Stoppen
FWFolderWatcher.EnableRaisingEvents = False
My.Application.Globix.Folderwatchstarted = False
'FolderWatch neu instanzieren
FWFolderWatcher = New System.IO.FileSystemWatcher(My.Application.Globix.CURRENT_FOLDERWATCH, "*.*")
Logger.Info(" >> FolderWatch neu instanziert")
FWFolderWatcher.IncludeSubdirectories = False
FWFolderWatcher.EnableRaisingEvents = True
AddHandler FWFolderWatcher.Created, AddressOf OnCreated
My.Application.Globix.Folderwatchstarted = True
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "True")
My.UIConfig.Globix.FolderWatchStarted = True
My.UIConfigManager.Save()
End If
Catch ex As Exception
Logger.Info($"Error in Restart_FolderWatch: {ex.Message}")
Logger.Error(ex.Message)
End Try
End Function
Public Function Restart_FolderWatchSCAN()
Try
If FWScan.EnableRaisingEvents = True Then
'Gestartet also Stoppen
FWScan.EnableRaisingEvents = False
'FolderWatch neu instanzieren
FWScan = New System.IO.FileSystemWatcher(My.Application.Globix.CURRENT_SCAN_FOLDERWATCH, "*.*")
Logger.Info(" >> FolderWatchScan neu instanziert")
FWScan.IncludeSubdirectories = False
FWScan.EnableRaisingEvents = True
AddHandler FWScan.Created, AddressOf OnCreated
'SaveConfigValue("FWSCAN_started", "True")
My.UIConfig.Globix.FolderWatchScanStarted = True
My.UIConfigManager.Save()
End If
Catch ex As Exception
Logger.Info($"Error in Restart_FolderWatchSCAN: {ex.Message}")
Logger.Error(ex.Message)
End Try
End Function
Public Function StartStop_FolderWatch()
Try
If My.Application.Globix.CURRENT_FOLDERWATCH = "" Then
'MsgBox("Bitte definieren Sie einen Überwachungsordner:", MsgBoxStyle.Exclamation)
Return False
End If
If FWFolderWatcher Is Nothing Then
FWFolderWatcher = New System.IO.FileSystemWatcher(My.Application.Globix.CURRENT_FOLDERWATCH, "*.*")
Logger.Info(" >> FolderWatch Gestartet")
FWFolderWatcher.IncludeSubdirectories = False
FWFolderWatcher.EnableRaisingEvents = True
AddHandler FWFolderWatcher.Created, AddressOf OnCreated
My.Application.Globix.Folderwatchstarted = True
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "True")
My.UIConfig.Globix.FolderWatchStarted = True
My.UIConfigManager.Save()
Return 1
End If
If FWFolderWatcher.EnableRaisingEvents = False Then
' Dim watcher As New FileSystemWatcher()
' watcher.Path = CURRENT_FOLDERWATCH
FWFolderWatcher = New System.IO.FileSystemWatcher(My.Application.Globix.CURRENT_FOLDERWATCH, "*.*")
Logger.Info(" >> FolderWatch Gestartet")
FWFolderWatcher.IncludeSubdirectories = False
FWFolderWatcher.EnableRaisingEvents = True
AddHandler FWFolderWatcher.Created, AddressOf OnCreated
My.Application.Globix.Folderwatchstarted = True
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "True")
My.UIConfig.Globix.FolderWatchStarted = True
My.UIConfigManager.Save()
Return 1
Else
'Gestartet also Stoppen
FWFolderWatcher.EnableRaisingEvents = False
My.Application.Globix.Folderwatchstarted = False
Logger.Info(" >> FolderWatch gestoppt")
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "False")
My.UIConfig.Globix.FolderWatchStarted = False
My.UIConfigManager.Save()
Return 0
End If
Catch ex As Exception
MsgBox("Error in StartStop_FolderWatch:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return 99
End Try
End Function
Public Function StartStop_FolderWatchSCAN() As Integer
Try
If My.Application.Globix.CURRENT_SCAN_FOLDERWATCH = "" Then
If FWFolderWatcher.EnableRaisingEvents = True Then
Stop_FWSCAN()
Return 0
Else
If My.Application.User.Language = "de-DE" Then
MsgBox("Bitte definieren Sie einen Überwachungsordner für Scan-Eingänge:", MsgBoxStyle.Exclamation)
Else
MsgBox("Please define a watchfolder for Scanning:", MsgBoxStyle.Exclamation)
End If
Return False
End If
End If
If FWScan Is Nothing Then
FWScan = New System.IO.FileSystemWatcher(My.Application.Globix.CURRENT_SCAN_FOLDERWATCH, "*.*")
Logger.Info(" >> FolderWatch Scan Gestartet")
FWScan.IncludeSubdirectories = False
FWScan.EnableRaisingEvents = True
AddHandler FWScan.Created, AddressOf OnCreated
My.UIConfig.Globix.FolderWatchScanStarted = True
My.UIConfigManager.Save()
Return 1
End If
If FWScan.EnableRaisingEvents = False Then
' Dim watcher As New FileSystemWatcher()
' watcher.Path = CURRENT_FOLDERWATCH
FWScan = New System.IO.FileSystemWatcher(My.Application.Globix.CURRENT_SCAN_FOLDERWATCH, "*.*")
Logger.Info(" >> FolderWatch Scan Gestartet")
FWScan.IncludeSubdirectories = False
FWScan.EnableRaisingEvents = True
AddHandler FWScan.Created, AddressOf OnCreated
My.UIConfig.Globix.FolderWatchScanStarted = True
My.UIConfigManager.Save()
Return 1
Else
'Gestartet also Stoppen
FWScan.EnableRaisingEvents = False
Logger.Info(" >> FolderWatch Scan gestoppt")
'SaveConfigValue("FWSCAN_started", "False")
My.UIConfig.Globix.FolderWatchScanStarted = False
My.UIConfigManager.Save()
Return 0
End If
Catch ex As Exception
MsgBox("Error in StartStop_FolderWatchSCAN:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return 99
End Try
End Function
Public Function Stop_FWSCAN()
If FWFolderWatcher.EnableRaisingEvents = True Then
'Gestartet also Stoppen
FWFolderWatcher.EnableRaisingEvents = False
My.Application.Globix.Folderwatchstarted = False
Logger.Info(" >> FolderWatch gestoppt")
'SaveConfigValue("my.Application.Globix.Folderwatchstarted", "False")
My.UIConfig.Globix.FolderWatchStarted = True
My.UIConfigManager.Save()
Return True
Else
Return False
End If
End Function
Private Sub OnCreated(source As Object, e As FileSystemEventArgs)
Try
If Not IsNothing(My.Application.Globix.DTEXCLUDE_FILES) Then
For Each row As DataRow In My.Application.Globix.DTEXCLUDE_FILES.Rows
Dim content As String = row.Item(0).ToString.ToLower
If e.FullPath.ToLower.Contains(content) Then
Exit Sub
End If
Next
End If
Dim handleType As String
If e.FullPath.ToLower.EndsWith(".msg") Then
handleType = "|FW_OUTLOOK_MESSAGE|"
Else
handleType = "|FW_SIMPLEINDEXER|"
End If
'Die Datei übergeben
Logger.Info(">> OnCreated-File:" & e.FullPath)
If My.Application.Globix.FileExistsinDropTable(e.FullPath) = False Then
clsFilehandle.Decide_FileHandle(e.FullPath, handleType)
Else
Logger.Info(">> Folderwatcher: File already exists:" & e.FullPath)
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error in folder_watch_Created")
End Try
End Sub
End Class