Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="drinkOrdered">The drink ordered</param>
        /// <param name="hasMilk">Indicates whether the drinks contains milk or not.
        /// It wasn't necessary given that the class drink amready contains the information
        /// However, it doesn't let us to enter invalid data e.g. icetea with milk</param>
        /// <returns></returns>
        public static async Task <string> PrepareOrder(Drink drinkOrdered, bool hasMilk)
        {
            Task <string> orderPreparation = null;

            CancellationTokenSource cancellationToken = new CancellationTokenSource();

            orderPreparation = drinkOrdered.Prepare(cancellationToken.Token);

            if (drinkOrdered is IceTea && hasMilk)
            {
                Thread.Sleep(Constants.CANCELLATION_WAITING_TIME);
                cancellationToken.Cancel();
            }


            return(await orderPreparation);
        }
Ejemplo n.º 2
0
        public static Drink OrderDrink(string type, bool hasMilk, bool hasSugar, bool hasChocolate)
        {
            Drink drink;

            switch (type)
            {
            case "Espresso":
                drink = new Espresso();
                break;

            case "HotTea":
                drink = new Tea();
                break;

            case "IceTea":
                drink = new IceTea();
                break;

            default:
                drink = new Drink();
                break;
            }
            try
            {
                drink.HasMilk      = hasMilk;
                drink.HasSugar     = hasSugar;
                drink.HasChocolate = hasChocolate;
                drink.Prepare();
            }
            catch (Exception ex)
            {
                Console.WriteLine("We are unable to prepare your drink.");
                Console.WriteLine(ex.Message);
                System.IO.File.WriteAllText(@"Error.txt", ex.ToString());
            }
            return(drink);
        }