public static Task <DomainEvent> FirstOfType <TEvent1, TEvent2>( this IEventObservable observable, string sourceId) where TEvent1 : DomainEvent where TEvent2 : DomainEvent { var events1 = observable.Observe <TEvent1>(e => e.SourceId == sourceId).OfType <DomainEvent>(); var events2 = observable.Observe <TEvent2>(e => e.SourceId == sourceId).OfType <DomainEvent>(); return(First(events1.Merge(events2))); }
public void CanHoldUsingModelRouter() { IRouter <TestModel> modelRouter = new Router <TestModel>(_model.Id, _router); IEventObservable <BaseEvent, IEventContext, TestModel> baseEventStream = modelRouter.GetEventObservable(new HoldBaseEventsBasedOnModelStrategy <FooEvent, BaseEvent>()); int receivedBaseEvents = 0, reveivedBarEvents = 0; baseEventStream.Observe((model, baseEvent, context) => { receivedBaseEvents++; }); IEventObservable <BarEvent, IEventContext, TestModel> fooEventStream = modelRouter.GetEventObservable(new HoldEventsBasedOnModelStrategy <BarEvent>()); fooEventStream.Observe((model, barEvent, context) => { reveivedBarEvents++; }); var event1 = new FooEvent("EventPayload1"); var event2 = new BarEvent("EventPayload2"); _router.PublishEvent(_model.Id, event1); _router.PublishEvent(_model.Id, event2); receivedBaseEvents.ShouldBe(0); reveivedBarEvents.ShouldBe(0); ReleasedEvent(event1.Id, HeldEventAction.Release); ReleasedEvent(event2.Id, HeldEventAction.Release); receivedBaseEvents.ShouldBe(1); reveivedBarEvents.ShouldBe(1); }
public static IEventObservable <TEvent, TContext, TModel> Take <TEvent, TContext, TModel>(this IEventObservable <TEvent, TContext, TModel> source, int number) { return(Create <TEvent, TContext, TModel>( o => { int count = 0; IDisposable disposable = null; disposable = source.Observe( (e, c, m) => { count++; if (count <= number) { o.OnNext(e, c, m); } else { disposable.Dispose(); } }, o.OnCompleted ); return disposable; } )); }
public static IEventObservable <TEvent, TContext, TSubModel> Select <TEvent, TContext, TModel, TSubModel>(this IEventObservable <TEvent, TContext, TModel> source, Func <TModel, TSubModel> subModelSelector) { return(Create <TEvent, TContext, TSubModel>( o => { return source.Observe( (e, c, m) => o.OnNext(e, c, subModelSelector(m)), o.OnCompleted ); } )); }
public static IEventObservable <TOtherEvent, TContext, TModel> Cast <TEvent, TContext, TModel, TOtherEvent>( this IEventObservable <TEvent, TContext, TModel> source) where TOtherEvent : TEvent { return(Create <TOtherEvent, TContext, TModel>( o => { return source.Observe( (e, c, m) => { o.OnNext((TOtherEvent)e, c, m); }, o.OnCompleted ); } )); }
public static IEventObservable <TEvent, TContext, TModel> Where <TEvent, TContext, TModel>(this IEventObservable <TEvent, TContext, TModel> source, Func <TEvent, TContext, TModel, bool> predicate) { return(Create <TEvent, TContext, TModel>( o => { var disposable = source.Observe( (e, c, m) => { if (predicate(e, c, m)) { o.OnNext(e, c, m); } }, o.OnCompleted ); return disposable; } )); }
public static Task <TEvent1> FirstOfType <TEvent1>( this IEventObservable observable, string sourceId) where TEvent1 : DomainEvent => First(observable.Observe <TEvent1>(e => e.SourceId == sourceId));