Exemple #1
0
        /// <summary>
        /// Raises a throttled event to any listeners of this instance.
        /// </summary>
        /// <param name="item">The identifying the event to raise.</param>
        private void RaiseEvent(PathEventItem item)
        {
            switch (item.PublishEventType)
            {
            case FileSystemEventType.Changed:
                if (this.Changed != null)
                {
                    this.Changed(this, item.PublishEventArgs);
                }

                break;

            case FileSystemEventType.Created:
                if (this.Created != null)
                {
                    this.Created(this, item.PublishEventArgs);
                }

                break;

            case FileSystemEventType.Deleted:
                if (this.Deleted != null)
                {
                    this.Deleted(this, item.PublishEventArgs);
                }

                break;

            case FileSystemEventType.Renamed:
                if (this.Renamed != null)
                {
                    this.Renamed(this, (RenamedEventArgs)item.PublishEventArgs);
                }

                break;

            default:
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture, "Cannot raise event type \"{0}\".", item.PublishEventType),
                          "item");
            }

            if (this.Operation != null)
            {
                this.Operation(this, item.PublishEventArgs);
            }
        }
Exemple #2
0
        /// <summary>
        /// Enqueues and possibly throttles an event for raising.
        /// </summary>
        /// <param name="path">The path that raised the original event.</param>
        /// <param name="eventType">The type of the original event that was raised.</param>
        /// <param name="e">The arguments passed when the original event was raised.</param>
        private void EnqueueEvent(string path, FileSystemEventType eventType, FileSystemEventArgs e)
        {
            DateTime now = DateTime.Now;
            string   key = this.Mode == FileSystemWatcherMode.Directory ? this.Path : path;

            lock (this.locker)
            {
                if (!this.pathEvents.ContainsKey(key))
                {
                    this.pathEvents[key] = new PathEventItem();
                }

                PathEventItem item = this.pathEvents[key];
                item.PublishEventArgs = e;
                item.PublishEventType = eventType;
                item.LastRaised       = now;
                item.RaisedCount++;
            }
        }
        /// <summary>
        /// Raises a throttled event to any listeners of this instance.
        /// </summary>
        /// <param name="item">The identifying the event to raise.</param>
        private void RaiseEvent(PathEventItem item)
        {
            switch (item.PublishEventType)
            {
                case FileSystemEventType.Changed:
                    if (this.Changed != null)
                    {
                        this.Changed(this, item.PublishEventArgs);
                    }

                    break;
                case FileSystemEventType.Created:
                    if (this.Created != null)
                    {
                        this.Created(this, item.PublishEventArgs);
                    }

                    break;
                case FileSystemEventType.Deleted:
                    if (this.Deleted != null)
                    {
                        this.Deleted(this, item.PublishEventArgs);
                    }

                    break;
                case FileSystemEventType.Renamed:
                    if (this.Renamed != null)
                    {
                        this.Renamed(this, (RenamedEventArgs)item.PublishEventArgs);
                    }

                    break;
                default:
                    throw new ArgumentException(
                        string.Format(CultureInfo.InvariantCulture, "Cannot raise event type \"{0}\".", item.PublishEventType),
                        "item");
            }

            if (this.Operation != null)
            {
                this.Operation(this, item.PublishEventArgs);
            }
        }