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(ExpireRegistrationProcess command)
 {
     using (var context = this._contextFactory.Invoke()) {
         var pm = context.Find(x => x.Id == command.ProcessId);
         if (pm != null)
         {
             pm.Handle(command);
             context.Save(pm);
         }
     }
 }
Beispiel #3
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();
                }
            }
        }
        public void Handle(ExpireRegistrationProcess command)
        {
            var pInfo = repository.GetBy(x => x.Id == command.ProcessId).FirstOrDefault();

            if (pInfo != null)
            {
                var manager = new RegistrationProcessManager(pInfo);
                manager.Handle(command);
                context.RegisterModified(manager.ProcessInfo);
                context.Commit();
            }
        }
Beispiel #5
0
        public void Handle(ExpireRegistrationProcess command)
        {
            if (this.ExpirationCommandId == command.Id)
            {
                this.Completed = true;

                this.AddCommand(new RejectOrder {
                    OrderId = this.OrderId
                });
                this.AddCommand(new CancelSeatReservation {
                    ConferenceId  = this.ConferenceId,
                    ReservationId = this.ReservationId
                });

                // TODO cancel payment if any
            }

            // else ignore the message as it is no longer relevant (but not invalid)
        }