コード例 #1
0
        public async Task <List <Event> > make(OrderInEvent orderInEvent)
        {
            setHostName();

            //logger.debug("orderIn: " + orderInEvent.toString());

            switch (orderInEvent.item)
            {
            case Item.COFFEE_BLACK:
                return(await prepare(orderInEvent, 5));

            case Item.COFFEE_WITH_ROOM:
                return(await prepare(orderInEvent, 5));

            case Item.ESPRESSO:
                return(await prepare(orderInEvent, 7));

            case Item.ESPRESSO_DOUBLE:
                return(await prepare(orderInEvent, 7));

            case Item.CAPPUCCINO:
                return(await prepare(orderInEvent, 9));

            default:
                return(await prepare(orderInEvent, 11));
            }
        }
コード例 #2
0
        async Task <List <Event> > prepare(OrderInEvent orderInEvent, int seconds)
        {
            // decrement the item in inventory
            try
            {
                inventory.decrementItem(orderInEvent.item);
            }
            catch (EightySixException e)
            {
                Console.WriteLine(orderInEvent.item + " is 86'd");
                return(new List <Event> {
                    new EightySixEvent(orderInEvent.item)
                });
            }

            try
            {
                await Task.Delay(seconds * 1000);
            }
            catch (ThreadInterruptedException e)
            {
                Thread.CurrentThread.Interrupt();
            }

            return(new List <Event>
            {
                new OrderUpEvent(
                    EventType.KITCHEN_ORDER_UP,
                    orderInEvent.orderId,
                    orderInEvent.name,
                    orderInEvent.item,
                    orderInEvent.itemId,
                    madeBy)
            });
        }
コード例 #3
0
        private void HandleOrderIn(string message, CancellationToken cancellationToken)
        {
            OrderInEvent orderIn = JsonSerializer.Deserialize <OrderInEvent>(message);

            if (orderIn.eventType.Equals(EventType.KITCHEN_ORDER_IN))
            {
                Console.WriteLine($"Kitchen Making Order " + message);

                /*List<Event> kitchenOutput = await _kitchen.make(orderIn);
                 *
                 * String orderUpJson = JsonSerializer.Serialize(kitchenOutput.First());
                 * await SendMessage(orderUpJson);*/

                _kitchen.make(orderIn).ContinueWith(async kitchenOutput =>
                {
                    Event orderUp = kitchenOutput.Result.First();
                    if (orderUp.GetType() == typeof(OrderUpEvent))
                    {
                        String orderUpJson = JsonSerializer.Serialize((OrderUpEvent)orderUp);
                        //String orderUpJson = JsonSerializer.Serialize(o.Result);
                        await SendMessage(orderUpJson);
                    }
                }, cancellationToken);
            }
        }
コード例 #4
0
        private async Task <List <Event> > prepare(OrderInEvent orderInEvent, int seconds)
        {
            // decrement the item in inventory
            try
            {
                inventory.decrementItem(orderInEvent.item);
            }
            catch (EightySixException e) {
                Console.WriteLine(orderInEvent.item + " is 86'd");
                return(new List <Event> {
                    new EightySixEvent(orderInEvent.item)
                });
            }
            catch (EightySixCoffeeException e) {
                // 86 both coffee items
                Console.WriteLine("coffee is 86'd");
                return(new List <Event>
                {
                    new EightySixEvent(Item.COFFEE_WITH_ROOM),
                    new EightySixEvent(Item.COFFEE_BLACK)
                });
            }

            try
            {
                await Task.Delay(seconds * 1000);
            }
            catch (ThreadInterruptedException e)
            {
                Thread.CurrentThread.Interrupt();
            }

            return(new List <Event>
            {
                new OrderUpEvent(
                    EventType.BEVERAGE_ORDER_UP,
                    orderInEvent.orderId,
                    orderInEvent.name,
                    orderInEvent.item,
                    orderInEvent.itemId,
                    madeBy)
            });
        }
コード例 #5
0
        private void HandleOrderIn(string message, CancellationToken cancellationToken)
        {
            OrderInEvent orderIn = JsonSerializer.Deserialize <OrderInEvent>(message);

            if (orderIn.eventType.Equals(EventType.BEVERAGE_ORDER_IN))
            {
                Console.WriteLine($"Barista Making Order " + message);

                _barista.make(orderIn).ContinueWith(async baristaOutput =>
                {
                    Event orderUp = baristaOutput.Result.First();
                    if (orderUp.GetType() == typeof(OrderUpEvent))
                    {
                        String orderUpJson = JsonSerializer.Serialize((OrderUpEvent)orderUp);
                        await SendMessage(orderUpJson);
                    }
                }, cancellationToken);
            }
        }
コード例 #6
0
        public async Task <List <Event> > make(OrderInEvent orderInEvent)
        {
            setHostName();

            switch (orderInEvent.item)
            {
            case Item.CAKEPOP:
                return(await prepare(orderInEvent, 5));

            case Item.CROISSANT:
                return(await prepare(orderInEvent, 5));

            case Item.CROISSANT_CHOCOLATE:
                return(await prepare(orderInEvent, 5));

            case Item.MUFFIN:
                return(await prepare(orderInEvent, 7));

            default:
                return(await prepare(orderInEvent, 11));
            }
        }