Esempio n. 1
0
        public FileDropWatcher(string path, string filter, SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            _searchOption = searchOption;
            var includeSubdirectories = searchOption == SearchOption.AllDirectories;

            _path    = path;
            _watcher = new ObservableFileSystemWatcher(w => {
                w.Path                  = path;
                w.NotifyFilter          = NotifyFilters.LastWrite | NotifyFilters.FileName;
                w.IncludeSubdirectories = includeSubdirectories;
            });

            var renames = _watcher.Renamed.Select(r => new FileDropped(r));
            var creates = _watcher.Created.Select(c => new FileDropped(c));

            Dropped = creates
                      .Merge(renames)
                      .Merge(_pollResults)
                      .Where(dropped => Regex.IsMatch(dropped.Name, filter));
        }
Esempio n. 2
0
        public FileDropWatcher(string path, string filter, SearchOption searchOption = SearchOption.TopDirectoryOnly)
        {
            _searchOption = searchOption;
            var includeSubdirectories = searchOption == SearchOption.AllDirectories;

            _path    = path;
            _watcher = new ObservableFileSystemWatcher(w => {
                w.Path   = path;
                w.Filter = filter;
                // note: filtering on changes can help reduce excessive notifications, make sure to verify any changes with integration tests
                w.NotifyFilter          = NotifyFilters.LastWrite | NotifyFilters.FileName;
                w.IncludeSubdirectories = includeSubdirectories;
            });

            var renames = _watcher.Renamed.Select(r => new FileDropped(r));
            var creates = _watcher.Created.Select(c => new FileDropped(c));
            var changed = _watcher.Changed.Select(c => new FileDropped(c));

            Dropped = creates
                      .Merge(renames)
                      .Merge(changed)
                      .Merge(_pollResults)
                      .Where(dropped => Regex.IsMatch(dropped.Name, filter));
        }