public void AddMessageHandler <T>(IHandler <T> handler) where T : Message { List <Func <Message, bool> > handlers; if (!_handlers.TryGetValue(typeof(T), out handlers)) { handlers = new List <Func <Message, bool> >(); _handlers.Add(typeof(T), handlers); } var guaranteedDelivery = new GuaranteedOnceDelivery <T>(handler); if (guaranteedDelivery.Enabled) { if (_messageLock == null) { throw new Exception("IMessageLock is null. You need to specify an implementation for IMessageLock."); } handler = new ExactlyOnceHandler <T>(handler, _messageLock, guaranteedDelivery.TimeOut); } var executionTimeMonitoring = _messagingMonitor as IMeasureHandlerExecutionTime; if (executionTimeMonitoring != null) { handler = new StopwatchHandler <T>(handler, executionTimeMonitoring); } handlers.Add(DelegateAdjuster.CastArgument <Message, T>(x => handler.Handle(x))); }
public void RegisterHandler <T>(Action <T> handler) where T : Message { List <Action <Message> > handlers; if (!_routes.TryGetValue(typeof(T), out handlers)) { handlers = new List <Action <Message> >(); _routes.Add(typeof(T), handlers); } handlers.Add(DelegateAdjuster.CastArgument <Message, T>(x => handler(x))); }
/// <summary> /// Register an event handler that will listen and respond to all events. /// </summary> public void RegisterGlobalEventHandler <TMessage>(Action <TMessage> handler, bool holdMessageLock = true) where TMessage : IMessage { GlobalEventRoute.Handlers.Add ( new RouteHandlerDelegate { Delegate = DelegateAdjuster.CastArgument <IMessage, TMessage>(x => handler(x)), TargetedType = null } ); }
void IBus.RegisterHandler <T>(Action <T> handler) { List <Action <DomainEvent> > handlers; if (!_Routes.TryGetValue(typeof(T), out handlers)) { handlers = new List <Action <DomainEvent> >(); _Routes.Add(typeof(T), handlers); } handlers.Add(DelegateAdjuster.CastArgument <DomainEvent, T>(x => handler(x))); }
public IProjection <TState> When <TEvent>(Expression <Func <TEvent, TState, TState> > handler, Expression <Func <TEvent, Guid> > id) where TEvent : IEvent { var idhandler = DelegateAdjuster.CastArgument(id); var handlerFunc = DelegateAdjuster.CastArgument(handler); source.Where(x => x.GetType() == typeof(TEvent)) .Subscribe(e => this.writer.AddOrUpdate(idhandler(e), init, state => handlerFunc(e, state)) ); return(this); }
public void RegisterHandler <TEvent>(Action <TEvent> handler) where TEvent : IEvent { List <Action <IEvent> > handlers; if (!m_routes.TryGetValue(typeof(TEvent), out handlers)) { handlers = new List <Action <IEvent> >(); m_routes.Add(typeof(TEvent), handlers); } handlers.Add(DelegateAdjuster.CastArgument <IEvent, TEvent>(x => handler(x))); }
public void UnadjustedHandlerShouldHandleMessage() { bool isProcessed = false; Action <SimpleAggregateUpdated> handler = (t) => { isProcessed = true; }; Action <SimpleAggregateUpdated> adjustedHandler = DelegateAdjuster.CastArgument <SimpleAggregateUpdated, SimpleAggregateUpdated>(x => handler(x)); Action act = () => adjustedHandler(new SimpleAggregateUpdated(Guid.NewGuid(), 0, DateTime.Now)); act(); isProcessed.Should().BeTrue(); }
public void FillFromHistory(IEnumerable<Event> events) { foreach (var e in events) { ApplyEvent(e); dynamic adjustedE = new DelegateAdjuster().ChangeType(e, e.GetType().FullName); Console.WriteLine(adjustedE.GetType()); Console.WriteLine(e.GetType()); dynamic t = new DelegateAdjuster().ChangeType(this, GetType().FullName); EventReplayer.Replay(t, adjustedE); } }
private void RegisterHandler <T>(Action <T> handler, SubscriptionDisposer subscriptionDisposer) where T : IMessage { Dictionary <Guid, Action <IMessage> > handlers; if (!this.routes.TryGetValue(typeof(T), out handlers)) { handlers = new Dictionary <Guid, Action <IMessage> >(); this.routes.Add(typeof(T), handlers); } Guid handlerID = Guid.NewGuid(); Action <IMessage> adjustedHandler = DelegateAdjuster.CastArgument <IMessage, T>(x => handler(x)); handlers.Add(handlerID, adjustedHandler); subscriptionDisposer.AddHandler(typeof(T), handlerID); }
public void replayertest2() { bool called = false; var replay = new Action<Cart, ItemAddedToCart>((es, ev) => { Console.WriteLine("Called"); es.Add(new CartItem()); called = true; }); EventReplayer.ClearRegistry(); EventReplayer.Register(replay); object instance = Activator.CreateInstance(typeof(ItemAddedToCart)); dynamic e = new DelegateAdjuster().ChangeType(instance, typeof(ItemAddedToCart).FullName); EventReplayer.Replay(new Cart(), e); Assert.IsTrue(called); }
/// <summary> /// Register an event or command handler that will listen and respond to events or commands. /// </summary> public virtual void RegisterHandler <TMessage>(Action <TMessage> handler, Type targetedType, bool holdMessageLock = true) where TMessage : IMessage { Route route; if (!Routes.TryGetValue(typeof(TMessage), out route)) { route = new Route { Handlers = new List <RouteHandlerDelegate>() }; Routes.Add(typeof(TMessage), route); } route.Handlers.Add ( new RouteHandlerDelegate { Delegate = DelegateAdjuster.CastArgument <IMessage, TMessage>(x => handler(x)), TargetedType = targetedType } ); }