/// <summary> /// Populates a <see cref="ReadOnlyListSubject{T}"/> with the full paths to all of the files that currently exist within /// the scope of the specified <see cref="FileSystemWatcher"/>, and also responds to changes by adding the full paths of files /// that are created and removing those that are deleted. /// </summary> /// <param name="watcher">The object that specifies the directory to be watched and the files to be included.</param> /// <returns>A <see cref="ReadOnlyListSubject{T}"/> that responds to changes from the specified <see cref="FileSystemWatcher"/> /// by adding the full paths of files that are created and removing those that are deleted, and also adds the full paths to all /// of the files that initially exist within the scope of the specified <see cref="FileSystemWatcher"/>.</returns> public static ReadOnlyListSubject <string> Collect(this FileSystemWatcher watcher) { Contract.Requires(watcher != null); Contract.Ensures(Contract.Result <ReadOnlyListSubject <string> >() != null); return(watcher.CollectInternal(false, all => all.SelectMany(n => n.ToModifications()), Scheduler.CurrentThread)); }
/// <summary> /// Populates a <see cref="ReadOnlyListSubject{T}"/> with elements projected from the full paths to all of the files that currently exist within /// the scope of the specified <see cref="FileSystemWatcher"/>, and also responds to changes by adding elements projected from the full paths of files /// that are created and removing those that are deleted. /// </summary> /// <typeparam name="TResult">The type of the projected elements in the list.</typeparam> /// <param name="watcher">The object that specifies the directory to be watched and the files to be included.</param> /// <param name="selector">Projects a sequence of file change notifications into a sequence from which the list is populated.</param> /// <returns>A <see cref="ReadOnlyListSubject{T}"/> that responds to changes from the specified <see cref="FileSystemWatcher"/> /// by adding the full paths of files that are created and removing those that are deleted, and also adds the full paths to all /// of the files that initially exist within the scope of the specified <see cref="FileSystemWatcher"/>.</returns> public static ReadOnlyListSubject <TResult> Collect <TResult>( this FileSystemWatcher watcher, Func <IObservable <CollectionNotification <string> >, IObservable <CollectionModification <TResult> > > selector) { Contract.Requires(watcher != null); Contract.Requires(selector != null); Contract.Ensures(Contract.Result <ReadOnlyListSubject <TResult> >() != null); return(watcher.CollectInternal(false, selector, Scheduler.CurrentThread)); }