示例#1
0
        /// <summary>
        /// Start watching for the folder changes.
        /// </summary>
        public void Start(CancellationToken token)
        {
            // stop what might have already started.
            Stop();

            _token = token;

            // it is posible that we are trying to (re)start an event that was
            // cancelled at some point.
            if (_token.IsCancellationRequested)
            {
                Logger.Information($"Could not start watcher, cancellation requested: {Folder.FullName}.");
                return;
            }

            // register the token cancellation
            _cancellationTokenRegistration = _token.Register(TokenCancellation);

            // start the event parser.
            FileEventsParser?.Start(_token);
            DirectoryEventsParser?.Start(_token);

            // start the file watcher
            StartFilesWatcher();

            // we can now start monitoring for tasks.
            // so we can remove the completed ones from time to time.
            StartTasksCleanupTimer();
        }
示例#2
0
 public async Task EventAsync(directorywatcher.interfaces.IFileSystemEvent fe, CancellationToken token)
 {
     if (fe.IsFile)
     {
         if (FileEventsParser != null)
         {
             await FileEventsParser.AddAsync(fe, token).ConfigureAwait(false);
         }
     }
     else
     {
         if (DirectoryEventsParser != null)
         {
             await DirectoryEventsParser.AddAsync(fe, token).ConfigureAwait(false);
         }
     }
 }
示例#3
0
        /// <summary>
        /// Stop the folder monitoring.
        /// </summary>
        public void Stop()
        {
            FileEventsParser?.Stop();
            DirectoryEventsParser?.Stop();

            // stop the cleanup timer
            // we don't need it anymore.
            // we will be cleaning them up below.
            StopTasksCleanupTimer();

            // we can then cancel the watchers
            // we have to do it outside th locks because "Dispose" will flush out
            // the remaining events... and they will need a lock to do that
            // so we might as well get out as soon as posible.
            _fileWatcher?.Stop();

            // stop the registration
            _cancellationTokenRegistration.Dispose();
        }