Imports System.ComponentModel
Imports System.IO
Imports DigitalData.Modules.Filesystem
Imports DigitalData.Modules.Filesystem.FileWatcherFilters
Imports DigitalData.Modules.Logging

Public Class frmFolderWatcher

    Private _LogConfig As LogConfig
    Private _Logger As Logger
    Private _Watcher As FileWatcher

    <STAThread()>
    Private Sub FolderWatcher_Load(sender As Object, e As EventArgs) Handles Me.Load
        _LogConfig = New LogConfig(LogConfig.PathType.CurrentDirectory, Nothing, "MAIN")
        _LogConfig.Debug = True
        _Logger = _LogConfig.GetLogger()
        Dim oFilters As New List(Of BaseFileFilter) From {
            New TempFileFilter,
            New OfficeFileFilter
        }
        _Watcher = New FileWatcher(_LogConfig, "E:\Watcher", oFilters)

        _Watcher.Add("*.*")

        AddHandler _Watcher.FileSaved, AddressOf HandleFileSaved

        _Watcher.Start()
    End Sub

    Private Sub HandleFileSaved(FullName As String, IsSpecial As Boolean)
        _Logger.Info("{1}File Saved: {0}", FullName, IIf(IsSpecial, "Special ", ""))
    End Sub

    Private Sub FolderWatcher_Closing(sender As Object, e As CancelEventArgs) Handles Me.Closing
        _Watcher.Stop()
    End Sub
End Class