public DirectoryTreeViewModel() { setUpBackgroundWorker(); #region FileSystemWatcher _watcher = new FileSystemWatcherEx(DirectoryInfoEx.DesktopDirectory); var handler = (FileSystemEventHandlerEx)delegate(object sender, FileSystemEventArgsEx args) { BroadcastChange(args.FullPath, args.ChangeType); }; var renameHandler = (RenameEventHandlerEx)delegate(object sender, RenameEventArgsEx args) { BroadcastChange(args.OldFullPath, args.ChangeType); }; _watcher.OnChanged += handler; _watcher.OnCreated += handler; _watcher.OnDeleted += handler; _watcher.OnRenamed += renameHandler; #endregion }
protected override void CoreInitialize() { FileSystemWatcherEx fileSystemWatcher; string path, name; base.CoreInitialize(); this.WriteLogSynchronized("INBOUND: Initialized on thread '{0}'.", Thread.CurrentThread.ManagedThreadId); foreach (IntegrationEndpoint endpoint in this.GetEndpoints()) { path = Path.GetFullPath(endpoint.Address.Uri.LocalPath); name = Path.GetFileName(path); if (this.FileSystemWatchers.ContainsKey(endpoint)) throw new InvalidOperationException(string.Format("The inbound adapter instance already contains an endpoint configuration '{0}'.", endpoint)); if (File.Exists(path)) throw new InvalidOperationException(string.Format("The inbound adapter instance expected a directory (not a file) endpoint configuration '{0}'.", endpoint)); if (!Directory.Exists(path)) Directory.CreateDirectory(path); fileSystemWatcher = new FileSystemWatcherEx(endpoint, path); fileSystemWatcher.Error += this.FileSystemWatcherOnError; fileSystemWatcher.Created += this.FileSystemWatcherOnCreated; fileSystemWatcher.IncludeSubdirectories = false; this.FileSystemWatchers.Add(endpoint, fileSystemWatcher); // manually trigger for existing files in drop location path = Path.GetDirectoryName(path); // special handling here this.ForceProcessing(fileSystemWatcher, new FileSystemEventArgs(WatcherChangeTypes.Created, path, name)); // allow eventing to tke over fileSystemWatcher.EnableRaisingEvents = true; } }
public CurrentDirectoryViewModel(FileListViewModel rootModel, Model.DirectoryModel model) : base(rootModel, model) { IsLoaded = false; _rootModel = rootModel; _subEntries = new CollectionViewSource(); _subEntries.Source = SubEntriesInternal; _subEntries.SortDescriptions.Add(new SortDescription("IsDirectory", ListSortDirection.Descending)); _subEntries.SortDescriptions.Add(new SortDescription("FullName", ListSortDirection.Ascending)); _refreshCommand = new SimpleCommand { CanExecuteDelegate = x => true, ExecuteDelegate = x => Refresh() }; #region FileSystemWatcher _watcher = new FileSystemWatcherEx(model.EmbeddedDirectoryEntry); var handler = (FileSystemEventHandlerEx)delegate(object sender, FileSystemEventArgsEx args) { if (args.FullPath.Equals(model.FullName)) Refresh(); }; var renameHandler = (RenameEventHandlerEx)delegate(object sender, RenameEventArgsEx args) { if (args.OldFullPath.Equals(model.FullName)) Refresh(); }; _watcher.OnChanged += handler; _watcher.OnCreated += handler; _watcher.OnDeleted += handler; _watcher.OnRenamed += renameHandler; #endregion }