CmisSync.Lib.Producer.Watcher.RenamedFileSystemEventHandler.Handle C# (CSharp) Method

Handle() public method

Takes rename file system events and transforms them to rename events on queue.
public Handle ( object source, RenamedEventArgs e ) : void
source object source object
e System.IO.RenamedEventArgs Rename event from file system watcher
return void
        public virtual void Handle(object source, RenamedEventArgs e) {
            try {
                bool? isDirectory = this.fsFactory.IsDirectory(e.FullPath);

                if (isDirectory == null) {
                    this.queue.AddEvent(new StartNextSyncEvent(true));
                    return;
                }

                this.queue.AddEvent(new FSMovedEvent(e.OldFullPath, e.FullPath, (bool)isDirectory));
            } catch (Exception ex) {
                Logger.Warn(string.Format("Processing RenamedEventArgs {0} produces Exception => force crawl sync", e.ToString()), ex);
                this.queue.AddEvent(new StartNextSyncEvent(true));
            }
        }
    }

Usage Example

        public void HandleRenameFolderEvent() {
            var handler = new RenamedFileSystemEventHandler(this.queue.Object, this.fsFactory.Object);
            string newPath = Path.Combine(RootPath, this.newName);
            string oldPath = Path.Combine(RootPath, this.oldName);
            this.fsFactory.Setup(f => f.IsDirectory(newPath)).Returns((bool?)true);

            handler.Handle(null, this.CreateEvent(this.oldName, this.newName));

            this.queue.Verify(
                q =>
                q.AddEvent(
                It.Is<FSMovedEvent>(e => e.OldPath == oldPath && e.Name == this.newName && e.IsDirectory == true && e.LocalPath == newPath)),
                Times.Once());
            this.queue.VerifyThatNoOtherEventIsAddedThan<FSMovedEvent>();
        }
All Usage Examples Of CmisSync.Lib.Producer.Watcher.RenamedFileSystemEventHandler::Handle
RenamedFileSystemEventHandler