/// <summary> /// Adds a IFileSystemListener to a given relative path, so every event on the path and every sub-paths are served to the /// IFileSystemListener. /// </summary> /// <param name="listener">The listener that defines the callback events for the file system.</param> protected void AddFileSystemListener(IFileSystemListener listener) { // Add the file system watcher for a directory and its subdirectories // AKA Sauron Watcher = new FileSystemWatcher(GetFileSystemRoot()) { EnableRaisingEvents = true, IncludeSubdirectories = true }; // Add the callback functions Watcher.Changed += ((o, e) => listener.OnChanged(e.FullPath + ((IsDirectory(GetRelativePath(e.FullPath)) && !e.FullPath.EndsWith(FileSystem.PathSeparator)) ? FileSystem.PathSeparator : String.Empty))); Watcher.Created += ((o, e) => listener.OnCreated(e.FullPath + ((IsDirectory(GetRelativePath(e.FullPath)) && !e.FullPath.EndsWith(FileSystem.PathSeparator)) ? FileSystem.PathSeparator : String.Empty))); Watcher.Deleted += ((o, e) => listener.OnDeleted(e.FullPath + ((IsDirectory(GetRelativePath(e.FullPath)) && !e.FullPath.EndsWith(FileSystem.PathSeparator)) ? FileSystem.PathSeparator : String.Empty))); Watcher.Renamed += ((o, e) => listener.OnRenamed(e.OldFullPath + ((IsDirectory(GetRelativePath(e.FullPath)) && !e.OldFullPath.EndsWith(FileSystem.PathSeparator)) ? FileSystem.PathSeparator : String.Empty), e.FullPath + ((IsDirectory(GetRelativePath(e.FullPath)) && !e.FullPath.EndsWith(FileSystem.PathSeparator)) ? FileSystem.PathSeparator : String.Empty))); }