public void Send <TCommand>(TCommand command) where TCommand : ICommand <TAuthenticationToken> { RouteHandlerDelegate commandHandler; if (!PrepareAndValidateCommand(command, out commandHandler)) { return; } Type senderType = commandHandler.TargetedType == null ? typeof(IConcurrentAkkaCommandSender <>).MakeGenericType(typeof(TAuthenticationToken)) : typeof(IConcurrentAkkaCommandSender <,>).MakeGenericType(typeof(TAuthenticationToken), commandHandler.TargetedType); var proxy = (IActorRef)ConcurrentEventBusProxy.Resolve(senderType, command.Id); proxy.Tell(command); CommandSender.Send(command); }
/// <summary> /// Sends the provided <paramref name="command"></paramref> and waits for an event of <typeparamref name="TEvent"/> or exits if the specified timeout is expired. /// </summary> /// <param name="command">The <typeparamref name="TCommand"/> to send.</param> /// <param name="condition">A delegate to be executed over and over until it returns the <typeparamref name="TEvent"/> that is desired, return null to keep trying.</param> /// <param name="millisecondsTimeout">The number of milliseconds to wait, or <see cref="F:System.Threading.Timeout.Infinite"/> (-1) to wait indefinitely.</param> /// <param name="eventReceiver">If provided, is the <see cref="IEventReceiver{TAuthenticationToken}" /> that the event is expected to be returned on.</param> public TEvent SendAndWait <TCommand, TEvent>(TCommand command, Func <IEnumerable <IEvent <TAuthenticationToken> >, TEvent> condition, int millisecondsTimeout, IEventReceiver <TAuthenticationToken> eventReceiver = null) where TCommand : ICommand <TAuthenticationToken> { if (eventReceiver != null) { throw new NotSupportedException("Specifying a different event receiver is not yet supported."); } RouteHandlerDelegate commandHandler; if (!PrepareAndValidateCommand(command, out commandHandler)) { return((TEvent)(object)null); } TEvent result = (TEvent)(object)null; EventWaits.Add(command.CorrelationId, new List <IEvent <TAuthenticationToken> >()); Type senderType = commandHandler.TargetedType == null ? typeof(IConcurrentAkkaCommandSender <>).MakeGenericType(typeof(TAuthenticationToken)) : typeof(IConcurrentAkkaCommandSender <,>).MakeGenericType(typeof(TAuthenticationToken), commandHandler.TargetedType); var proxy = (IActorRef)ConcurrentEventBusProxy.Resolve(senderType, command.Id); proxy.Tell(command); CommandSender.Send(command); SpinWait.SpinUntil(() => { IList <IEvent <TAuthenticationToken> > events = EventWaits[command.CorrelationId]; result = condition(events); return(result != null); }, millisecondsTimeout); return(result); }