CmisSync.Lib.Filter.IgnoreAlreadyHandledFsEventsFilter.Handle C# (CSharp) Метод

Handle() публичный Метод

Filters FSEvents if they signalize an add and are handled already. This occurs if the syncer creates a local object on file system.
public Handle ( ISyncEvent e ) : bool
e ISyncEvent Sync event
Результат bool
        public override bool Handle(ISyncEvent e) {
            if (e is IFSEvent) {
                var fsEvent = e as IFSEvent;
                IFileSystemInfo path = fsEvent.IsDirectory ? (IFileSystemInfo)this.fsFactory.CreateDirectoryInfo(fsEvent.LocalPath) : (IFileSystemInfo)this.fsFactory.CreateFileInfo(fsEvent.LocalPath);
                switch (fsEvent.Type) {
                case WatcherChangeTypes.Created:
                    return this.storage.GetObjectByLocalPath(path) != null;
                case WatcherChangeTypes.Renamed:
                    var obj = this.storage.GetObjectByLocalPath(path);
                    if (obj != null) {
                        if (obj.Guid != Guid.Empty) {
                            try {
                                Guid? guid = path.Uuid;
                                return guid == null ? false : guid == obj.Guid;
                            } catch (FileNotFoundException) {
                                return true;
                            } catch (DirectoryNotFoundException) {
                                return true;
                            }
                        } else {
                            return false;
                        }
                    } else {
                        return false;
                    }

                case WatcherChangeTypes.Deleted:
                    IMappedObject o = this.storage.GetObjectByLocalPath(path);
                    if (o == null) {
                        return true;
                    } else if (path.Exists) {
                        try {
                            Guid? uuid = path.Uuid;
                            if (uuid != null) {
                                return (Guid)uuid == o.Guid;
                            }
                        } catch (IOException) {
                        }
                    }

                    return false;
                default:
                    return false;
                }
            }

            return false;
        }
    }

Usage Example

 public void FilterIgnoresNonExistingPaths() {
     var storage = new Mock<IMetaDataStorage>();
     var fsFactory = new Mock<IFileSystemInfoFactory>();
     var filter = new IgnoreAlreadyHandledFsEventsFilter(storage.Object, fsFactory.Object);
     var fsEvent = new FSEvent(WatcherChangeTypes.Created, Path.Combine(Path.GetTempPath(), "path"), true);
     Assert.That(filter.Handle(fsEvent), Is.False);
 }
All Usage Examples Of CmisSync.Lib.Filter.IgnoreAlreadyHandledFsEventsFilter::Handle
IgnoreAlreadyHandledFsEventsFilter