예제 #1
0
        public void Handle(CookFood message)
        {
            Thread.Sleep(_timeToCook);
            var order = message.Order;

            order.Ingredients = order.Items.Select(i => ingredientDb[i.ItemName]).ToArray();

            _bus.Publish(new OrderCooked(order, message.MessageId, message.CorrelationId));
        }
예제 #2
0
 public void HandleOutstandingPayments()
 {
     while (true)
     {
         TakePayment takePayment;
         while (_orders.TryDequeue(out takePayment))
         {
             takePayment.Order.Paid = true;
             _bus.Publish(new OrderPaid(takePayment.Order, takePayment.MessageId, takePayment.CorrelationId));
         }
         Thread.Sleep(1);
     }
 }
예제 #3
0
        public void Handle(PriceOrder message)
        {
            var     order    = message.Order;
            decimal subtotal = 0M;

            foreach (var item in order.Items)
            {
                var price = dishPrices[item.ItemName];
                item.Price = price;
                subtotal  += price * item.Qty;
            }

            var tax = subtotal * TaxRate;

            order.Subtotal = subtotal;
            order.Tax      = tax;
            order.Total    = subtotal + tax;

            bus.Publish(new OrderPriced(order, message.MessageId, message.CorrelationId));
        }
예제 #4
0
        public string PlaceOrder(Guid correlationId)
        {
            DateTime liveUntil = DateTime.UtcNow.Add(TimeSpan.FromSeconds(10.0));
            var      order     = new Order
            {
                OrderId     = orderId++.ToString(CultureInfo.InvariantCulture),
                TableNumber = 5,
                ServerName  = "Dave",
                TimeStamp   = DateTime.Now.ToShortTimeString(),
                Items       = new[]
                {
                    new OrderItem {
                        ItemName = "Spaghetti Bolognese", Qty = 2
                    },
                    new OrderItem {
                        ItemName = "Fish", Qty = 3
                    },
                },
                LiveUntil = liveUntil
            };

            bus.Publish(new OrderPlaced(order, Guid.Empty, correlationId, liveUntil));
            return(order.OrderId);
        }