Ejemplo n.º 1
0
 private void SetupMocks()
 {
     this.queue   = new Mock <ISyncEventQueue>();
     this.ignores = new Mock <IIgnoredEntitiesStorage>();
     this.ignores.Setup(i => i.IsIgnoredPath(It.Is <string>(s => !s.Contains(this.ignoredLocalPath)))).Returns(IgnoredState.NOT_IGNORED);
     this.ignores.Setup(i => i.IsIgnoredPath(this.ignoredLocalPath)).Returns(IgnoredState.IGNORED);
     this.ignores.Setup(i => i.IsIgnoredPath(It.Is <string>(s => s.StartsWith(this.ignoredLocalPath) && s != this.ignoredLocalPath))).Returns(IgnoredState.INHERITED);
     this.ignores.Setup(i => i.IsIgnoredId(this.ignoredFolderId)).Returns(IgnoredState.IGNORED);
     this.underTest = new SelectiveIgnoreEventTransformer(this.ignores.Object, this.queue.Object);
 }
Ejemplo n.º 2
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);
        }