public void On(FileDeletedEvent @event) { string source = @event.Path; string target = @event.Sender == this.encryptedFolder.FolderName ? this.decryptedFolder.GetAbsolutePath(this.encryptedFolder.GetRelativePath(source)) : this.encryptedFolder.GetAbsolutePath(this.decryptedFolder.GetRelativePath(source)); this.operations.Enqueue(new DeleteFileOperation(target)); }
/// <summary> /// Initializes a new instance of the <see cref="FileWatcher"/> class. /// </summary> /// <param name="path">The path.</param> /// <param name="add">The add.</param> /// <param name="delete">The delete.</param> public FileWatcher(string path, FileAddedEvent add, FileDeletedEvent delete) { this.path = path; callbackAdded = add; callbackDeleted = delete; fileWatcher = new FileSystemWatcher(path, "*.*"); fileWatcher.Created += new FileSystemEventHandler(FileWatcherCreated); fileWatcher.Deleted += new FileSystemEventHandler(FileWatcherDeleted); fileWatcher.EnableRaisingEvents = true; }
public void Handle(FileDeletedEvent message) { foreach (var siteItemBase in Children.OfType <FileSystemSiteItem>()) { if (siteItemBase.Path == message.FileName) { Children.Remove(siteItemBase); break; } } }
public void HandleChange(FileSystemEventArgs args) { try { switch (args.ChangeType) { case WatcherChangeTypes.Created: { if (File.Exists(args.FullPath)) { this.Files.Add(new LocalFile(args.FullPath, this.FolderPath)); var @event = new FileCreatedEvent(args.FullPath, this.FolderName); this.eventListener.On(@event); Console.WriteLine($"Created: {args.FullPath}"); } break; } case WatcherChangeTypes.Deleted: { var toDelete = this.Files.FirstOrDefault(it => string.Equals(it.AbsolutePath, args.FullPath, StringComparison.InvariantCultureIgnoreCase)); this.Files.Remove(toDelete); var @event = new FileDeletedEvent(args.FullPath, this.FolderName); this.eventListener.On(@event); Console.WriteLine($"Deleted: {args.FullPath}"); break; } case WatcherChangeTypes.Changed: { if (File.Exists(args.FullPath)) { var @event = new FileChangedEvent(args.FullPath, this.FolderName); this.eventListener.On(@event); Console.WriteLine($"Changed: {args.FullPath}"); } break; } } } catch (Exception exception) { Console.WriteLine(exception.ToString()); } }