예제 #1
0
 void Apply(OrderPlaced @event)
 {
     Data.Id                  = @event.AggregateId;
     Data.State               = Placed;
     Data.BillingAccountId    = @event.BillingAccountId;
     Data.CatalogId           = @event.CatalogId;
     Data.QuantityOrdered     = @event.Quantity;
     Data.ActivateImmediately = @event.ActivateImmediately;
     Data.StartedOn           = @event.ReceivedDate;
     Data.IdempotencyToken    = @event.IdempotencyToken;
 }
예제 #2
0
        public async Task Receive(OrderPlaced @event, IMessageContext context)
        {
            if (Data.State == Canceled)
            {
                return;
            }

            var tokenVault = (ITokenVault)context.GetService(typeof(ITokenVault));
            var request    = new TransferRequest(@event.AggregateId, @event.BillingAccountId, @event.CatalogId, @event.Quantity, @event.ActivateImmediately, @event.CorrelationId);
            var success    = await tokenVault.Transfer(request, context.CancellationToken);

            if (success)
            {
                Record(new OrderFulfilled(Id));
                MarkAsComplete();
            }
            else
            {
                // TODO: handle and reply with event when reservation cannot be satisfied; retry should be possible
                await Handle(new CancelOrder( Id, Version ), context);
            }
        }
예제 #3
0
        public async Task Handle(PlaceOrder command, IMessageContext context)
        {
            if (Data.IdempotencyToken == command.IdempotencyToken)
            {
                return;
            }

            var receivedDate     = Now;
            var afterOneDay      = receivedDate.AddDays(1d);
            var orderId          = command.AggregateId;
            var billingAccountId = command.BillingAccountId;
            var catalogId        = command.CatalogId;
            var orderPlaced      = new OrderPlaced(orderId,
                                                   billingAccountId,
                                                   catalogId,
                                                   command.Quantity,
                                                   command.ActivateImmediately,
                                                   receivedDate,
                                                   command.IdempotencyToken);

            Record(orderPlaced);
            await RequestTimeout(afterOneDay, new OrderTookTooLongToFulfill( orderId ), context);
        }