コード例 #1
0
        public void ServeDrink(TableRequests tr)
        {
            _result = new string[0];

            int           j   = 0;
            TableRequests tr2 = tr;

            foreach (KeyValuePair <string, List <IMenuItem> > customerMenus in tr)
            {
                string drinkAll = "";
                foreach (IMenuItem order in customerMenus.Value)
                {
                    if (order is CocaCola)
                    {
                        drinkAll = drinkAll + menu.Cola + ",";
                    }
                    else if (order is Pepsi)
                    {
                        drinkAll = drinkAll + menu.Pepsi + ",";
                    }
                    else if (order is Tea)
                    {
                        drinkAll = drinkAll + menu.Tea + ",";
                    }
                    order.Serve();
                }

                if (drinkAll != "")
                {
                    Array.Resize(ref _result, j + 1);
                    _result[j] = "Customer " + customerMenus.Key + " is served " + drinkAll;
                    j++;
                }
            }
        }
コード例 #2
0
        public void Receive(int numberChicken, int numberEgg, menu typeDrink, string customerName)
        {
            if (!isTableRequestCreated)
            {
                _tr = new TableRequests();
                isTableRequestCreated = true;
            }

            for (int i = 0; i < numberChicken; i++)
            {
                _tr.Add <Chicken>(customerName);
            }


            for (int i = 0; i < numberEgg; i++)
            {
                _tr.Add <Egg>(customerName);
            }

            if (typeDrink != menu.NoDrink)
            {
                if (typeDrink == menu.Pepsi)
                {
                    _tr.Add <Pepsi>(customerName);
                }
                else if (typeDrink == menu.Cola)
                {
                    _tr.Add <CocaCola>(customerName);
                }
                else
                {
                    _tr.Add <Tea>(customerName);
                }
            }
        }
コード例 #3
0
        public Task Process(TableRequests tr)
        {
            Task t = Task.Run(() =>
            {
                this.Status = status.Busy;
                List <CookedFood> menuItems;

                menuItems = tr.Get <CookedFood>();
                Parallel.ForEach(menuItems, menuItem => {
                    menuItem.Prepare();
                });
                this.Status = status.Free;
            });

            return(t);
        }
コード例 #4
0
        private async void sendCustomerRequestsCook_Click(object sender, EventArgs e)
        {
            try
            {
                if (server.Tr == null)
                {
                    throw new NullReferenceException("order not sent to the Cook");
                }
                Boolean       b  = true;
                TableRequests tr = server.Tr;
                server.Send();
                server.ServeDrink(tr);
                showResult("drink");
                while (b)
                {
                    if (cook.Status == status.Free)
                    {
                        await cook.Process(tr);

                        await server.Serve(tr);

                        showResult("food");
                        b = false;
                    }
                    else if (cook2.Status == status.Free)
                    {
                        await cook2.Process(tr);

                        await server.Serve(tr);

                        showResult("food");
                        b = false;
                    }
                    System.Threading.Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                textResult.Text = ex.Message;
            }
        }
コード例 #5
0
        public Task Serve(TableRequests tr)
        {
            Task t = Task.Run(() =>
            {
                System.Threading.Thread.Sleep(4000);
                _result = new string[0];

                //TODO: Can you try to use LINQ instead of these 2 'foreach' ?
                //can`t use linq in TableRequest
                int j = 0;
                foreach (KeyValuePair <string, List <IMenuItem> > customerMenus in tr)
                {
                    int numberChiken = 0;
                    int numberEgg    = 0;

                    foreach (IMenuItem order in customerMenus.Value)
                    {
                        if (order is Chicken)
                        {
                            numberChiken += ((Chicken)order).GetQuantity();
                        }
                        else if (order is Egg)
                        {
                            numberEgg += ((Egg)order).GetQuantity();
                        }
                        order.Serve();
                    }

                    Array.Resize(ref _result, j + 1);
                    _result[j] = "Customer " + customerMenus.Key + " is served " + numberChiken + " chicken, " + numberEgg + " egg";
                    j++;
                }
            });

            return(t);
        }