161 lines
7.2 KiB
VB.net
161 lines
7.2 KiB
VB.net
Imports System.IO
|
|
Imports Independentsoft
|
|
Imports System.Threading
|
|
|
|
Public Class ClassFolderWatcher
|
|
Public Shared FolderWatcher As FileSystemWatcher
|
|
Public Shared FolderWatcher_SCAN As FileSystemWatcher
|
|
Public Shared Function Restart_FolderWatch()
|
|
If FolderWatcher.EnableRaisingEvents = True Then
|
|
'Gestartet also Stoppen
|
|
FolderWatcher.EnableRaisingEvents = False
|
|
FW_started = False
|
|
'FolderWatch neu instanzieren
|
|
FolderWatcher = New System.IO.FileSystemWatcher(CURRENT_FOLDERWATCH, "*.*")
|
|
ClassLogger.Add(" >> FolderWatch neu instanziert", False)
|
|
FolderWatcher.IncludeSubdirectories = False
|
|
FolderWatcher.EnableRaisingEvents = True
|
|
AddHandler FolderWatcher.Created, AddressOf OnCreated
|
|
FW_started = True
|
|
SaveConfigValue("FW_started", "True")
|
|
End If
|
|
End Function
|
|
Public Shared Function Restart_FolderWatchSCAN()
|
|
If FolderWatcher_SCAN.EnableRaisingEvents = True Then
|
|
'Gestartet also Stoppen
|
|
FolderWatcher_SCAN.EnableRaisingEvents = False
|
|
FWSCAN_started = False
|
|
'FolderWatch neu instanzieren
|
|
FolderWatcher_SCAN = New System.IO.FileSystemWatcher(CURRENT_SCAN_FOLDERWATCH, "*.*")
|
|
ClassLogger.Add(" >> FolderWatchScan neu instanziert", False)
|
|
FolderWatcher_SCAN.IncludeSubdirectories = False
|
|
FolderWatcher_SCAN.EnableRaisingEvents = True
|
|
AddHandler FolderWatcher_SCAN.Created, AddressOf OnCreated
|
|
FWSCAN_started = True
|
|
SaveConfigValue("FWSCAN_started", "True")
|
|
End If
|
|
End Function
|
|
Public Shared Function StartStop_FolderWatch()
|
|
Try
|
|
If CURRENT_FOLDERWATCH = "" Then
|
|
MsgBox("Bitte definieren Sie einen Überwachungsordner:", MsgBoxStyle.Exclamation)
|
|
Return False
|
|
End If
|
|
If FolderWatcher Is Nothing Then
|
|
FolderWatcher = New System.IO.FileSystemWatcher(CURRENT_FOLDERWATCH, "*.*")
|
|
ClassLogger.Add(" >> FolderWatch Gestartet", False)
|
|
FolderWatcher.IncludeSubdirectories = False
|
|
FolderWatcher.EnableRaisingEvents = True
|
|
AddHandler FolderWatcher.Created, AddressOf OnCreated
|
|
FW_started = True
|
|
SaveConfigValue("FW_started", "True")
|
|
Return 1
|
|
End If
|
|
If FolderWatcher.EnableRaisingEvents = False Then
|
|
' Dim watcher As New FileSystemWatcher()
|
|
' watcher.Path = CURRENT_FOLDERWATCH
|
|
FolderWatcher = New System.IO.FileSystemWatcher(CURRENT_FOLDERWATCH, "*.*")
|
|
ClassLogger.Add(" >> FolderWatch Gestartet", False)
|
|
FolderWatcher.IncludeSubdirectories = False
|
|
FolderWatcher.EnableRaisingEvents = True
|
|
AddHandler FolderWatcher.Created, AddressOf OnCreated
|
|
FW_started = True
|
|
SaveConfigValue("FW_started", "True")
|
|
Return 1
|
|
Else
|
|
'Gestartet also Stoppen
|
|
FolderWatcher.EnableRaisingEvents = False
|
|
FW_started = False
|
|
ClassLogger.Add(" >> FolderWatch gestoppt", False)
|
|
SaveConfigValue("FW_started", "False")
|
|
Return 0
|
|
End If
|
|
'If watcher.EnableRaisingEvents = False Then
|
|
' watcher = New System.IO.FileSystemWatcher(CURRENT_FOLDERWATCH, "*.*")
|
|
' ClassLogger.Add(" - vFolderWatch.Gestartet", False)
|
|
' watcher.IncludeSubdirectories = False
|
|
' watcher.EnableRaisingEvents = True
|
|
' AddHandler watcher.Created, AddressOf OnCreated
|
|
' Return 1
|
|
'Else
|
|
' 'Gestartet also Stoppen
|
|
' watcher.EnableRaisingEvents = False
|
|
' 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 Shared Function StartStop_FolderWatchSCAN()
|
|
Try
|
|
If CURRENT_SCAN_FOLDERWATCH = "" Then
|
|
MsgBox("Bitte definieren Sie einen Überwachungsordner für Scan-Eingänge:", MsgBoxStyle.Exclamation)
|
|
Return False
|
|
End If
|
|
If FolderWatcher_SCAN Is Nothing Then
|
|
FolderWatcher_SCAN = New System.IO.FileSystemWatcher(CURRENT_SCAN_FOLDERWATCH, "*.*")
|
|
ClassLogger.Add(" >> FolderWatch Scan Gestartet", False)
|
|
FolderWatcher_SCAN.IncludeSubdirectories = False
|
|
FolderWatcher_SCAN.EnableRaisingEvents = True
|
|
AddHandler FolderWatcher_SCAN.Created, AddressOf OnCreated
|
|
FWSCAN_started = True
|
|
SaveConfigValue("FWSCAN_started", "True")
|
|
Return 1
|
|
End If
|
|
If FolderWatcher_SCAN.EnableRaisingEvents = False Then
|
|
' Dim watcher As New FileSystemWatcher()
|
|
' watcher.Path = CURRENT_FOLDERWATCH
|
|
FolderWatcher_SCAN = New System.IO.FileSystemWatcher(CURRENT_SCAN_FOLDERWATCH, "*.*")
|
|
ClassLogger.Add(" >> FolderWatch Scan Gestartet", False)
|
|
FolderWatcher_SCAN.IncludeSubdirectories = False
|
|
FolderWatcher_SCAN.EnableRaisingEvents = True
|
|
AddHandler FolderWatcher_SCAN.Created, AddressOf OnCreated
|
|
FWSCAN_started = True
|
|
SaveConfigValue("FWSCAN_started", "True")
|
|
Return 1
|
|
Else
|
|
'Gestartet also Stoppen
|
|
FolderWatcher_SCAN.EnableRaisingEvents = False
|
|
FWSCAN_started = False
|
|
ClassLogger.Add(" >> FolderWatch Scan gestoppt", False)
|
|
SaveConfigValue("FWSCAN_started", "False")
|
|
Return 0
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
MsgBox("Error in StartStop_FolderWatchSCAN:" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
|
Return 99
|
|
End Try
|
|
End Function
|
|
Private Shared Sub OnCreated(source As Object, e As FileSystemEventArgs)
|
|
Try
|
|
For Each row As DataRow In DTEXCLUDE_FILES.Rows
|
|
Dim content As String = row.Item(0).ToString.ToLower
|
|
If e.FullPath.ToLower.Contains(content) Then
|
|
Exit Sub
|
|
End If
|
|
Next
|
|
|
|
Dim handleType As String
|
|
If e.FullPath.EndsWith(".msg") Then
|
|
handleType = "@FW_OUTLOOK_MESSAGE@"
|
|
Else
|
|
handleType = "@FW_SIMPLEINDEXER@"
|
|
End If
|
|
'Die Datei übergeben
|
|
If LogErrorsOnly = False Then ClassLogger.Add(">> OnCreated-File:" & e.FullPath, False)
|
|
If ClassIndexFunctions.FileExistsinDropTable(CURRENT_FILENAME) = False Then
|
|
ClassFilehandle.Decide_FileHandle(e.FullPath, handleType)
|
|
Else
|
|
Console.WriteLine("File existiert bereits")
|
|
End If
|
|
|
|
Catch ex As Exception
|
|
MsgBox(ex.Message, MsgBoxStyle.Critical, "Fehler bei folder_watch_Created")
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
End Class
|