public void LocalFolderAddedSituation()
        {
            var localFolder            = Mock.Of <IDirectoryInfo>();
            var localFolderAddedSolver = new Mock <ISolver>();
            var localDetection         = new LocalSituationDetection();
            var remoteDetection        = new RemoteSituationDetection();
            var folderEvent            = new FolderEvent(localFolder: localFolder)
            {
                Local = MetaDataChangeType.CREATED, Remote = MetaDataChangeType.NONE
            };

            var mechanism = this.CreateMechanism(localDetection, remoteDetection);

            mechanism.Solver[(int)SituationType.ADDED, (int)SituationType.NOCHANGE] = localFolderAddedSolver.Object;

            Assert.IsTrue(mechanism.Handle(folderEvent));

            localFolderAddedSolver.Verify(
                s => s.Solve(
                    It.IsAny <IFileSystemInfo>(),
                    It.IsAny <IObjectId>(),
                    It.IsAny <ContentChangeType>(),
                    It.IsAny <ContentChangeType>()),
                Times.Once());
            this.VerifyThatListenerIsInformed();
        }
        public void NoChangeDetectionForFileOnAddedEvent()
        {
            var lastModificationDate = DateTime.Now;
            var remoteObject         = new Mock <IDocument>();
            var remotePaths          = new List <string>();

            remotePaths.Add(this.remotePath);
            remoteObject.Setup(remote => remote.ChangeToken).Returns(this.remoteChangeToken);
            remoteObject.Setup(remote => remote.Id).Returns(this.objectId.Id);
            remoteObject.Setup(remote => remote.LastModificationDate).Returns(lastModificationDate);
            remoteObject.Setup(remote => remote.Paths).Returns(remotePaths);
            var file = Mock.Of <IMappedObject>(f =>
                                               f.LastRemoteWriteTimeUtc == lastModificationDate &&
                                               f.RemoteObjectId == this.objectId.Id &&
                                               f.LastChangeToken == this.remoteChangeToken &&
                                               f.Type == MappedObjectType.File);

            this.storage.AddMappedFile(file);
            var fileEvent = new FileEvent(remoteFile: remoteObject.Object)
            {
                Remote = MetaDataChangeType.CREATED
            };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.NOCHANGE, underTest.Analyse(this.storage.Object, fileEvent));
        }
        public void FileMovedDetectionOnChangeEvent()
        {
            string fileName     = "old";
            string oldLocalPath = Path.Combine(Path.GetTempPath(), fileName);
            string remoteId     = "remoteId";
            string oldParentId  = "oldParentId";
            string newParentId  = "newParentId";
            var    remoteFile   = new Mock <IDocument>();

            remoteFile.Setup(f => f.Name).Returns(fileName);
            remoteFile.SetupPath("/new/" + fileName);
            remoteFile.Setup(f => f.Id).Returns(remoteId);
            remoteFile.SetupParent(Mock.Of <IFolder>(p => p.Id == newParentId));
            var mappedParentFolder = Mock.Of <IMappedObject>(p =>
                                                             p.RemoteObjectId == oldParentId &&
                                                             p.Type == MappedObjectType.Folder);
            var mappedFile = this.storage.AddLocalFile(oldLocalPath, remoteId);

            mappedFile.Setup(f => f.Name).Returns(fileName);
            mappedFile.Setup(f => f.ParentId).Returns(mappedParentFolder.RemoteObjectId);
            var fileEvent = new FileEvent(remoteFile: remoteFile.Object)
            {
                Remote = MetaDataChangeType.CHANGED
            };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.MOVED, underTest.Analyse(this.storage.Object, fileEvent));
        }
        public void FolderMovedDetectionOnChangeEvent()
        {
            string folderName   = "old";
            string oldLocalPath = Path.Combine(Path.GetTempPath(), folderName);
            string remoteId     = "remoteId";
            string oldParentId  = "oldParentId";
            string newParentId  = "newParentId";
            var    remoteFolder = new Mock <IFolder>();

            remoteFolder.Setup(f => f.Name).Returns(folderName);
            remoteFolder.Setup(f => f.Path).Returns("/new/" + folderName);
            remoteFolder.Setup(f => f.Id).Returns(remoteId);
            remoteFolder.Setup(f => f.ParentId).Returns(newParentId);
            var mappedParentFolder = Mock.Of <IMappedObject>(p =>
                                                             p.RemoteObjectId == oldParentId &&
                                                             p.Type == MappedObjectType.Folder);
            var mappedFolder = this.storageMock.AddLocalFolder(oldLocalPath, remoteId);

            mappedFolder.Setup(f => f.Name).Returns(folderName);
            mappedFolder.Setup(f => f.ParentId).Returns(mappedParentFolder.RemoteObjectId);
            var folderEvent = new FolderEvent(remoteFolder: remoteFolder.Object)
            {
                Remote = MetaDataChangeType.CHANGED
            };

            var detector = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.MOVED, detector.Analyse(this.storageMock.Object, folderEvent));
        }
        public void NoChangeDetectionForFile() {
            var lastModificationDate = DateTime.Now;
            var remoteObject = new Mock<IDocument>();
            var fileEvent = new FileEvent(remoteFile: remoteObject.Object);
            fileEvent.Remote = MetaDataChangeType.NONE;

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.NOCHANGE, underTest.Analyse(this.storage.Object, fileEvent));
        }
        public void NoChangeDetectedForFolder()
        {
            var remoteObject = new Mock <IFolder>();
            var folderEvent  = new FolderEvent(remoteFolder: remoteObject.Object);

            folderEvent.Remote = MetaDataChangeType.NONE;

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.NOCHANGE, underTest.Analyse(this.storage.Object, folderEvent));
        }
        public void FolderRemovedDetection()
        {
            var remoteObject = new Mock <IFolder>();
            var folderEvent  = new FolderEvent(remoteFolder: remoteObject.Object);

            folderEvent.Remote = MetaDataChangeType.DELETED;

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.REMOVED, underTest.Analyse(this.storage.Object, folderEvent));
        }
        public void FolderAddedDetection()
        {
            var remoteObject = new Mock <IFolder>();
            var folderEvent  = new FolderEvent(remoteFolder: remoteObject.Object);

            folderEvent.Remote = MetaDataChangeType.CREATED;

            var detector = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.ADDED, detector.Analyse(this.storageMock.Object, folderEvent));
        }
        public void NoChangeDetectionForFile()
        {
            var lastModificationDate = DateTime.Now;
            var remoteObject         = new Mock <IDocument>();
            var fileEvent            = new FileEvent(remoteFile: remoteObject.Object);

            fileEvent.Remote = MetaDataChangeType.NONE;

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.NOCHANGE, underTest.Analyse(this.storage.Object, fileEvent));
        }
        public void FolderMovedDetectionOnFolderMovedEvent()
        {
            var remoteObject = new Mock <IFolder>();
            var folderEvent  = new FolderMovedEvent(null, null, null, remoteObject.Object)
            {
                Remote = MetaDataChangeType.MOVED
            };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.MOVED, underTest.Analyse(this.storage.Object, folderEvent));
        }
        public void FileAddedDetection()
        {
            var remoteObject = new Mock <IDocument>();

            var fileEvent = new FileEvent(remoteFile: remoteObject.Object);

            fileEvent.Remote = MetaDataChangeType.CREATED;

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.ADDED, underTest.Analyse(this.storage.Object, fileEvent));
        }
        public void FileRemovedDetection()
        {
            var remoteObject = new Mock <IDocument>();

            var fileEvent = new FileEvent(remoteFile: remoteObject.Object);

            fileEvent.Remote = MetaDataChangeType.DELETED;

            var detector = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.REMOVED, detector.Analyse(this.storageMock.Object, fileEvent));
        }
        public void FileEventIsNotChangedIfSavedObjectIsEqualChangeToken()
        {
            var mappedFile = new MappedObject("name", "remoteId", MappedObjectType.File, "parentId", "changeToken");

            this.storage.AddMappedFile(mappedFile);
            var remoteObject = Mock.Of <IDocument>(o => o.Id == "remoteId" && o.ChangeToken == "changeToken");
            var fileEvent    = new FileEvent(remoteFile: remoteObject);

            fileEvent.Remote = MetaDataChangeType.NONE;

            var underTest = new RemoteSituationDetection();

            Assert.That(underTest.Analyse(this.storage.Object, fileEvent), Is.EqualTo(SituationType.NOCHANGE));
            Assert.That(fileEvent.Remote, Is.EqualTo(MetaDataChangeType.NONE));
        }
        public void FolderRenameDetectionOnChangeEvent()
        {
            string remoteId     = "remoteId";
            string oldName      = "old";
            string newName      = "new";
            var    remoteFolder = new Mock <IFolder>();

            remoteFolder.Setup(f => f.Name).Returns(newName);
            remoteFolder.Setup(f => f.Id).Returns(remoteId);
            var mappedFolder = Mock.Of <IMappedObject>(f =>
                                                       f.RemoteObjectId == remoteId &&
                                                       f.Name == oldName &&
                                                       f.Type == MappedObjectType.Folder);

            this.storageMock.AddMappedFolder(mappedFolder);
            var folderEvent = new FolderEvent(remoteFolder: remoteFolder.Object)
            {
                Remote = MetaDataChangeType.CHANGED
            };

            var detector = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.RENAMED, detector.Analyse(this.storageMock.Object, folderEvent));
        }
        public void FileRenameDetectionOnChangeEvent()
        {
            string remoteId   = "remoteId";
            string oldName    = "old";
            string newName    = "new";
            var    remoteFile = new Mock <IDocument>();

            remoteFile.Setup(f => f.Name).Returns(newName);
            remoteFile.Setup(f => f.Id).Returns(remoteId);
            var mappedFile = Mock.Of <IMappedObject>(f =>
                                                     f.RemoteObjectId == remoteId &&
                                                     f.Name == oldName &&
                                                     f.Type == MappedObjectType.File);

            this.storage.AddMappedFile(mappedFile);
            var folderEvent = new FileEvent(remoteFile: remoteFile.Object)
            {
                Remote = MetaDataChangeType.CHANGED
            };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.RENAMED, underTest.Analyse(this.storage.Object, folderEvent));
        }
        public void FolderRemovedDetection() {
            var remoteObject = new Mock<IFolder>();
            var folderEvent = new FolderEvent(remoteFolder: remoteObject.Object);
            folderEvent.Remote = MetaDataChangeType.DELETED;

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.REMOVED, underTest.Analyse(this.storage.Object, folderEvent));
        }
        public void FolderMovedDetectionOnFolderMovedEvent() {
            var remoteObject = new Mock<IFolder>();
            var folderEvent = new FolderMovedEvent(null, null, null, remoteObject.Object) { Remote = MetaDataChangeType.MOVED };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.MOVED, underTest.Analyse(this.storage.Object, folderEvent));
        }
        public void FileMovedDetectionOnChangeEvent() {
            string fileName = "old";
            string oldLocalPath = Path.Combine(Path.GetTempPath(), fileName);
            string remoteId = "remoteId";
            string oldParentId = "oldParentId";
            string newParentId = "newParentId";
            var remoteFile = new Mock<IDocument>();
            remoteFile.Setup(f => f.Name).Returns(fileName);
            remoteFile.SetupPath("/new/" + fileName);
            remoteFile.Setup(f => f.Id).Returns(remoteId);
            remoteFile.SetupParent(Mock.Of<IFolder>(p => p.Id == newParentId));
            var mappedParentFolder = Mock.Of<IMappedObject>(p =>
                p.RemoteObjectId == oldParentId &&
                p.Type == MappedObjectType.Folder);
            var mappedFile = this.storage.AddLocalFile(oldLocalPath, remoteId);
            mappedFile.Setup(f => f.Name).Returns(fileName);
            mappedFile.Setup(f => f.ParentId).Returns(mappedParentFolder.RemoteObjectId);
            var fileEvent = new FileEvent(remoteFile: remoteFile.Object) { Remote = MetaDataChangeType.CHANGED };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.MOVED, underTest.Analyse(this.storage.Object, fileEvent));
        }
        public void FileRenameDetectionOnChangeEvent() {
            string remoteId = "remoteId";
            string oldName = "old";
            string newName = "new";
            var remoteFile = new Mock<IDocument>();
            remoteFile.Setup(f => f.Name).Returns(newName);
            remoteFile.Setup(f => f.Id).Returns(remoteId);
            var mappedFile = Mock.Of<IMappedObject>(f =>
                f.RemoteObjectId == remoteId &&
                f.Name == oldName &&
                f.Type == MappedObjectType.File);
            this.storage.AddMappedFile(mappedFile);
            var folderEvent = new FileEvent(remoteFile: remoteFile.Object) { Remote = MetaDataChangeType.CHANGED };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.RENAMED, underTest.Analyse(this.storage.Object, folderEvent));
        }
