static void OnFileDeletedEvent(object sender, FileDeletedEventArgs e) { lock (Lock) { Console.WriteLine("OnFileDeletedEvent:"); Console.WriteLine(" FilePath = {0}", e.FilePath); Console.WriteLine(); } }
private void OnFileDeleted(object sender, FileSystemEventArgs e) { var filePath = e.FullPath; //There is no good way of detecting files without extensions and directories with full stops in name. The file/directory has been deleted so we can't find it out from the path. var isDirectory = Path.GetExtension(filePath) == string.Empty; if (isDirectory) { lock (_filesRaisingEventsLock) { var filesInDirectory = _filesChanging.Keys.Where(x => x.StartsWith(e.FullPath + "/")); foreach (var fileInDirectory in filesInDirectory) { Pop(fileInDirectory); } } var directoryDeletedEventArgs = new DirectoryDeletedEventArgs(e.FullPath, UserState); RaiseAsynchronousOnDirectoryDeletedEvent(directoryDeletedEventArgs); return; } if (!ShouldMonitorFile(filePath)) return; lock (_filesRaisingEventsLock) { if (_filesChanging.ContainsKey(filePath)) { Pop(filePath); var fileFinishedChangingEventArgs = new FileFinishedChangingEventArgs(filePath, FileEventType.Deleted, UserState); RaiseAsynchronousOnFileFinishedChangingEvent(fileFinishedChangingEventArgs); } } var fileDeletedEventArgs = new FileDeletedEventArgs(e.FullPath, UserState); RaiseAsynchronousOnFileDeletedEvent(fileDeletedEventArgs); }
/// <summary> /// Will raise the event on the current thread synchronously. /// i.e. it will wait until all event handlers have processed the event. /// </summary> /// <param name="e">The state to be passed to the event.</param> private void RaiseOnFileDeletedEvent(FileDeletedEventArgs e) { // Make a temporary copy of the event to avoid possibility of // a race condition if the last subscriber unsubscribes // immediately after the null check and before the event is raised. FileDeletedEventHandler eventHandler; if (!Monitor.TryEnter(_fileDeletedEventLock, _lockTimeout)) { throw new ApplicationException("Timeout waiting for lock - RaiseOnFileDeletedEvent"); } try { eventHandler = _fileDeletedEvent; } finally { Monitor.Exit(_fileDeletedEventLock); } OnFileDeletedEvent(e); if (eventHandler != null) { eventHandler(this, e); } }
/// <summary> /// Will raise the event on the calling thread synchronously. /// i.e. it will wait until all event handlers have processed the event. /// </summary> /// <param name="state">The state to be passed to the event.</param> private void RaiseCrossThreadOnFileDeletedEvent(FileDeletedEventArgs e) { _asyncOperation.SynchronizationContext.Send(new SendOrPostCallback(AsynchronousOnFileDeletedEventRaised), e); }
/// <summary> /// Will raise the event on the calling thread asynchronously. /// i.e. it will immediatly continue processing even though event /// handlers have not processed the event yet. /// </summary> /// <param name="state">The state to be passed to the event.</param> private void RaiseAsynchronousOnFileDeletedEvent(FileDeletedEventArgs e) { _asyncOperation.Post(new SendOrPostCallback(AsynchronousOnFileDeletedEventRaised), e); }
/// <summary> /// Template method to add default behaviour for the event /// </summary> private void OnFileDeletedEvent(FileDeletedEventArgs e) { // TODO: Implement default behaviour of OnFileDeletedEvent }