This event should be used by scheduler to periodically start sync processes. If any inconsitancy is detected, it could also be used by the algorithm itself to force a full sync on the next sync execution.
Inheritance: IRemoveFromLoggingEvent, ICountableEvent
コード例 #1
0
        public void IgnoreDuplicatedContentChangesEventTestDeleted() {
            var queue = new Mock<ISyncEventQueue>();

            Mock<IMetaDataStorage> storage = MockMetaDataStorageUtil.GetMetaStorageMockWithToken();

            Mock<ISession> session = MockSessionUtil.GetSessionMockReturning3Changesin2Batches(DotCMIS.Enums.ChangeType.Deleted, true);

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

            Assert.IsTrue(changes.Handle(startSyncEvent));
            queue.Verify(foo => foo.AddEvent(It.IsAny<ContentChangeEvent>()), Times.Exactly(3));
        }
コード例 #2
0
 public void ExtendCrawlSyncEvent() {
     var start = new StartNextSyncEvent(true);
     var repositoryService = new Mock<IRepositoryService>();
     repositoryService.Setup(r => r.GetRepositoryInfos(null)).Returns((IList<IRepositoryInfo>)null);
     repositoryService.Setup(r => r.GetRepositoryInfo(It.IsAny<string>(), It.IsAny<IExtensionsData>()).LatestChangeLogToken).Returns(this.latestChangeLogToken);
     var session = new Mock<ISession>();
     session.Setup(s => s.Binding.GetRepositoryService()).Returns(repositoryService.Object);
     session.Setup(s => s.RepositoryInfo.Id).Returns(this.repoId);
     var manager = new Mock<ISyncEventManager>().Object;
     var storage = new Mock<IMetaDataStorage>();
     storage.Setup(db => db.ChangeLogToken).Returns((string)null);
     var queue = new Mock<ISyncEventQueue>();
     var changes = new ContentChanges(session.Object, storage.Object, queue.Object);
     Assert.IsFalse(changes.Handle(start));
     Assert.AreEqual(this.latestChangeLogToken, start.LastTokenOnServer);
 }
コード例 #3
0
        public void GivesCorrectContentChangeEvent() {
            ContentChangeEvent contentChangeEvent = null;
            var queue = new Mock<ISyncEventQueue>();
            queue.Setup(q => q.AddEvent(It.IsAny<ContentChangeEvent>())).Callback((ISyncEvent f) => {
                contentChangeEvent = f as ContentChangeEvent;
            });
            string id = "myId";

            Mock<IMetaDataStorage> storage = MockMetaDataStorageUtil.GetMetaStorageMockWithToken();
            var session = MockSessionUtil.PrepareSessionMockForSingleChange(DotCMIS.Enums.ChangeType.Created, id);
            var changes = new ContentChanges(session.Object, storage.Object, queue.Object, this.maxNumberOfContentChanges, this.isPropertyChangesSupported);

            var startSyncEvent = new StartNextSyncEvent(false);
            Assert.IsTrue(changes.Handle(startSyncEvent));

            queue.Verify(foo => foo.AddEvent(It.IsAny<ContentChangeEvent>()), Times.Once());
            Assert.That(contentChangeEvent.Type, Is.EqualTo(DotCMIS.Enums.ChangeType.Created));
            Assert.That(contentChangeEvent.ObjectId, Is.EqualTo(id));
        }
コード例 #4
0
 public void HandleStartSyncEventOnNoRemoteChange() {
     var startSyncEvent = new StartNextSyncEvent(false);
     var session = new Mock<ISession>();
     session.SetupSessionDefaultValues();
     session.Setup(s => s.Binding.GetRepositoryService().GetRepositoryInfo(this.repoId, null).LatestChangeLogToken).Returns(this.changeLogToken);
     var storage = new Mock<IMetaDataStorage>();
     storage.Setup(db => db.ChangeLogToken).Returns(this.changeLogToken);
     var queue = new Mock<ISyncEventQueue>();
     var changes = new ContentChanges(session.Object, storage.Object, queue.Object);
     Assert.IsTrue(changes.Handle(startSyncEvent));
 }
コード例 #5
0
        public void ExecuteCrawlSyncOnNoLocalTokenAvailable() {
            var startSyncEvent = new StartNextSyncEvent(false);
            var session = new Mock<ISession>();
            session.SetupSessionDefaultValues();
            session.Setup(s => s.Binding.GetRepositoryService().GetRepositoryInfo(this.repoId, null).LatestChangeLogToken).Returns(this.changeLogToken);
            var storage = new Mock<IMetaDataStorage>();
            storage.Setup(db => db.ChangeLogToken).Returns((string)null);
            var queue = new Mock<ISyncEventQueue>();
            var changes = new ContentChanges(session.Object, storage.Object, queue.Object);

            Assert.IsTrue(changes.Handle(startSyncEvent));
            queue.Verify(q => q.AddEvent(It.Is<StartNextSyncEvent>(e => e.FullSyncRequested == true)), Times.Once());
        }
