Renamed file system event handler.
        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>();
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetWatcher"/> class.
        /// Takes the given file system watcher and listens for events and passes them to the given queue
        /// </summary>
        /// <param name="watcher">File System Watcher.</param>
        /// <param name="queue">Queue for the occured events.</param>
        /// <param name="storage">Meta Data Storage to verify, if a deleted object is a file or folder.</param>
        /// <param name="fsFactory">File system info factory. If factory is null, the normal file system is used, otherwise the given factory.</param>
        public NetWatcher(
            FileSystemWatcher watcher,
            ISyncEventQueue queue,
            IMetaDataStorage storage,
            FileSystemInfoFactory fsFactory = null)
        {
            if (watcher == null)
            {
                throw new ArgumentNullException("The given fs watcher must not be null");
            }

            if (string.IsNullOrEmpty(watcher.Path))
            {
                throw new ArgumentException("The given watcher must contain a path, where it is listening");
            }

            if (queue == null)
            {
                throw new ArgumentNullException("The given queue must not be null");
            }

            if (storage == null)
            {
                throw new ArgumentNullException("The given storage must not be null");
            }

            this.fsFactory = fsFactory ?? new FileSystemInfoFactory();

            this.queue   = queue;
            this.storage = storage;

            this.fileSystemWatcher = watcher;
            this.fileSystemWatcher.IncludeSubdirectories = true;
            this.fileSystemWatcher.Filter             = "*";
            this.fileSystemWatcher.InternalBufferSize = 4 * 1024 * 16;
            this.fileSystemWatcher.NotifyFilter       = NotifyFilters.Size | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite | NotifyFilters.Security;

            this.createChangeDeleteHandler = new CreatedChangedDeletedFileSystemEventHandler(this.queue, this.storage, this.fsFactory);
            this.renamedHandler            = new RenamedFileSystemEventHandler(this.queue, this.fsFactory);

            this.fileSystemWatcher.Created += new FileSystemEventHandler(this.createChangeDeleteHandler.Handle);
            this.fileSystemWatcher.Deleted += new FileSystemEventHandler(this.createChangeDeleteHandler.Handle);
            this.fileSystemWatcher.Changed += new FileSystemEventHandler(this.createChangeDeleteHandler.Handle);
            this.fileSystemWatcher.Renamed += new RenamedEventHandler(this.renamedHandler.Handle);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NetWatcher"/> class.
        /// Takes the given file system watcher and listens for events and passes them to the given queue
        /// </summary>
        /// <param name="watcher">File System Watcher.</param>
        /// <param name="queue">Queue for the occured events.</param>
        /// <param name="storage">Meta Data Storage to verify, if a deleted object is a file or folder.</param>
        /// <param name="fsFactory">File system info factory. If factory is null, the normal file system is used, otherwise the given factory.</param>
        public NetWatcher(
            FileSystemWatcher watcher,
            ISyncEventQueue queue,
            IMetaDataStorage storage,
            FileSystemInfoFactory fsFactory = null)
        {
            if (watcher == null) {
                throw new ArgumentNullException("watcher");
            }

            if (string.IsNullOrEmpty(watcher.Path)) {
                throw new ArgumentException("The given watcher must contain a path, where it is listening");
            }

            if (queue == null) {
                throw new ArgumentNullException("queue");
            }

            if (storage == null) {
                throw new ArgumentNullException("storage");
            }

            this.fsFactory = fsFactory ?? new FileSystemInfoFactory();

            this.queue = queue;
            this.storage = storage;

            this.fileSystemWatcher = watcher;
            this.fileSystemWatcher.IncludeSubdirectories = true;
            this.fileSystemWatcher.Filter = "*";
            this.fileSystemWatcher.InternalBufferSize = 4 * 1024 * 16;
            this.fileSystemWatcher.NotifyFilter = NotifyFilters.Size | NotifyFilters.FileName | NotifyFilters.DirectoryName | NotifyFilters.LastWrite | NotifyFilters.Security;

            this.createChangeDeleteHandler = new CreatedChangedDeletedFileSystemEventHandler(this.queue, this.storage, this.fsFactory);
            this.renamedHandler = new RenamedFileSystemEventHandler(this.queue, this.fsFactory);

            this.fileSystemWatcher.Created += new FileSystemEventHandler(this.createChangeDeleteHandler.Handle);
            this.fileSystemWatcher.Deleted += new FileSystemEventHandler(this.createChangeDeleteHandler.Handle);
            this.fileSystemWatcher.Changed += new FileSystemEventHandler(this.createChangeDeleteHandler.Handle);
            this.fileSystemWatcher.Renamed += new RenamedEventHandler(this.renamedHandler.Handle);
        }
        public void HandleExceptionsByInvokingCrawlSync() {
            var handler = new RenamedFileSystemEventHandler(this.queue.Object, this.fsFactory.Object);
            string newPath = Path.Combine(RootPath, this.newName);
            this.fsFactory.Setup(f => f.IsDirectory(newPath)).Throws(new Exception("IOException"));

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

            this.queue.VerifyThatNoOtherEventIsAddedThan<StartNextSyncEvent>();
            this.queue.Verify(q => q.AddEvent(It.Is<StartNextSyncEvent>(e => e.FullSyncRequested == true)), Times.Once);
        }
        public void HandleRenameEventOfNonExistingPath() {
            var handler = new RenamedFileSystemEventHandler(this.queue.Object, this.fsFactory.Object);
            string newPath = Path.Combine(RootPath, this.newName);
            this.fsFactory.Setup(f => f.IsDirectory(newPath)).Returns((bool?)null);

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

            this.queue.VerifyThatNoOtherEventIsAddedThan<StartNextSyncEvent>();
            this.queue.Verify(q => q.AddEvent(It.Is<StartNextSyncEvent>(e => e.FullSyncRequested == true)), Times.Once);
        }