Esempio n. 20
0
        private SingleStepEventQueue CreateQueue(Mock <ISession> session, IMetaDataStorage storage, ObservableHandler observer, IFileSystemInfoFactory fsFactory = null)
        {
            var manager = new SyncEventManager();
            SingleStepEventQueue queue = new SingleStepEventQueue(manager);

            manager.AddEventHandler(observer);

            var connectionScheduler = new ConnectionScheduler(new RepoInfo(), queue, Mock.Of <ISessionFactory>(), Mock.Of <IAuthenticationProvider>());

            manager.AddEventHandler(connectionScheduler);

            var changes = new ContentChanges(session.Object, storage, queue, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);

            manager.AddEventHandler(changes);

            var transformer = new ContentChangeEventTransformer(queue, storage, fsFactory);

            manager.AddEventHandler(transformer);

            var ccaccumulator = new ContentChangeEventAccumulator(session.Object, queue);

            manager.AddEventHandler(ccaccumulator);

            var remoteFetcher = new RemoteObjectFetcher(session.Object, storage);

            manager.AddEventHandler(remoteFetcher);

            var localFetcher = new LocalObjectFetcher(storage.Matcher, fsFactory);

            manager.AddEventHandler(localFetcher);

            var watcher = new Strategy.WatcherConsumer(queue);

            manager.AddEventHandler(watcher);

            var localDetection      = new LocalSituationDetection();
            var remoteDetection     = new RemoteSituationDetection();
            var transmissionManager = new ActiveActivitiesManager();
            var activityAggregator  = new ActivityListenerAggregator(Mock.Of <IActivityListener>(), transmissionManager);

            var ignoreFolderFilter      = new IgnoredFoldersFilter();
            var ignoreFolderNameFilter  = new IgnoredFolderNameFilter();
            var ignoreFileNamesFilter   = new IgnoredFileNamesFilter();
            var invalidFolderNameFilter = new InvalidFolderNameFilter();
            var filterAggregator        = new FilterAggregator(ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter, ignoreFolderFilter);

            var syncMechanism = new SyncMechanism(localDetection, remoteDetection, queue, session.Object, storage, activityAggregator, filterAggregator, isServerAbleToUpdateModificationDate: true);

            manager.AddEventHandler(syncMechanism);

            var remoteFolder = MockSessionUtil.CreateCmisFolder();

            var localFolder = new Mock <IDirectoryInfo>();
            var generator   = new CrawlEventGenerator(storage, fsFactory);
            var treeBuilder = new DescendantsTreeBuilder(storage, remoteFolder.Object, localFolder.Object, filterAggregator);
            var notifier    = new CrawlEventNotifier(queue);
            var crawler     = new DescendantsCrawler(queue, treeBuilder, generator, notifier, Mock.Of <IActivityListener>());

            manager.AddEventHandler(crawler);

            var permissionDenied = new GenericHandleDublicatedEventsFilter <PermissionDeniedEvent, ConfigChangedEvent>();

            manager.AddEventHandler(permissionDenied);

            var alreadyAddedFilter = new IgnoreAlreadyHandledFsEventsFilter(storage, fsFactory);

            manager.AddEventHandler(alreadyAddedFilter);

            var ignoreContentChangesFilter = new IgnoreAlreadyHandledContentChangeEventsFilter(storage, session.Object);

            manager.AddEventHandler(ignoreContentChangesFilter);

            var delayRetryAndNextSyncEventHandler = new DelayRetryAndNextSyncEventHandler(queue);

            manager.AddEventHandler(delayRetryAndNextSyncEventHandler);

            /* This is not implemented yet
             * var failedOperationsFilder = new FailedOperationsFilter(queue);
             * manager.AddEventHandler(failedOperationsFilder);
             */

            var reportingFilter = new ReportingFilter(queue, ignoreFolderFilter, ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter);

            manager.AddEventHandler(reportingFilter);

            var debugHandler = new DebugLoggingHandler();

            manager.AddEventHandler(debugHandler);

            var movedOrRenamed = new RemoteObjectMovedOrRenamedAccumulator(queue, storage, fsFactory);

            manager.AddEventHandler(movedOrRenamed);

            return(queue);
        }
