/// <summary> /// Initializes a new instance of the PathEventItem class. /// </summary> /// <param name="info">The <see cref="SerializationInfo"/> to load data from..</param> /// <param name="context">The source <see cref="StreamingContext"/> for this serialization.</param> public PathEventItem(SerializationInfo info, StreamingContext context) { if (info == null) { throw new ArgumentNullException("info", "info cannot be null."); } this.publishEventArgs = (FileSystemEventArgs)info.GetValue("publishEventArgs", typeof(FileSystemEventArgs)); this.publishEventType = (TastyFileSystemEventType)Enum.ToObject(typeof(TastyFileSystemEventType), info.GetInt32("publishEventType")); this.lastRaised = info.GetDateTime("lastRaised"); this.raisedCount = info.GetInt32("raisedCount"); }
/// <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, TastyFileSystemEventType eventType, FileSystemEventArgs e) { DateTime now = DateTime.Now; string key = this.Mode == TastyFileSystemWatcherMode.Directory ? this.Path : path; lock (this.pathEvents) { if (!this.pathEvents.ContainsKey(key)) { this.pathEvents[key] = new PathEventItem(); } PathEventItem item = this.pathEvents[key]; if (item.RaisedCount == 0 || now.Subtract(item.LastRaised).TotalMilliseconds > this.Threshold) { item.PublishEventArgs = e; item.PublishEventType = eventType; this.RaiseEvent(item); } item.LastRaised = now; item.RaisedCount++; } }