Ejemplo n.º 1
0
        public void StartWatching(string directory)
        {
            // TODO: Change dir instead of creation new?
            _fileSystemWatcher = _fileSystemWatcherWrapperFactory.Create(directory);

            SubscribeToEvents();
        }
Ejemplo n.º 2
0
 internal DiskWatcher(
     IFileSystemWatcherWrapper fileSystemWatcherWrapper,
     IWebLogger logger, IQueueProcessor queueProcessor)
 {
     _fileSystemWatcherWrapper = fileSystemWatcherWrapper;
     _webLogger      = logger;
     _queueProcessor = queueProcessor;
 }
Ejemplo n.º 3
0
 public TheClassThatActsOnFilesystemChanges(IFileSystemWatcherWrapper fileSystemWatcher)
 {
     this.fileSystemWatcher     = fileSystemWatcher;
     fileSystemWatcher.Changed += (sender, args) =>
     {
         //Do something...
     };
 }
Ejemplo n.º 4
0
        public DiskWatcher(IFileSystemWatcherWrapper fileSystemWatcherWrapper,
                           IServiceScopeFactory scopeFactory)
        {
            _fileSystemWatcherWrapper = fileSystemWatcherWrapper;
            var serviceProvider = scopeFactory.CreateScope().ServiceProvider;

            _webLogger = serviceProvider.GetService <IWebLogger>();
            var memoryCache = serviceProvider.GetService <IMemoryCache>();

            _queueProcessor = new QueueProcessor(scopeFactory, new SyncWatcherConnector(scopeFactory).Sync, memoryCache);
        }
Ejemplo n.º 5
0
        private void CleanupFileSystemWatcher()
        {
            if (_fileSystemWatcher is null)
            {
                return;
            }

            UnsubscribeFromEvents();

            _fileSystemWatcher.Dispose();
            _fileSystemWatcher = null;
        }
        public AdaptiveFileSystemWatch(IFileSystemWatchWrapperFactory watchWrapperFactory, IFileSystem fileSystem,
                                       string path, bool recursive = false, string filter = null)
        {
            this.watchWrapperFactory = watchWrapperFactory;
            this.fileSystem          = fileSystem;
            this.recursive           = recursive;
            watch = watchWrapperFactory.CreateWatch(path, false, filter);
            watch.AddListener(this);

            if (recursive)
            {
                ScanChildPaths(path);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// @see: https://www.codeguru.com/dotnet/filesystemwatcher%EF%BF%BDwhy-does-it-stop-working/
        /// </summary>
        internal bool Retry(IFileSystemWatcherWrapper fileSystemWatcherWrapper, int numberOfTries = 20, int milliSecondsTimeout = 5000)
        {
            _webLogger.LogInformation("[DiskWatcher] next retry " +
                                      $"{DateTimeDebug()}");
            var path = _fileSystemWatcherWrapper.Path;

            _fileSystemWatcherWrapper.Dispose();
            _fileSystemWatcherWrapper = fileSystemWatcherWrapper;

            var i = 0;

            while (!_fileSystemWatcherWrapper.EnableRaisingEvents && i < numberOfTries)
            {
                try
                {
                    // This will throw an error at the
                    // watcher.NotifyFilter line if it can't get the path.
                    Watcher(path);
                    if (_fileSystemWatcherWrapper.EnableRaisingEvents)
                    {
                        _webLogger.LogInformation("[DiskWatcher] I'm Back!");
                    }
                    return(true);
                }
                catch
                {
                    _webLogger.LogInformation($"[DiskWatcher] next retry {i} - wait for {milliSecondsTimeout}ms");
                    // Sleep for a bit; otherwise, it takes a bit of
                    // processor time
                    System.Threading.Thread.Sleep(milliSecondsTimeout);
                    i++;
                }
            }
            _webLogger.LogError($"[DiskWatcher] Failed after {i} times - so stop trying");
            return(false);
        }
Ejemplo n.º 8
0
 public void Setup()
 {
     _fakeTimer   = Substitute.For <ITimerWrapper>();
     _fakeWatcher = Substitute.For <IFileSystemWatcherWrapper>();
     _uut         = new FileMonitor(_fakeWatcher, _fakeTimer);
 }
Ejemplo n.º 9
0
 public FolderMonitor(IFileSystemWatcherWrapper watcher) : base(watcher)
 {
 }
Ejemplo n.º 10
0
 public FileMonitor(IFileSystemWatcherWrapper watcher, ITimerWrapper timer) : base(watcher)
 {
     _timer = timer;
 }
Ejemplo n.º 11
0
        public void StartWatching(string directory)
        {
            _fileSystemWatcher = _fileSystemWatcherWrapperFactory.Create(directory);

            SubscribeToEvents();
        }
 public override void Dispose()
 {
     base.Dispose();
     watch?.Dispose();
     watch = null;
 }
 public DefaultFileSystemWatch(IFileSystemWatchWrapperFactory watchWrapperFactory, string path, bool recursive = false, string filter = null)
 {
     watch = watchWrapperFactory.CreateWatch(path, recursive, filter);
     watch.AddListener(this);
 }
Ejemplo n.º 14
0
 protected AbstractMonitor(IFileSystemWatcherWrapper watcher)
 {
     Watcher = watcher;
 }