コード例 #6
0
 private void DelayNextSyncEvent(StartNextSyncEvent startNextSyncEvent) {
     this.syncHasBeenDelayed = true;
     if (!this.lastDelayedSyncWasFullSync && startNextSyncEvent.FullSyncRequested == true) {
         this.lastDelayedSyncWasFullSync = true;
     }
 }
コード例 #7
0
 public void HandleFullSyncCompletedEvent() {
     var startSyncEvent = new StartNextSyncEvent(false);
     startSyncEvent.LastTokenOnServer = this.changeLogToken;
     var completedEvent = new FullSyncCompletedEvent(startSyncEvent);
     var storage = new Mock<IMetaDataStorage>();
     storage.SetupProperty(db => db.ChangeLogToken);
     var queue = new Mock<ISyncEventQueue>();
     var session = new Mock<ISession>();
     var changes = new ContentChanges(session.Object, storage.Object, queue.Object);
     Assert.IsFalse(changes.Handle(completedEvent));
     storage.VerifySet(db => db.ChangeLogToken = this.changeLogToken);
     Assert.AreEqual(this.changeLogToken, storage.Object.ChangeLogToken);
 }
コード例 #8
0
 public void ConstructorWithTrueParamSetsFullSyncRequestedFlagToTrue() {
     var start = new StartNextSyncEvent(true);
     Assert.IsTrue(start.FullSyncRequested);
 }
コード例 #9
0
        private void Sync() {
            // Get last change log token on server side.
            this.session.Binding.GetRepositoryService().GetRepositoryInfos(null);    // refresh
            string lastTokenOnServer = this.session.Binding.GetRepositoryService().GetRepositoryInfo(this.session.RepositoryInfo.Id, null).LatestChangeLogToken;

            // Get last change token that had been saved on client side.
            string lastTokenOnClient = this.storage.ChangeLogToken;

            if (lastTokenOnClient == null) {
                // Token is null, which means no content change sync has ever happened yet, so just sync everything from remote.
                // Force full sync
                var fullsyncevent = new StartNextSyncEvent(true);
                Queue.AddEvent(fullsyncevent);
                return;
            }

            do {
                // Check which files/folders have changed.
                IChangeEvents changes = this.session.GetContentChanges(lastTokenOnClient, this.isPropertyChangesSupported, this.maxNumberOfContentChanges);

                // Replicate each change to the local side.
                bool first = true;
                foreach (IChangeEvent change in changes.ChangeEventList) {
                    // ignore first event when lists overlapp
                    if (first) {
                        first = false;
                        if (this.lastChange != null &&
                           (this.lastChange.ChangeType == DotCMIS.Enums.ChangeType.Created
                         || this.lastChange.ChangeType == DotCMIS.Enums.ChangeType.Deleted)) {
                            if (change != null && change.ChangeType == this.lastChange.ChangeType && change.ObjectId == this.lastChange.ObjectId) {
                                continue;
                            }
                        }
                    }

                    this.lastChange = change;

                    Queue.AddEvent(new ContentChangeEvent(change.ChangeType, change.ObjectId));
                }

                // Save change log token locally.
                if (changes.HasMoreItems == true) {
                    lastTokenOnClient = changes.LatestChangeLogToken;
                } else {
                    lastTokenOnClient = lastTokenOnServer;
                }

                this.storage.ChangeLogToken = lastTokenOnClient;

                // refresh
                this.session.Binding.GetRepositoryService().GetRepositoryInfos(null);
                lastTokenOnServer = this.session.Binding.GetRepositoryService().GetRepositoryInfo(this.session.RepositoryInfo.Id, null).LatestChangeLogToken;
            } while (!lastTokenOnServer.Equals(lastTokenOnClient));
        }
コード例 #10
0
 public void ConstructorWithFalseParamSetsFullSyncRequestedFlagToFalse() {
     var start = new StartNextSyncEvent(false);
     Assert.IsFalse(start.FullSyncRequested);
 }
コード例 #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CmisSync.Lib.Events.FullSyncCompletedEvent"/> class.
 /// </summary>
 /// <param name="startEvent">Start event, which is completed.</param>
 public FullSyncCompletedEvent(StartNextSyncEvent startEvent) : base(startEvent)
 {
 }
コード例 #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CmisSync.Lib.Events.FullSyncCompletedEvent"/> class.
 /// </summary>
 /// <param name="startEvent">Start event, which is completed.</param>
 public FullSyncCompletedEvent(StartNextSyncEvent startEvent) : base(startEvent)
 {
 }
コード例 #13
0
 public void RunStartSyncEvent() {
     var startSyncEvent = new StartNextSyncEvent(false);
     this.AddEvent(startSyncEvent);
     this.Run();
 }
コード例 #14
0
 public void HandlesStartNextSyncEventAndReportsOnQueueIfDone() {
     var crawler = this.CreateCrawler();
     var startEvent = new StartNextSyncEvent();
     Assert.That(crawler.Handle(startEvent), Is.True);
     this.queue.Verify(q => q.AddEvent(It.Is<FullSyncCompletedEvent>(e => e.StartEvent.Equals(startEvent))), Times.Once());
     this.VerifyThatListenerHasBeenUsed();
 }