private void RunSuccessfulLoginEvent(IMetaDataStorage storage, ISyncEventManager manager, ActivityListenerAggregator listener, bool changeEventSupported = false, string id = "i", string token = "t")
        {
            var e = CreateNewSessionEvent(changeEventSupported, id, token);

            var handler = this.CreateStrategyInitializer(storage, manager, listener);

            Assert.True(handler.Handle(e));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Queueing.SyncEventQueue"/> class.
        /// </summary>
        /// <param name="manager">Manager holding the handler.</param>
        public SyncEventQueue(ISyncEventManager manager)
        {
            if (manager == null)
            {
                throw new ArgumentException("manager may not be null");
            }

            this.EventManager = manager;
            this.consumer     = new Task(() => this.Listen(this.queue, this.EventManager, this.suspendHandle));
            this.consumer.Start();
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CmisSync.Lib.Queueing.SyncEventQueue"/> class.
        /// </summary>
        /// <param name="manager">Manager holding the handler.</param>
        public SyncEventQueue(ISyncEventManager manager) {
            if (manager == null) {
                throw new ArgumentException("manager may not be null");
            }

            this.fullCounter = new QueuedEventsCounter();
            this.categoryCounter = new QueuedCategorizedEventsCounter();
            this.EventManager = manager;
            this.consumer = new Task(() => this.Listen(this.queue, this.EventManager, this.suspendHandle));
            this.consumer.Start();
        }
Esempio n. 4
0
        private void Listen(BlockingCollection <ISyncEvent> queue, ISyncEventManager manager, WaitHandle waitHandle)
        {
            Logger.Debug("Starting to listen on SyncEventQueue");
            while (!queue.IsCompleted)
            {
                ISyncEvent syncEvent = null;

                // Blocks if number.Count == 0
                // IOE means that Take() was called on a completed collection.
                // Some other thread can call CompleteAdding after we pass the
                // IsCompleted check but before we call Take.
                // In this example, we can simply catch the exception since the
                // loop will break on the next iteration.
                try {
                    syncEvent = queue.Take();
                } catch (InvalidOperationException) {
                }

                if (syncEvent != null)
                {
                    try {
                        if (this.suspend)
                        {
                            Logger.Debug("Suspending sync");
                            waitHandle.WaitOne();
                            Logger.Debug("Continue sync");
                        }

                        manager.Handle(syncEvent);
                    } catch (CmisConnectionException connectionException) {
                        this.AddEvent(new CmisConnectionExceptionEvent(connectionException));
                    } catch (Exception e) {
                        Logger.Error(string.Format("Exception in EventHandler on Event {0}: ", syncEvent.ToString()), e);
                    }

                    if (syncEvent is ICountableEvent)
                    {
                        var category = (syncEvent as ICountableEvent).Category;
                        if (category != EventCategory.NoCategory)
                        {
                            lock (this.subscriberLock) {
                                this.fullCounter.Decrease(syncEvent as ICountableEvent);
                                this.categoryCounter.Decrease(syncEvent as ICountableEvent);
                            }
                        }
                    }
                }
            }

            Logger.Debug("Stopping to listen on SyncEventQueue");
        }
 public SingleStepEventQueue(
     ISyncEventManager manager,
     IEventCounter fullCounter     = null,
     IEventCounter categoryCounter = null)
 {
     this.Manager                = manager;
     this.fullCounter            = fullCounter ?? new QueuedEventsCounter();
     this.categoryCounter        = categoryCounter ?? new QueuedCategorizedEventsCounter();
     this.dropAllFsEventsHandler = new GenericSyncEventHandler <IFSEvent>(
         int.MaxValue,
         delegate(ISyncEvent e) {
         return(true);
     });
 }
 public SingleStepEventQueue(
     ISyncEventManager manager,
     IEventCounter fullCounter = null,
     IEventCounter categoryCounter = null)
 {
     this.Manager = manager;
     this.fullCounter = fullCounter ?? new QueuedEventsCounter();
     this.categoryCounter = categoryCounter ?? new QueuedCategorizedEventsCounter();
     this.dropAllFsEventsHandler = new GenericSyncEventHandler<IFSEvent>(
         int.MaxValue,
         delegate(ISyncEvent e) {
         return true;
     });
 }
 public SingleStepEventQueue(ISyncEventManager manager)
 {
     this.Manager = manager;
 }
 private EventManagerInitializer CreateStrategyInitializer(IMetaDataStorage storage, ISyncEventManager manager, ActivityListenerAggregator listener)
 {
     this.queue.Setup(s => s.EventManager).Returns(manager);
     return(new EventManagerInitializer(this.queue.Object, storage, CreateRepoInfo(), MockOfIFilterAggregatorUtil.CreateFilterAggregator().Object, listener));
 }
Esempio n. 9
0
        private void Listen(BlockingCollection<ISyncEvent> queue, ISyncEventManager manager, WaitHandle waitHandle) {
            Logger.Debug("Starting to listen on SyncEventQueue");
            while (!queue.IsCompleted) {
                ISyncEvent syncEvent = null;

                // Blocks if number.Count == 0
                // IOE means that Take() was called on a completed collection.
                // Some other thread can call CompleteAdding after we pass the
                // IsCompleted check but before we call Take.
                // In this example, we can simply catch the exception since the
                // loop will break on the next iteration.
                try {
                    syncEvent = queue.Take();
                } catch (InvalidOperationException) {
                }

                if (syncEvent != null) {
                    try {
                        if (this.suspend) {
                            Logger.Debug("Suspending sync");
                            waitHandle.WaitOne();
                            Logger.Debug("Continue sync");
                        }

                        manager.Handle(syncEvent);
                    } catch (CmisConnectionException connectionException) {
                        this.AddEvent(new CmisConnectionExceptionEvent(connectionException));
                    } catch(Exception e) {
                        Logger.Error(string.Format("Exception in EventHandler on Event {0}: ", syncEvent.ToString()), e);
                    }

                    if (syncEvent is ICountableEvent) {
                        var category = (syncEvent as ICountableEvent).Category;
                        if (category != EventCategory.NoCategory) {
                            lock (this.subscriberLock) {
                                this.fullCounter.Decrease(syncEvent as ICountableEvent);
                                this.categoryCounter.Decrease(syncEvent as ICountableEvent);
                            }
                        }
                    }
                }
            }

            Logger.Debug("Stopping to listen on SyncEventQueue");
        }
        private void RunSuccessfulLoginEvent(IMetaDataStorage storage, ISyncEventManager manager, ActivityListenerAggregator listener, bool changeEventSupported = false, bool supportsSelectiveIgnore = true, string id = "i", string token = "t") {
            var e = CreateNewSessionEvent(changeEventSupported, supportsSelectiveIgnore, id, token);

            var handler = this.CreateStrategyInitializer(storage, manager, listener);

            Assert.True(handler.Handle(e));
        }
 private EventManagerInitializer CreateStrategyInitializer(IMetaDataStorage storage, ISyncEventManager manager, ActivityListenerAggregator listener) {
     this.queue.Setup(s => s.EventManager).Returns(manager);
     return new EventManagerInitializer(this.queue.Object, storage, Mock.Of<IFileTransmissionStorage>(), Mock.Of<IIgnoredEntitiesStorage>(), CreateRepoInfo(), MockOfIFilterAggregatorUtil.CreateFilterAggregator().Object, listener);
 }