public void SubscribeEventWithTargetThatDoesntUseMainThreadContextWorks(ThreadTarget threadTarget) { var subscription = new EventAggregatorService(this.subscriptionLogger) .Subscribe <TestEvent>(e => {}, false, EventPriority.Normal, threadTarget); subscription.Should().NotBeNull(); }
public ITask AddTask(TaskFunction function, TaskComplete completion, TaskContext ctx) { //Just cycle to the next free one. lock (_nextThreadTargetLock) _nextThreadTarget = (ThreadTarget)(((int)(_nextThreadTarget) + 1) % _nThreads); return(AddTask(_nextThreadTarget, function, completion, ctx)); }
public void ThreadTargetWillBeSetInSubscription(ThreadTarget threadTarget) { var subscription = this.eventAggregator .Subscribe <TestEvent>(e => { }, false, EventPriority.Normal, threadTarget); subscription.Should().NotBeNull(); subscription.ThreadTarget.Should().Be(threadTarget); }
public void SubscribingToDataChangingEventInWrongThreadTargetThrowsException(ThreadTarget threadTarget) { Action act = () => this.eventAggregator.Subscribe <DataChangingEvent>( _ => { }, false, EventPriority.Normal, threadTarget); act.Should().Throw <InvalidOperationException>().WithMessage($"*{nameof(IDataChangingEvent)}*"); }
public void SubscribingToDataChangingEventInNonPublishThreadThrowsException(ThreadTarget threadTarget) { Action act = () => new Subscription <DataChangingEvent>( this.logger, _ => { }, false, EventPriority.Normal, threadTarget, this.synchronizationContext, () => { }); act.Should().Throw <InvalidOperationException>().WithMessage($"*{nameof(IDataChangingEvent)}*"); }
public void SubscriptionThreadTargetWillBeSet(ThreadTarget threadTarget) { var subscription = new Subscription <TestEvent>( this.logger, e => {}, false, EventPriority.Normal, threadTarget, this.synchronizationContext, () => {}); subscription.ThreadTarget.Should().Be(threadTarget); }
/// <summary> /// Initializes a new instance of the <see cref="Subscription{T}"/> class. /// </summary> /// <param name="logger">Logger that should receive.</param> /// <param name="handler">Callback that should be called upon publish.</param> /// <param name="ignoreCancelled">Ignore event subscription if event was cancelled before.</param> /// <param name="eventPriority">Priority of this subscription.</param> /// <param name="threadTarget">Selected Thread where this subscription should be executed.</param> /// <param name="context">Context that will be needed for <paramref name="threadTarget"/> selections.</param> /// <param name="unsubscribeAction">Action that will be called when this subscription should not be called anymore.</param> /// <exception cref="ArgumentOutOfRangeException"><paramref name="threadTarget"></paramref> is invalid.</exception> public Subscription( ILogger <ISubscription> logger, IEventAggregator.EventHandlerDelegate <T> handler, bool ignoreCancelled, EventPriority eventPriority, ThreadTarget threadTarget, SynchronizationContext?context, Action unsubscribeAction) { if (Enum.IsDefined(typeof(ThreadTarget), (int)threadTarget) == false) { throw new ArgumentOutOfRangeException( nameof(threadTarget), threadTarget, $"{nameof(threadTarget)} is not defined in {typeof(ThreadTarget)}"); } if (Enum.IsDefined(typeof(EventPriority), (int)eventPriority) == false) { throw new ArgumentOutOfRangeException( nameof(eventPriority), eventPriority, $"{nameof(eventPriority)} is not defined in {typeof(EventPriority)}"); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } this.logger = logger; this.handler = handler ?? throw new ArgumentNullException(nameof(handler)); this.context = context; this.unsubscribeAction = unsubscribeAction ?? throw new ArgumentNullException(nameof(unsubscribeAction)); this.IgnoreCancelled = ignoreCancelled; this.Priority = eventPriority; this.ThreadTarget = threadTarget; this.Type = typeof(T); this.ValidateSubscription(); }
public ITask AddTask(ThreadTarget threadTarget, TaskFunction function, TaskComplete completion, TaskContext ctx) { return(_wrappers[(int)threadTarget].AddTask(function, completion, ctx)); }