public virtual bool IsDuplicate(object obj) { DelayedEvent delayedEvent = obj as DelayedEvent; if (delayedEvent == null) { return(false); // this is not null so they are different } FileSystemEventArgs eO1 = _args; RenamedEventArgs reO1 = _args as RenamedEventArgs; FileSystemEventArgs eO2 = delayedEvent._args; RenamedEventArgs reO2 = delayedEvent._args as RenamedEventArgs; // The events are equal only if they are of the same type (reO1 and reO2 // are both null or NOT NULL) and have all properties equal. // We also eliminate Changed events that follow recent Created events // because many apps create new files by creating an empty file and then // they update the file with the file content. return(((eO1 != null && eO2 != null && eO1.ChangeType == eO2.ChangeType && eO1.FullPath == eO2.FullPath && eO1.Name == eO2.Name) && ((reO1 == null && reO2 == null) || (reO1 != null && reO2 != null && reO1.OldFullPath == reO2.OldFullPath && reO1.OldName == reO2.OldName))) || (eO1 != null && eO2 != null && eO1.ChangeType == WatcherChangeTypes.Created && eO2.ChangeType == WatcherChangeTypes.Changed && eO1.FullPath == eO2.FullPath && eO1.Name == eO2.Name)); }
protected void RaiseEvents(Queue deQueue) { if ((deQueue != null) && (deQueue.Count > 0)) { DelayedEvent de = null; SmartFileSystemEventArgs eArgs = null; SmartFileSystemRenamedEventArgs reArgs = null; var deQueueClone = (Queue)deQueue.Clone(); var deConsolidated = new List <FileSystemEventArgs>(); while (deQueueClone.Count > 0) { de = deQueueClone.Dequeue() as DelayedEvent; deConsolidated.Add(de.Args); } while (deQueue.Count > 0) { de = deQueue.Dequeue() as DelayedEvent; if (de.Args.ChangeType == WatcherChangeTypes.Renamed) { reArgs = new SmartFileSystemRenamedEventArgs(de.Args as RenamedEventArgs); reArgs.ConsolidatedEvents = deConsolidated; } else { eArgs = new SmartFileSystemEventArgs(de.Args); eArgs.ConsolidatedEvents = deConsolidated; } switch (de.Args.ChangeType) { case WatcherChangeTypes.Changed: OnChanged(eArgs); break; case WatcherChangeTypes.Created: OnCreated(eArgs); break; case WatcherChangeTypes.Deleted: OnDeleted(eArgs); break; case WatcherChangeTypes.Renamed: OnRenamed(reArgs); break; } } } }