public PreconditionNotMetException(ScheduledCommandPrecondition precondition)
     : base("Precondition was not met: " + precondition)
 {
     if (precondition == null)
     {
         throw new ArgumentNullException("precondition");
     }
     Precondition = precondition;
 }
 public PreconditionNotMetException(ScheduledCommandPrecondition precondition)
     : base("Precondition was not met: " + precondition)
 {
     if (precondition == null)
     {
         throw new ArgumentNullException("precondition");
     }
     Precondition = precondition;
 }
Ejemplo n.º 3
0
        internal static IScheduledCommand <TAggregate> CreateScheduledCommand <TCommand, TAggregate>(
            Guid aggregateId,
            TCommand command,
            DateTimeOffset?dueTime,
            IEvent deliveryDependsOn = null)
            where TCommand : ICommand <TAggregate> where TAggregate : IEventSourced
        {
            ScheduledCommandPrecondition precondition = null;

            if (deliveryDependsOn != null)
            {
                if (deliveryDependsOn.AggregateId == Guid.Empty)
                {
                    throw new ArgumentException("An AggregateId must be set on the event on which the scheduled command depends.");
                }

                if (String.IsNullOrWhiteSpace(deliveryDependsOn.ETag))
                {
                    deliveryDependsOn.IfTypeIs <Event>()
                    .ThenDo(e => e.ETag = Guid.NewGuid().ToString("N"))
                    .ElseDo(() => { throw new ArgumentException("An ETag must be set on the event on which the scheduled command depends."); });
                }

                precondition = new ScheduledCommandPrecondition
                {
                    AggregateId = deliveryDependsOn.AggregateId,
                    ETag        = deliveryDependsOn.ETag
                };
            }

            if (String.IsNullOrEmpty(command.ETag))
            {
                command.IfTypeIs <Command>()
                .ThenDo(c => c.ETag = CommandContext.Current
                                      .IfNotNull()
                                      .Then(ctx => ctx.NextETag(aggregateId.ToString("N")))
                                      .Else(() => Guid.NewGuid().ToString("N")));
            }

            var scheduledCommand = new CommandScheduled <TAggregate>
            {
                Command              = command,
                DueTime              = dueTime,
                AggregateId          = aggregateId,
                SequenceNumber       = -DateTimeOffset.UtcNow.Ticks,
                DeliveryPrecondition = precondition
            };

            return(scheduledCommand);
        }
Ejemplo n.º 4
0
        public static Task 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.");
            }

            ScheduledCommandPrecondition precondition = null;

            if (deliveryDependsOn != null)
            {
                if (deliveryDependsOn.AggregateId == Guid.Empty)
                {
                    throw new ArgumentException("An AggregateId must be set on the event on which the scheduled command depends.");
                }

                if (string.IsNullOrWhiteSpace(deliveryDependsOn.ETag))
                {
                    deliveryDependsOn.IfTypeIs <Event>()
                    .ThenDo(e => e.ETag = Guid.NewGuid().ToString("N"))
                    .ElseDo(() => { throw new ArgumentException("An ETag must be set on the event on which the scheduled command depends."); });
                }

                precondition = new ScheduledCommandPrecondition
                {
                    AggregateId = deliveryDependsOn.AggregateId,
                    ETag        = deliveryDependsOn.ETag
                };
            }

            return(scheduler.Schedule(new CommandScheduled <TAggregate>
            {
                Command = command,
                DueTime = dueTime,
                AggregateId = aggregateId,
                SequenceNumber = -DateTimeOffset.UtcNow.Ticks,
                DeliveryPrecondition = precondition
            }));
        }