Ejemplo n.º 1
0
        /// <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 void ScheduleCommand <TCommand>(TCommand command,
                                                  DateTimeOffset?due = null)
            where TCommand : class, ICommand <T>
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            var scheduled = CommandScheduler.CreateScheduledCommand <TCommand, T>(
                Id,
                command,
                due) as CommandScheduled <T>;

            RecordEvent(scheduled);
        }
Ejemplo n.º 2
0
        // TODO: (CommandSchedulerExtensions) combine with CommandScheduler class
        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>
            where TAggregate : IEventSourced
        {
            if (aggregateId == Guid.Empty)
            {
                throw new ArgumentException("Parameter aggregateId cannot be an empty Guid.");
            }

            var scheduledCommand = CommandScheduler.CreateScheduledCommand <TCommand, TAggregate>(
                aggregateId,
                command,
                dueTime,
                deliveryDependsOn);

            await scheduler.Schedule(scheduledCommand);

            return(scheduledCommand);
        }