Last active
August 29, 2015 14:05
-
-
Save kstrauss/c5640251967239cc9ca9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void Main() | |
{ | |
var fsw = new FileSystemWatcher(@"c:\"){ | |
IncludeSubdirectories = true | |
}; | |
fsw.EnableRaisingEvents = true; | |
var created = Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(h=>fsw.Created+=h,h=>fsw.Created-=h); | |
var changed = Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(h=>fsw.Changed+=h,h=>fsw.Changed-=h); | |
var deleted = Observable.FromEventPattern<FileSystemEventHandler, FileSystemEventArgs>(h=>fsw.Deleted+=h,h=>fsw.Deleted-=h); | |
var renamed = Observable.FromEventPattern<RenamedEventHandler, FileSystemEventArgs>(h=>fsw.Renamed+=h,h=>fsw.Renamed-=h); | |
created.Merge(changed) | |
.Merge(deleted) | |
.Merge(renamed) | |
.Select(x=>x.EventArgs) | |
.Select(x=>String.Format("{1} was {0}",x.ChangeType,x.FullPath)) | |
.DistinctUntilChanged() | |
// use linqpad's utility observer | |
.DumpLive(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment