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

Handle() public method

Raises the created/changed/deleted event as FSEvent.
public Handle ( object source, FileSystemEventArgs e ) : void
source object /// Source file system watcher. ///
e System.IO.FileSystemEventArgs /// Reported changes. ///
return void
        public virtual void Handle(object source, FileSystemEventArgs e) {
            try {
                bool isDirectory = false;
                if (e.ChangeType == WatcherChangeTypes.Deleted) {
                    var path = this.fsFactory.CreateFileInfo(e.FullPath);
                    var obj = this.storage.GetObjectByLocalPath(path);
                    Guid guid = Guid.Empty;
                    if (obj != null) {
                        isDirectory = obj.Type == MappedObjectType.Folder;
                        guid = obj.Guid;
                    }

                    this.AddEventToList(e, guid, isDirectory);
                } else {
                    bool? check = this.fsFactory.IsDirectory(e.FullPath);
                    if (check != null) {
                        isDirectory = (bool)check;
                        IFileSystemInfo fsInfo = isDirectory ? (IFileSystemInfo)this.fsFactory.CreateDirectoryInfo(e.FullPath) : (IFileSystemInfo)this.fsFactory.CreateFileInfo(e.FullPath);
                        Guid uuid = Guid.Empty;
                        try {
                            Guid? fsGuid = fsInfo.Uuid;
                            if (fsGuid != null) {
                                uuid = (Guid)fsGuid;
                            }
                        } catch(Exception) {
                            uuid = Guid.Empty;
                        }

                        this.AddEventToList(e, uuid, isDirectory);
                    }
                }
            } catch (Exception ex) {
                Logger.Warn(string.Format("Processing file system event {0} produces exception => force crawl sync", e.ToString()), ex);
                this.queue.AddEvent(new StartNextSyncEvent(true));
            }
        }

Usage Example

        public void HandlesFileCreatedEvent() {
            using (var underTest = new CreatedChangedDeletedFileSystemEventHandler(this.queue.Object, this.storage.Object, this.fsFactory.Object)) {
                this.fsFactory.Setup(f => f.IsDirectory(this.path)).Returns((bool?)false);
                this.fsFactory.AddFile(this.path, true);
                underTest.Handle(null, new FileSystemEventArgs(WatcherChangeTypes.Created, Directory, Name));

                this.WaitForThreshold();
                this.queue.Verify(q => q.AddEvent(It.Is<FSEvent>(e => e.IsDirectory == false && e.Name == Name && e.LocalPath == this.path && e.Type == WatcherChangeTypes.Created)), Times.Once());
                this.queue.VerifyThatNoOtherEventIsAddedThan<FSEvent>();
            }
        }
All Usage Examples Of CmisSync.Lib.Producer.Watcher.CreatedChangedDeletedFileSystemEventHandler::Handle