Beispiel #1
0
 static void CreateProducerAndConsumers()
 {
     for (int i = 0; i < guestCount; i++)
     {
         guestArray[i] = new Guest()
         {
             GuestId   = i + 1,
             GuestName = string.Concat(Enumerable.Repeat("*", i + 1))
         };
     }
     for (int i = 0; i < trayCount; i++)
     {
         trayArray[i] = new Tray()
         {
             TrayId   = i + 1,
             FoodType = (Food)i
         };
     }
 }
Beispiel #2
0
 private void ProduceCookie(Tray tray)
 {
     if (cookieCount > 0 && tray.MaxCookieCount != tray.ActiveCookieCount)
     {
         if (tray.ActiveCookieCount == 0 || tray.ActiveCookieCount == 1)
         {
             if (cookieCount == tray.ActiveCookieCount)
             {
                 tray.ActiveCookieCount += cookieCount;
                 cookieCount             = 0;
             }
             else
             {
                 tray.ActiveCookieCount += tray.MaxCookieCount;
                 cookieCount            -= tray.MaxCookieCount;
             }
             ProduceInfo(tray.TrayId.ToString(), "kurabiye");
         }
     }
 }
Beispiel #3
0
 private void ProduceDrink(Tray tray)
 {
     if (drinkCount > 0 && tray.MaxDrinkCount != tray.ActiveDrinkCount)
     {
         if (tray.ActiveDrinkCount == 0 || tray.ActiveDrinkCount == 1)
         {
             if (drinkCount == tray.MaxDrinkCount)
             {
                 tray.ActiveDrinkCount += drinkCount;
                 drinkCount             = 0;
             }
             else
             {
                 tray.ActiveDrinkCount += tray.MaxDrinkCount;
                 drinkCount            -= tray.MaxDrinkCount;
             }
             ProduceInfo(tray.TrayId.ToString(), "içecek");
         }
     }
 }
Beispiel #4
0
 private void ProduceCake(Tray tray)
 {
     if (cakeCount > 0 && tray.MaxCakeCount != tray.ActiveCakeCount)
     {
         if (tray.ActiveCakeCount == 0 || tray.ActiveCakeCount == 1)
         {
             if (cakeCount == tray.MaxCakeCount)
             {
                 tray.ActiveCakeCount += cakeCount;
                 cakeCount             = 0;
             }
             else
             {
                 tray.ActiveCakeCount += tray.MaxCakeCount;
                 cakeCount            -= tray.MaxCakeCount;
             }
             ProduceInfo(tray.TrayId.ToString(), "kek");
         }
     }
 }
Beispiel #5
0
        private void CalculateFoodCounts(Tray tray, Guest guest, Food food)
        {
            lock (lockObject)
            {
                switch (food)
                {
                case Food.Cake:
                    ConsumeCake(tray, guest);
                    break;

                case Food.Drink:
                    ConsumeDrink(tray, guest);
                    break;

                case Food.Cookie:
                    ConsumeCookie(tray, guest);
                    break;

                default:
                    break;
                }
            }
        }
Beispiel #6
0
 private void ConsumeCookie(Tray tray, Guest guest)
 {
     if (guest.ConsumedCookieCount < guest.MaxCookieCount)
     {
         if (tray.ActiveCookieCount == 0)
         {
             TrayDoesntExistItem(guest.GuestInfo, "kurabiye", tray.TrayId.ToString());
         }
         else
         {
             if (guest.HasConsumedAll || (!guest.HasConsumedAll && guest.ConsumedCookieCount == 0))
             {
                 ProduceCookie(tray);
                 ++guest.ConsumedCookieCount;
                 --tray.ActiveCookieCount;
                 ConsumedItem(guest.GuestInfo, "kurabiye", tray.TrayId.ToString());
             }
         }
     }
     else
     {
         ReachedMaxConsumeCount(guest.GuestInfo, "kurabiye");
     }
 }
Beispiel #7
0
 private void ConsumeDrink(Tray tray, Guest guest)
 {
     if (guest.ConsumedDrinkCount < guest.MaxDrinkCount)
     {
         if (tray.ActiveDrinkCount == 0)
         {
             TrayDoesntExistItem(guest.GuestInfo, "içecek", tray.TrayId.ToString());
         }
         else
         {
             if (guest.HasConsumedAll || (!guest.HasConsumedAll && guest.ConsumedDrinkCount == 0))
             {
                 ProduceDrink(tray);
                 ++guest.ConsumedDrinkCount;
                 --tray.ActiveDrinkCount;
                 ConsumedItem(guest.GuestInfo, "içecek", tray.TrayId.ToString());
             }
         }
     }
     else
     {
         ReachedMaxConsumeCount(guest.GuestInfo, "içecek");
     }
 }