public void WatchDirectories(ICollection <string> monitoringPaths, ICollection <string> extensions, int newPageTimeout = 10)
        {
            ImageExtensions = extensions;
            NewPageTimeout  = newPageTimeout;
            if (!_isSubscribedToTimerEvent)
            {
                _timer.Elapsed           += _timer_Elapsed;
                _isSubscribedToTimerEvent = true;
            }

            if (_watchers == null)
            {
                _watchers = new List <FileSystemWatcher>();
            }

            foreach (var path in monitoringPaths)
            {
                if (!Directory.Exists(path))
                {
                    throw new DirectoryNotFoundException($"Directory '{path}' was not found.");
                }

                var watcher = new FileSystemWatcher(path);
                watcher.WatcherSettings(Watcher_Created, Watcher_Error);
                _watchers.Add(watcher);
            }
        }
Beispiel #2
0
        public ImageWatcher(ICollection <string> monitoringPaths, int newPageTimeout)
        {
            NewPageTimeout = newPageTimeout;
            _imagesNames   = new List <string>();
            _timer         = new Timer
            {
                Interval  = NewPageTimeout,
                AutoReset = false,
            };
            _timer.Elapsed += _timer_Elapsed;

            _watchers = new List <FileSystemWatcher>();
            foreach (var path in monitoringPaths)
            {
                if (!Directory.Exists(path))
                {
                    throw new DirectoryNotFoundException($"Directory '{path}' was not found.");
                }

                var watcher = new FileSystemWatcher(path);
                watcher.WatcherSettings(Watcher_Created, Watcher_Error);
                _watchers.Add(watcher);
            }
        }