Beispiel #1
0
        public void Handle(OrderPlaced message)
        {
            if (this.State == ProcessStateType.NotStarted)
            {
                this.ProcessInfo.ConferenceId = message.ConferenceId;
                this.ProcessInfo.OrderId      = message.SourceId;
                // Use the order id as an opaque reservation id for the seat reservation.
                // It could be anything else, as long as it is deterministic from the OrderPlaced event.
                this.ProcessInfo.ReservationId             = message.SourceId;
                this.ProcessInfo.ReservationAutoExpiration = message.ReservationAutoExpiration;
                var expirationWindow = message.ReservationAutoExpiration.Subtract(DateTime.UtcNow);

                if (expirationWindow > TimeSpan.Zero)
                {
                    this.State = ProcessStateType.AwaitingReservationConfirmation;
                    var seatReservationCommand =
                        new MakeSeatReservation
                    {
                        ConferenceId  = this.ProcessInfo.ConferenceId,
                        ReservationId = this.ProcessInfo.ReservationId,
                        Seats         = message.Seats.ToList()
                    };
                    this.ProcessInfo.SeatReservationCommandId = seatReservationCommand.Id;

                    this.AddCommand(new Envelope <ICommand>(seatReservationCommand)
                    {
                        TimeToLive = expirationWindow.Add(TimeSpan.FromMinutes(1)),
                    });

                    var expirationCommand = new ExpireRegistrationProcess {
                        ProcessId = this.Id
                    };
                    this.ProcessInfo.ExpirationCommandId = expirationCommand.Id;
                    this.AddCommand(new Envelope <ICommand>(expirationCommand)
                    {
                        Delay = expirationWindow.Add(BufferTimeBeforeReleasingSeatsAfterExpiration),
                    });
                }
                else
                {
                    this.AddCommand(new RejectOrder {
                        OrderId = this.ProcessInfo.OrderId
                    });
                    this.ProcessInfo.Completed = true;
                }
            }
            else
            {
                if (message.ConferenceId != this.ProcessInfo.ConferenceId)
                {
                    // throw only if not reprocessing
                    throw new InvalidOperationException();
                }
            }
        }
Beispiel #2
0
        public void Handle(OrderPlaced message)
        {
            if (this.State == ProcessState.NotStarted)
            {
                this.ConferenceId = message.ConferenceId;
                this.OrderId      = message.SourceId;

                this.ReservationId             = message.SourceId;
                this.ReservationAutoExpiration = message.ReservationAutoExpiration;
                var expirationWindow = message.ReservationAutoExpiration.Subtract(DateTime.UtcNow);

                if (expirationWindow > TimeSpan.Zero)
                {
                    this.State = ProcessState.AwaitingReservationConfirmation;
                    var seatReservationCommand = new MakeSeatReservation {
                        ConferenceId  = this.ConferenceId,
                        ReservationId = this.ReservationId,
                        Seats         = message.Seats.ToList()
                    };

                    this.SeatReservationCommandId = seatReservationCommand.Id;

                    this.AddCommand(new Envelope <ICommand>(seatReservationCommand)
                    {
                        TimeToLive = expirationWindow.Add(TimeSpan.FromMinutes(1))
                    });

                    var expirationCommand = new ExpireRegistrationProcess()
                    {
                        ProcessId = this.Id
                    };
                    this.ExpirationCommandId = expirationCommand.Id;
                    this.AddCommand(new Envelope <ICommand>(expirationCommand)
                    {
                        Delay = expirationWindow.Add(BufferTimeBeforeReleasingSeatsAfterExpiration)
                    });
                }
                else
                {
                    this.AddCommand(new RejectOrder {
                        OrderId = this.OrderId
                    });
                    this.Completed = true;
                }
            }
            else
            {
                if (message.ConferenceId != this.ConferenceId)
                {
                    throw new InvalidOperationException();
                }
            }
        }
Beispiel #3
0
        public void Handle(OrderUpdated message)
        {
            if (this.State == ProcessState.AwaitingReservationConfirmation ||
                this.State == ProcessState.ReservationConfirmationReceived)
            {
                this.State = ProcessState.AwaitingReservationConfirmation;

                var seatReservationCommand = new MakeSeatReservation {
                    ConferenceId  = this.ConferenceId,
                    ReservationId = this.ReservationId,
                    Seats         = message.Seats.ToList()
                };

                this.SeatReservationCommandId = seatReservationCommand.Id;
                this.AddCommand(seatReservationCommand);
            }
            else
            {
                throw new InvalidOperationException("The order cannot be updated at this stage.");
            }
        }
Beispiel #4
0
        public async Task HandleAsync(ICommandContext context, MakeSeatReservation command)
        {
            var conference = await context.GetAsync <Conference>(command.AggregateRootId);

            conference.MakeReservation(command.ReservationId, command.Seats.Select(x => new ReservationItem(x.SeatType, x.Quantity)).ToList());
        }
 public void Handle(ICommandContext context, MakeSeatReservation command)
 {
     context.Get <Conference>(command.AggregateRootId).MakeReservation(command.ReservationId, command.Seats.Select(x => new ReservationItem(x.SeatType, x.Quantity)).ToList());
 }