Esempio n. 21
0
        public void LocalFolderAddedSituation() {
            var localFolder = Mock.Of<IDirectoryInfo>();
            var localFolderAddedSolver = new Mock<ISolver>();
            var localDetection = new LocalSituationDetection();
            var remoteDetection = new RemoteSituationDetection();
            var folderEvent = new FolderEvent(localFolder: localFolder) { Local = MetaDataChangeType.CREATED, Remote = MetaDataChangeType.NONE };

            var mechanism = this.CreateMechanism(localDetection, remoteDetection);
            mechanism.Solver[(int)SituationType.ADDED, (int)SituationType.NOCHANGE] = localFolderAddedSolver.Object;

            Assert.IsTrue(mechanism.Handle(folderEvent));

            localFolderAddedSolver.Verify(
                s => s.Solve(
                It.IsAny<IFileSystemInfo>(),
                It.IsAny<IObjectId>(),
                It.IsAny<ContentChangeType>(),
                It.IsAny<ContentChangeType>()),
                Times.Once());
            this.VerifyThatListenerIsInformed();
        }
        public void FileAddedDetection() {
            var remoteObject = new Mock<IDocument>();

            var fileEvent = new FileEvent(remoteFile: remoteObject.Object);
            fileEvent.Remote = MetaDataChangeType.CREATED;

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.ADDED, underTest.Analyse(this.storage.Object, fileEvent));
        }
        public void FileEventIsNotChangedIfSavedObjectIsEqualChangeToken() {
            var mappedFile = new MappedObject("name", "remoteId", MappedObjectType.File, "parentId", "changeToken");
            this.storage.AddMappedFile(mappedFile);
            var remoteObject = Mock.Of<IDocument>(o => o.Id == "remoteId" && o.ChangeToken == "changeToken");
            var fileEvent = new FileEvent(remoteFile: remoteObject);
            fileEvent.Remote = MetaDataChangeType.NONE;

            var underTest = new RemoteSituationDetection();

            Assert.That(underTest.Analyse(this.storage.Object, fileEvent), Is.EqualTo(SituationType.NOCHANGE));
            Assert.That(fileEvent.Remote, Is.EqualTo(MetaDataChangeType.NONE));
        }
        public void NoChangeDetectionForFileOnAddedEvent() {
            var lastModificationDate = DateTime.Now;
            var remoteObject = new Mock<IDocument>();
            var remotePaths = new List<string>();
            remotePaths.Add(this.remotePath);
            remoteObject.Setup(remote => remote.ChangeToken).Returns(this.remoteChangeToken);
            remoteObject.Setup(remote => remote.Id).Returns(this.objectId.Id);
            remoteObject.Setup(remote => remote.LastModificationDate).Returns(lastModificationDate);
            remoteObject.Setup(remote => remote.Paths).Returns(remotePaths);
            var file = Mock.Of<IMappedObject>(f =>
                                              f.LastRemoteWriteTimeUtc == lastModificationDate &&
                                              f.RemoteObjectId == this.objectId.Id &&
                                              f.LastChangeToken == this.remoteChangeToken &&
                                              f.Type == MappedObjectType.File);
            this.storage.AddMappedFile(file);
            var fileEvent = new FileEvent(remoteFile: remoteObject.Object) { Remote = MetaDataChangeType.CREATED };

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.NOCHANGE, underTest.Analyse(this.storage.Object, fileEvent));
        }
        public void NoChangeDetectedForFolder() {
            var remoteObject = new Mock<IFolder>();
            var folderEvent = new FolderEvent(remoteFolder: remoteObject.Object);
            folderEvent.Remote = MetaDataChangeType.NONE;

            var underTest = new RemoteSituationDetection();

            Assert.AreEqual(SituationType.NOCHANGE, underTest.Analyse(this.storage.Object, folderEvent));
        }
