Ejemplo n.º 1
0
        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));
            }
        }
Ejemplo n.º 2
0
        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;
        }
Ejemplo n.º 3
0
        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;
        }