/// <summary> /// Schedules a command for asynchronous and, optionally, deferred delivery. /// </summary> /// <typeparam name="TCommand">The type of the command.</typeparam> /// <param name="command">The command.</param> /// <param name="due">The time when the command should be delivered. If this is null, the scheduler will deliver it as soon as possible.</param> /// <exception cref="System.ArgumentNullException">command</exception> protected async Task ScheduleCommandAsync <TCommand>(TCommand command, DateTimeOffset?due = null) where TCommand : class, ICommand <T> { if (command == null) { throw new ArgumentNullException(nameof(command)); } var commandScheduledEvent = new CommandScheduled <T> { AggregateId = Id, Command = command, DueTime = due }; var scheduledCommand = new ScheduledCommand <T>( command, Id, due, new EventHasBeenRecordedPrecondition(commandScheduledEvent.ETag, Id)); await Configuration.Current .CommandScheduler <T>() .Schedule(scheduledCommand); RecordEvent(commandScheduledEvent); }
/// <summary> /// Schedules a command on the specified scheduler. /// </summary> public static async Task <IScheduledCommand <TTarget> > Schedule <TCommand, TTarget>( this ICommandScheduler <TTarget> scheduler, string targetId, TCommand command, DateTimeOffset?dueTime = null, IPrecondition deliveryDependsOn = null) where TCommand : ICommand <TTarget> { var scheduledCommand = new ScheduledCommand <TTarget>( command, targetId, dueTime, deliveryDependsOn); await scheduler.Schedule(scheduledCommand); return(scheduledCommand); }
/// <summary> /// Schedules a command on the specified scheduler. /// </summary> public static async Task <IScheduledCommand <TAggregate> > Schedule <TCommand, TAggregate>( this ICommandScheduler <TAggregate> scheduler, Guid aggregateId, TCommand command, DateTimeOffset?dueTime = null, IEvent deliveryDependsOn = null) where TCommand : ICommand <TAggregate> { var scheduledCommand = new ScheduledCommand <TAggregate>( command, aggregateId, dueTime, deliveryDependsOn.ToPrecondition()); await scheduler.Schedule(scheduledCommand); return(scheduledCommand); }