private void HandleChange(FileSystemWatcher watcher, string file) { WatcherInfo info = _patternsByWatcher[watcher]; Uri fileUri = new Uri(file, UriKind.Absolute); Uri rel = info.RootDirectory.MakeRelativeUri(fileUri); if (info.Patterns.Any(x => x.IsMatch(rel.ToString()))) { DemandTimer(); _timer.Change(_granularity, TimeSpan.FromMilliseconds(-1)); } }
public WatchEnvironment(Guid token, TimeSpan granularity, IEnumerable<WatchDefinition> definitions) { _token = token; _granularity = granularity; Dictionary<FileSystemWatcher, WatcherInfo> patternsByWatcher = new Dictionary<FileSystemWatcher, WatcherInfo>(); foreach (IGrouping<string, string> grouping in definitions.GroupBy(x => x?.RootDirectory?.TrimEnd('/', '\\'), x => x?.GlobbingPattern, StringComparer.OrdinalIgnoreCase)) { FileSystemWatcher watcher = new FileSystemWatcher(grouping.Key) {IncludeSubdirectories = true}; watcher.Changed += HandleChanged; watcher.Created += HandleCreated; watcher.Deleted += HandleDeleted; watcher.Renamed += HandleRenamed; patternsByWatcher[watcher] = new WatcherInfo(grouping.Key, grouping); } _patternsByWatcher = patternsByWatcher; }
public WatchEnvironment(Guid token, TimeSpan granularity, IEnumerable <WatchDefinition> definitions) { _token = token; _granularity = granularity; Dictionary <FileSystemWatcher, WatcherInfo> patternsByWatcher = new Dictionary <FileSystemWatcher, WatcherInfo>(); foreach (IGrouping <string, string> grouping in definitions.GroupBy(x => x?.RootDirectory?.TrimEnd('/', '\\'), x => x?.GlobbingPattern, StringComparer.OrdinalIgnoreCase)) { FileSystemWatcher watcher = new FileSystemWatcher(grouping.Key) { IncludeSubdirectories = true }; watcher.Changed += HandleChanged; watcher.Created += HandleCreated; watcher.Deleted += HandleDeleted; watcher.Renamed += HandleRenamed; patternsByWatcher[watcher] = new WatcherInfo(grouping.Key, grouping); } _patternsByWatcher = patternsByWatcher; }