Example #1
0
 /// <summary>
 /// Raises all queued events.
 /// </summary>
 /// <exception cref="ArgumentNullException">
 /// The parameter "eventQueue" is a null reference.
 /// </exception>
 /// <param name="eventQueue"></param>
 private void RaiseEvents(Queue <FileWatchEvent> eventQueue)
 {
     if (eventQueue == null)
     {
         throw new ArgumentNullException("eventQueue", "The parameter \"eventQueue\" is a null reference.");
     }
     while (eventQueue.Count > 0)
     {
         var watchEvent           = eventQueue.Dequeue();
         IFileWatchEventArgs args = new FileWatchEventArgs(watchEvent);
         foreach (var info in _subscriptions.Keys)
         {
             if (info.MayRaiseEventFor(args))
             {
                 Task.Run(() => RaiseEvent(new EventData(info, args)));
             }
         }
     }
 }
Example #2
0
        /// <summary>
        /// Adds a new <see cref="FileWatcherInfo"/> to the current <see cref="FileWatcher"/>.
        /// The <see cref="FileEventHandler"/> in the specified <see cref="fileWatcherInfo"/> will be called on a change in the current watch.
        /// </summary>
        /// <exception cref="InvalidFileWatchInfoException">
        /// The given <see cref="fileWatcherInfo"/> contains a different path than the one being watched.
        /// </exception>
        /// <param name="fileWatcherInfo">The <see cref="fileWatcherInfo"/> to add.</param>
        public void AddSubscription(FileWatcherInfo fileWatcherInfo)
        {
            if (!_watchedPath.IsEquivalentPath(fileWatcherInfo.Path))
            {
                throw new InvalidFileWatchInfoException("The specified path does not equal the watched path.");
            }

            if (!_subscriptions.TryAdd(fileWatcherInfo, DateTime.Now))
            {
                return; // The given subscription already exists
            }
            if (fileWatcherInfo.EventHandler == null)
            {
                return; // No event to call
            }
            var eventArgs = new FileWatchEventArgs(_watching
                                               ? FileWatchChangeType.Enabled
                                               : FileWatchChangeType.Disabled,
                                                   fileWatcherInfo.Path);

            RaiseEvent(new EventData(fileWatcherInfo, eventArgs));
        }
Example #3
0
 /// <summary>
 /// Adds a new <see cref="FileWatcherInfo"/> to the current <see cref="FileWatcher"/>.
 /// The <see cref="FileEventHandler"/> in the specified <see cref="fileWatcherInfo"/> will be called on a change in the current watch.
 /// </summary>
 /// <exception cref="InvalidFileWatchInfoException">
 /// The given <see cref="fileWatcherInfo"/> contains a different path than the one being watched.
 /// </exception>
 /// <param name="fileWatcherInfo">The <see cref="fileWatcherInfo"/> to add.</param>
 public void AddSubscription(FileWatcherInfo fileWatcherInfo)
 {
     if (fileWatcherInfo.Path != _watchedPath.Path.FullName)
     {
         throw new InvalidFileWatchInfoException("The specified path does not equal the watched path.");
     }
     lock (_subscriptions)
     {
         if (_subscriptions.Contains(fileWatcherInfo))
         {
             return; // The given subscription already exists
         }
         _subscriptions.Add(fileWatcherInfo);
         if (fileWatcherInfo.EventHandler == null)
         {
             return; // No event to call
         }
         var eventArgs = new FileWatchEventArgs(_watching
                                          ? FileWatchChangeType.Enabled
                                          : FileWatchChangeType.Disabled,
                                                fileWatcherInfo.Path);
         RaiseEvent(new EventData(fileWatcherInfo, eventArgs));
     }
 }
Example #4
0
 /// <summary>
 /// Raises all queued events.
 /// </summary>
 /// <exception cref="ArgumentNullException">
 /// The parameter "eventQueue" is a null reference.
 /// </exception>
 /// <param name="eventQueue"></param>
 private void RaiseEvents(Queue<FileWatchEvent> eventQueue)
 {
   if (eventQueue == null)
     throw new ArgumentNullException("eventQueue", "The parameter \"eventQueue\" is a null reference.");
   while (eventQueue.Count > 0)
   {
     var watchEvent = eventQueue.Dequeue();
     IFileWatchEventArgs args = new FileWatchEventArgs(watchEvent);
     lock (_subscriptions)
     {
       foreach (var info in _subscriptions)
       {
         if (info.MayRaiseEventFor(args))
           new Thread(RaiseEvent).Start(new EventData(info, args));
       }
     }
   }
 }
Example #5
0
 /// <summary>
 /// Adds a new <see cref="FileWatcherInfo"/> to the current <see cref="FileWatcher"/>.
 /// The <see cref="FileEventHandler"/> in the specified <see cref="fileWatcherInfo"/> will be called on a change in the current watch.
 /// </summary>
 /// <exception cref="InvalidFileWatchInfoException">
 /// The given <see cref="fileWatcherInfo"/> contains a different path than the one being watched.
 /// </exception>
 /// <param name="fileWatcherInfo">The <see cref="fileWatcherInfo"/> to add.</param>
 public void AddSubscription(FileWatcherInfo fileWatcherInfo)
 {
   if (fileWatcherInfo.Path != _watchedPath.Path.FullName)
     throw new InvalidFileWatchInfoException("The specified path does not equal the watched path.");
   lock (_subscriptions)
   {
     if (_subscriptions.Contains(fileWatcherInfo))
       return; // The given subscription already exists
     _subscriptions.Add(fileWatcherInfo);
     if (fileWatcherInfo.EventHandler == null)
       return; // No event to call
     var eventArgs = new FileWatchEventArgs(_watching
                                              ? FileWatchChangeType.Enabled
                                              : FileWatchChangeType.Disabled,
                                            fileWatcherInfo.Path);
     RaiseEvent(new EventData(fileWatcherInfo, eventArgs));
   }
 }