Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }