Exemplo n.º 1
0
        /// <summary>
        ///     Grabs all missing meals as soon as possible.
        /// </summary>
        private void GrabMissingMeals()
        {
            var changedEntries = new Dictionary <MealTypes, int>();

            while (_restOrder.Count > 0)
            {
                Thread.Sleep(Constants.CashierGrabMealRetryTimeoutMs);
                Console.WriteLine(@"Cashier {0} has pending meals. Retrying....", _employeeName);

                foreach (var orderEntry in _restOrder.Where(x => x.Value > 0))
                {
                    ICook cook = _cooks[orderEntry.Key];
                    int   takenCount;
                    cook.TryGetMeals(orderEntry.Value, out takenCount);
                    changedEntries.Add(orderEntry.Key, orderEntry.Value - takenCount);
                }

                //clean _restOrder collection from outside to avoid CollectionChanged exception.
                foreach (var changedEntry in changedEntries)
                {
                    _restOrder[changedEntry.Key] = changedEntry.Value;
                    if (changedEntry.Value == 0)
                    {
                        _restOrder.Remove(changedEntry.Key);
                    }
                }
                changedEntries.Clear();
            }
            _restOrder.Clear();
            Console.WriteLine(@"Order for client {0} is completed.", _currentClient.ClientId);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Tries to gather next client's order.
        /// </summary>
        public void TryToGatherOrder()
        {
            _currentClient = _line.Dequeue();

            foreach (var mealCountPair in _currentClient.Order.Where(order => order.Value > 0))
            {
                int takenCount;

                ICook cook = _cooks[mealCountPair.Key];

                #region log4net[debug]

                log.Debug(Id + " try to get " + mealCountPair.Value + " " + mealCountPair.Key);

                #endregion


                if (!cook.TryGetMeals(mealCountPair.Value, out takenCount))
                {
                    _restOrder.Add(mealCountPair.Key, mealCountPair.Value - takenCount);
                }
            }
        }