public static IObservable <ShellChangedEventArgs> CreatedAsObservable(this ShellWatcher watcher) { return(Observable.FromEventPattern <ShellChangedEventArgs>( h => watcher.ItemCreated += h, h => watcher.ItemCreated -= h) .Select(x => x.EventArgs)); }
public async void Loaded(dynamic view) { this.View = view as IMainView; this.View.WriteLine(String.Empty); this.View.WriteLine($"RootFolder: {this.RootFolder.Value.Path}"); this.shellWatcher = await ShellWatcher.CreateAsync(this.RootFolder.Value, true); this.shellWatcher.CreatedAsObservable() .Subscribe(e => { this.View.WriteLine($"Create: {e.ShellObject}"); }) .AddTo(this.CompositeDisposable); this.shellWatcher.DeletedAsObservable() .Subscribe(e => { this.View.WriteLine($"Delete: {e.ShellObject}"); }) .AddTo(this.CompositeDisposable); this.shellWatcher.RenamtedAsObservable() .Subscribe(e => { this.View.WriteLine($"Rename: {e.ShellObject} -> {e.NewShellObject}"); }) .AddTo(this.CompositeDisposable); this.shellWatcher.Start(); }
/// <summary> /// Unregister <see cref="ShellWatcher" /> from the message listener. /// </summary> /// <param name="shellWatcher">Unregister <see cref="ShellWatcher" />.</param> /// <returns></returns> public static Task UnregisterAsync(ShellWatcher shellWatcher) { Contract.Requires <ArgumentNullException>(shellWatcher != null); ShellWatcher temp; Listeners.TryRemove(shellWatcher.Message, out temp); return(Task.FromResult(0)); }
/// <summary> /// Register <see cref="ShellWatcher" /> in the message listener. /// </summary> /// <param name="shellObject">Register <see cref="ShellObject" />.</param> /// <param name="recursive">Specify whether to monitor recursively.</param> /// <returns>Created <see cref="ShellWatcher" />.</returns> public static async Task <ShellWatcher> RegisterAsync(ShellObject shellObject, bool recursive) { Contract.Requires <ArgumentNullException>(shellObject != null); var message = await FindWindowMessageAsync(); if (message < WM_APP) { throw new ShellException(ErrorMessages.ShellWatcherManagerFilterUnableToRegister); } // Create ShellWatcher. var result = new ShellWatcher(shellObject, Window, message, recursive); // Register ShellWatcher. Listeners.TryAdd(message, result); return(result); }