Exemple #1
0
        public string Receive(string chickenQ, string eggQ, string customerName, string drinkingType, TableRequests tableRequests)
        {
            this.tableRequests = tableRequests;
            if (receiveIndex > 7)
            {
                throw new Exception("Up to 8 customers are allowed per table. Send to Cook first!");
            }
            var   chQ      = Convert.ToInt32(chickenQ);
            var   eQ       = Convert.ToInt32(eggQ);
            Drink drinking = new Pepsi();

            if (drinkingType == "Cola")
            {
                drinking = new Cola();
            }
            if (drinkingType == "Tea")
            {
                drinking = new Tea();
            }
            ServeDrinkings.Add(customerName.ToUpper() + " is served " + drinking.GetType().Name);

            for (int i = 0; i < chQ; i++)
            {
                tableRequests.Add <Chicken>(customerName);
            }
            for (int i = 0; i < eQ; i++)
            {
                tableRequests.Add <Egg>(customerName);
            }
            receiveIndex++;
            return("Request received from: " + customerName.ToUpper());
        }
Exemple #2
0
 private void Initialize()
 {
     server        = new Server();
     FirstCook     = new Cook();
     SecondCook    = new Cook();
     tableRequests = new TableRequests();
 }
Exemple #3
0
 private void Initialize()
 {
     server          = new Server();
     cook            = new Cook();
     tableRequests   = new TableRequests();
     server.Ready   += (TableRequests tableRequests) => cook.Process(tableRequests);
     cook.Processed += server.Serve;
 }
Exemple #4
0
 private void Reset()
 {
     SetResult("Enjoy your food!");
     customerName.Text   = "";
     tableRequests       = new TableRequests();
     status              = Statuses.NotRecieved;
     server.receiveIndex = 0;
     server.ServeDrinkings.Clear();
 }
Exemple #5
0
 private void OnRunProcess(TableRequests tableRequests)
 {
     semaphore.WaitOne();
     State = CookState.Busy;
     OnProcess(tableRequests);
     Thread.Sleep(14000);
     State = CookState.Free;
     semaphore.Release();
 }
Exemple #6
0
        private void OnProcess(TableRequests tableRequests)
        {
            var chickenOrders = tableRequests.Get <Chicken>();

            Parallel.ForEach(chickenOrders, chicken =>
            {
                ((Chicken)chicken).PrepareFood();
            });

            var eggOrders = tableRequests.Get <Egg>();

            Parallel.ForEach(eggOrders, egg =>
            {
                using (egg as Egg)
                    (egg as Egg).PrepareFood();
            });
        }
Exemple #7
0
 public Task Process(TableRequests tableRequests) => Task.Run(() => OnRunProcess(tableRequests));