IFileEventNotifier is a service created to give an interface to the System.IO.FileSystemWatcher.
The default implementation is FileEventNotifier.
IFileEventNotifier contains only 2 methods:
The FileWatchInfo to unsubscribe must be the same object as the one used to subscribe. If it's not, an InvalidFileWatchInfoException will be thrown.
FileWatchInfo contains all data regarding a watched file, the class is needed to subscribe and unsubscribe a watch.
It's most important properties are the path, the filter, the changes to report, and the eventhandler to call.
When initializing a new instance of FileWatchInfo:
This is especially necessairy if the path-to-watch is not available on the sytem at the time of FileWatchInfo's initialization, because then FileWatchInfo is not able to know if the path is a file or directory. This could lead to unexpected results.
FileEventNotifier is just like FileSystemWatcher able to watch changes on files and/or directories.
FileEventNotifier supports subsriptions for unavailable paths. The path will be watched as soon as it comes available.
Useful feature for watching files/directories on network shares, removable disks, ramdisks, ...
When such a path is lost, the FileEventNotifier will autorestore the watch as soon as the path is available again.
FileEventNotifier will raise an event if a path is lost or retrieved.
Only one event per change is sent.
Example: when a new file is created, a single Created-event will be sent in stead of a the 3 events Created, Renamed, and Changed (which is how some applications create files).
FileEventNotifier supports multiple filters. Filters are case sensitive and can contain wildcards.
The following table comes straight from MSDN, and demonstrates the use of wildcards:
Watches the following files
All files (default). An empty string ("") also watches all files.
All files with a "txt" extension.
All files ending in "recipe" with a "doc" extension.
All files beginning with "win" with an "xml" extension.
Matches the following: Sales July 2001.xlsSales Aug 2002.xlsSales March 2004.xls but does not match: Sales Nov 1999.xls
Watches only MyReport.doc
No events are raised when the filesize is still increasing.
This is especially useful when the user creates a new large file in the watched path. The Created event will only be raised when the file is complete, this makes it save to immediately read tags or parse content from the file.
The feature only works for files.
All errorhandling is kept internal.
The FAT file system is not supported.
The FileEventNotifier will throw a NotSupportedDriveTypeException if such a path is subscribed,
unless the path is specified by UNC (meaning the path is not watched, and without the subscriber knowing).