Esempio n. 26
0
        /// <summary>
        /// Handle the specified e if it is a SuccessfulLoginEvent
        /// </summary>
        /// <param name='e'>
        /// The event.
        /// </param>
        /// <returns>
        /// true if handled.
        /// </returns>
        public override bool Handle(ISyncEvent e)
        {
            if (e is SuccessfulLoginEvent)
            {
                var successfulLoginEvent = e as SuccessfulLoginEvent;
                var session = successfulLoginEvent.Session;

                var remoteRoot = successfulLoginEvent.Session.GetObjectByPath(this.repoInfo.RemotePath) as IFolder;

                // Remove former added instances from event Queue.EventManager
                if (this.ccaccumulator != null)
                {
                    this.Queue.EventManager.RemoveEventHandler(this.ccaccumulator);
                }

                if (this.contentChanges != null)
                {
                    this.Queue.EventManager.RemoveEventHandler(this.contentChanges);
                }

                if (this.alreadyHandledFilter != null)
                {
                    this.Queue.EventManager.RemoveEventHandler(this.alreadyHandledFilter);
                }

                if (this.selectiveIgnoreFilter != null)
                {
                    this.Queue.EventManager.RemoveEventHandler(this.selectiveIgnoreFilter);
                }

                if (this.transformer != null)
                {
                    this.Queue.EventManager.RemoveEventHandler(this.transformer);
                }

                if (this.ignoreChangeDetector != null)
                {
                    this.Queue.EventManager.RemoveEventHandler(this.ignoreChangeDetector);
                }

                if (session.AreChangeEventsSupported() &&
                    (this.repoInfo.SupportedFeatures == null || this.repoInfo.SupportedFeatures.GetContentChangesSupport != false))
                {
                    Logger.Info("Session supports content changes");

                    // Add Accumulator
                    this.ccaccumulator = new ContentChangeEventAccumulator(session, this.Queue);
                    this.Queue.EventManager.AddEventHandler(this.ccaccumulator);

                    // Add Content Change sync algorithm
                    this.contentChanges = new ContentChanges(session, this.storage, this.Queue);
                    this.Queue.EventManager.AddEventHandler(this.contentChanges);

                    // Add Filter of already handled change events
                    this.alreadyHandledFilter = new IgnoreAlreadyHandledContentChangeEventsFilter(this.storage, session);
                    this.Queue.EventManager.AddEventHandler(this.alreadyHandledFilter);
                }

                if (session.SupportsSelectiveIgnore())
                {
                    // Transforms events of ignored folders
                    this.transformer = new SelectiveIgnoreEventTransformer(this.ignoredStorage, this.Queue);
                    this.Queue.EventManager.AddEventHandler(this.transformer);

                    // Filters events of ignored folders
                    this.selectiveIgnoreFilter = new SelectiveIgnoreFilter(this.ignoredStorage);
                    this.Queue.EventManager.AddEventHandler(this.selectiveIgnoreFilter);

                    // Detection if any ignored object has changed its state
                    this.ignoreChangeDetector = new IgnoreFlagChangeDetection(this.ignoredStorage, new PathMatcher.PathMatcher(this.repoInfo.LocalPath, this.repoInfo.RemotePath), this.Queue);
                    this.Queue.EventManager.AddEventHandler(this.ignoreChangeDetector);
                }

                // Add remote object fetcher
                if (this.remoteFetcher != null)
                {
                    this.Queue.EventManager.RemoveEventHandler(this.remoteFetcher);
                }

                this.remoteFetcher = new RemoteObjectFetcher(session, this.storage);
                this.Queue.EventManager.AddEventHandler(this.remoteFetcher);

                // Add crawler
                if (this.crawler != null)
                {
                    this.Queue.EventManager.RemoveEventHandler(this.crawler);
                }

                this.crawler = new DescendantsCrawler(this.Queue, remoteRoot, this.fileSystemFactory.CreateDirectoryInfo(this.repoInfo.LocalPath), this.storage, this.filter, this.activityListener, this.ignoredStorage);
                this.Queue.EventManager.AddEventHandler(this.crawler);

                // Add remote object moved accumulator
                if (this.romaccumulator != null)
                {
                    this.Queue.EventManager.RemoveEventHandler(this.romaccumulator);
                }

                this.romaccumulator = new RemoteObjectMovedOrRenamedAccumulator(this.Queue, this.storage, this.fileSystemFactory);
                this.Queue.EventManager.AddEventHandler(this.romaccumulator);

                // Add sync mechanism
                if (this.mechanism != null)
                {
                    this.Queue.EventManager.RemoveEventHandler(this.mechanism);
                }

                var localDetection  = new LocalSituationDetection();
                var remoteDetection = new RemoteSituationDetection();

                this.mechanism = new SyncMechanism(localDetection, remoteDetection, this.Queue, session, this.storage, this.fileTransmissionStorage, this.activityListener, this.filter);
                this.Queue.EventManager.AddEventHandler(this.mechanism);

                var  localRootFolder = this.fileSystemFactory.CreateDirectoryInfo(this.repoInfo.LocalPath);
                Guid rootFolderGuid;
                if (!Guid.TryParse(localRootFolder.GetExtendedAttribute(MappedObject.ExtendedAttributeKey), out rootFolderGuid))
                {
                    try {
                        rootFolderGuid = Guid.NewGuid();
                        localRootFolder.SetExtendedAttribute(MappedObject.ExtendedAttributeKey, rootFolderGuid.ToString(), false);
                    } catch (ExtendedAttributeException ex) {
                        Logger.Warn("Problem on setting Guid of the root path", ex);
                        rootFolderGuid = Guid.Empty;
                    }
                }

                var rootFolder = new MappedObject("/", remoteRoot.Id, MappedObjectType.Folder, null, remoteRoot.ChangeToken)
                {
                    LastRemoteWriteTimeUtc = remoteRoot.LastModificationDate,
                    Guid = rootFolderGuid
                };

                Logger.Debug("Saving Root Folder to DataBase");
                this.storage.SaveMappedObject(rootFolder);

                // Sync up everything that changed
                // since we've been offline
                // start full crawl sync on beginning
                this.Queue.AddEvent(new StartNextSyncEvent(true));
                return(true);
            }

            return(false);
        }
