File moved event.
Inheritance: FileEvent
示例#1
0
        /// <summary>
        /// Handles the FSEvents of files and creates FileEvents.
        /// </summary>
        /// <param name='e'>
        /// The FSEvent.
        /// </param>
        private void HandleFileEvents(IFSEvent e) {
            var movedEvent = e as IFSMovedEvent;
            if (movedEvent != null) {
                var oldfile = this.fsFactory.CreateFileInfo(movedEvent.OldPath);
                var newfile = this.fsFactory.CreateFileInfo(movedEvent.LocalPath);
                var newEvent = new FileMovedEvent(
                    oldfile,
                    newfile,
                    null,
                    null);
                Queue.AddEvent(newEvent);
            } else {
                var file = this.fsFactory.CreateFileInfo(e.LocalPath);
                var newEvent = new FileEvent(file, null);
                switch (e.Type) {
                case WatcherChangeTypes.Created:
                    newEvent.Local = MetaDataChangeType.CREATED;
                    newEvent.LocalContent = ContentChangeType.CREATED;
                    break;
                case WatcherChangeTypes.Changed:
                    newEvent.LocalContent = ContentChangeType.CHANGED;
                    break;
                case WatcherChangeTypes.Deleted:
                    newEvent.Local = MetaDataChangeType.DELETED;
                    newEvent.LocalContent = ContentChangeType.DELETED;
                    break;
                }

                Queue.AddEvent(newEvent);
            }
        }
 public void FileMovedEventWithoutLocalPath() {
     var session = new Mock<ISession>();
     var fetcher = new RemoteObjectFetcher(session.Object, Mock.Of<IMetaDataStorage>());
     var fileMovedEvent = new FileMovedEvent(null, null, Path, Mock.Of<IDocument>());
     Assert.That(fetcher.Handle(fileMovedEvent), Is.False);
     session.Verify(s => s.GetObject(It.IsAny<string>(), It.IsAny<IOperationContext>()), Times.Never());
 }
        public void NotifyMultipleChangeEvents() {
            var file = Mock.Of<IFileInfo>();
            var oldfile = Mock.Of<IFileInfo>();
            var fileEvent = new FileMovedEvent(oldfile, file);
            var doc = Mock.Of<IDocument>();
            var docEvent = new FileEvent(null, doc) {
                Remote = MetaDataChangeType.DELETED
            };
            var doc2 = Mock.Of<IDocument>();
            var doc2Event = new FileEvent(null, doc2) {
                Remote = MetaDataChangeType.CHANGED
            };
            this.collection.mergableEvents.Add("remoteId", new Tuple<AbstractFolderEvent, AbstractFolderEvent>(fileEvent, docEvent));
            this.collection.mergableEvents.Add("otherRemoteId", new Tuple<AbstractFolderEvent, AbstractFolderEvent>(null, doc2Event));

            this.underTest.MergeEventsAndAddToQueue(this.collection);
            this.queue.VerifyThatNoOtherEventIsAddedThan<FileEvent>();
            this.queue.Verify(q => q.AddEvent(It.Is<FileEvent>(e => e.LocalFile == file && e.RemoteFile == doc && e.Local == MetaDataChangeType.MOVED && e.Remote == MetaDataChangeType.DELETED)), Times.Once());
            this.queue.Verify(q => q.AddEvent(It.Is<FileEvent>(e => e.LocalFile == null && e.RemoteFile == doc2 && e.Local == MetaDataChangeType.NONE && e.Remote == MetaDataChangeType.CHANGED)), Times.Once());
            this.queue.Verify(q => q.AddEvent(It.IsAny<ISyncEvent>()), Times.Exactly(2));
        }