Esempio n. 27
0
        private SingleStepEventQueue CreateQueue(Mock<ISession> session, IMetaDataStorage storage, ObservableHandler observer, IFileSystemInfoFactory fsFactory = null) {
            var manager = new SyncEventManager();
            SingleStepEventQueue queue = new SingleStepEventQueue(manager);

            manager.AddEventHandler(observer);

            var connectionScheduler = new ConnectionScheduler(new RepoInfo(), queue, Mock.Of<ISessionFactory>(), Mock.Of<IAuthenticationProvider>());
            manager.AddEventHandler(connectionScheduler);

            var changes = new ContentChanges(session.Object, storage, queue, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);
            manager.AddEventHandler(changes);

            var transformer = new ContentChangeEventTransformer(queue, storage, fsFactory);
            manager.AddEventHandler(transformer);

            var ccaccumulator = new ContentChangeEventAccumulator(session.Object, queue);
            manager.AddEventHandler(ccaccumulator);

            var remoteFetcher = new RemoteObjectFetcher(session.Object, storage);
            manager.AddEventHandler(remoteFetcher);

            var localFetcher = new LocalObjectFetcher(storage.Matcher, fsFactory);
            manager.AddEventHandler(localFetcher);

            var watcher = new Strategy.WatcherConsumer(queue);
            manager.AddEventHandler(watcher);

            var localDetection = new LocalSituationDetection();
            var remoteDetection = new RemoteSituationDetection();
            var transmissionManager = new TransmissionManager();
            var activityAggregator = new ActivityListenerAggregator(Mock.Of<IActivityListener>(), transmissionManager);

            var ignoreFolderFilter = new IgnoredFoldersFilter();
            var ignoreFolderNameFilter = new IgnoredFolderNameFilter();
            var ignoreFileNamesFilter = new IgnoredFileNamesFilter();
            var invalidFolderNameFilter = new InvalidFolderNameFilter();
            var filterAggregator = new FilterAggregator(ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter, ignoreFolderFilter);

            var syncMechanism = new SyncMechanism(localDetection, remoteDetection, queue, session.Object, storage, Mock.Of<IFileTransmissionStorage>(), activityAggregator, filterAggregator);
            manager.AddEventHandler(syncMechanism);

            var remoteFolder = MockSessionUtil.CreateCmisFolder();
            remoteFolder.Setup(r => r.Path).Returns(this.remoteRoot);
            var localFolder = new Mock<IDirectoryInfo>();
            localFolder.Setup(f => f.FullName).Returns(this.localRoot);
            var generator = new CrawlEventGenerator(storage, fsFactory);
            var ignoreStorage = new IgnoredEntitiesStorage(new IgnoredEntitiesCollection(), storage);
            var treeBuilder = new DescendantsTreeBuilder(storage, remoteFolder.Object, localFolder.Object, filterAggregator, ignoreStorage);
            var notifier = new CrawlEventNotifier(queue);
            var crawler = new DescendantsCrawler(queue, treeBuilder, generator, notifier, Mock.Of<IActivityListener>());
            manager.AddEventHandler(crawler);

            var permissionDenied = new GenericHandleDublicatedEventsFilter<PermissionDeniedEvent, ConfigChangedEvent>();
            manager.AddEventHandler(permissionDenied);

            var alreadyAddedFilter = new IgnoreAlreadyHandledFsEventsFilter(storage, fsFactory);
            manager.AddEventHandler(alreadyAddedFilter);

            var ignoreContentChangesFilter = new IgnoreAlreadyHandledContentChangeEventsFilter(storage, session.Object);
            manager.AddEventHandler(ignoreContentChangesFilter);

            var delayRetryAndNextSyncEventHandler = new DelayRetryAndNextSyncEventHandler(queue);
            manager.AddEventHandler(delayRetryAndNextSyncEventHandler);

            /* This is not implemented yet
            var failedOperationsFilder = new FailedOperationsFilter(queue);
            manager.AddEventHandler(failedOperationsFilder);
            */

            var reportingFilter = new ReportingFilter(queue, ignoreFolderFilter, ignoreFileNamesFilter, ignoreFolderNameFilter, invalidFolderNameFilter, new SymlinkFilter());
            manager.AddEventHandler(reportingFilter);

            var debugHandler = new DebugLoggingHandler();
            manager.AddEventHandler(debugHandler);

            var movedOrRenamed = new RemoteObjectMovedOrRenamedAccumulator(queue, storage, fsFactory);
            manager.AddEventHandler(movedOrRenamed);

            return queue;
        }