Esempio n. 1
0
        public override bool Equals(object obj)
        {
            DrinkRecipe other = obj as DrinkRecipe;

            if (other == null)
            {
                return(false);
            }
            else if (other.FirstStep == null && FirstStep != null)
            {
                return(false);
            }
            else if (other.FirstStep != null && !other.FirstStep.Equals(FirstStep))
            {
                return(false);
            }
            else if (other.Name == null && Name != null)
            {
                return(false);
            }
            else if (other.Name != null && !other.Name.Equals(Name))
            {
                return(false);
            }
            else if (other.Ingredients.Count != Ingredients.Count)
            {
                return(false);
            }

            foreach (Ingredient ingredient in Ingredients)
            {
                if (!other.Ingredients.Contains(ingredient))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 2
0
        private void ParseXmlDocument(XmlDocument doc)
        {
            Dictionary <String, String> userStringLookup = new Dictionary <string, string>();

            foreach (XmlNode ingredient in doc.SelectNodes("DrinkRecipes/Ingredients/Ingredient"))
            {
                userStringLookup[ingredient.Attributes["Key"].Value] = ingredient.Attributes["Name"].Value;
            }

            Dictionary <String, double> drinkVolumes = new Dictionary <String, double>();

            foreach (XmlNode ingredient in doc.SelectNodes("DrinkRecipes/Glasses/Glass"))
            {
                drinkVolumes[ingredient.Attributes["Name"].Value] = Double.Parse(ingredient.Attributes["Volume"].Value);
            }

            _drinks = new List <DrinkRecipe>();
            foreach (XmlNode node in doc.SelectNodes("DrinkRecipes/Cocktails/Drink"))
            {
                _drinks.Add(DrinkRecipe.CreateFromXml(node, userStringLookup, drinkVolumes));
            }

            _drinks.RemoveAll(r => r == null);
        }
Esempio n. 3
0
        public static DrinkRecipe CreateFromXml(XmlNode recipeNode, Dictionary <String, String> userNameLookup, Dictionary <String, double> glassVolumes)
        {
            RecipeStepFactory factory = new RecipeStepFactory();
            DrinkRecipe       recipe  = new DrinkRecipe(recipeNode.Attributes["Name"].Value);
            // Determine total number of parts, static volume
            double totalParts   = 0;
            double staticVolume = 0;

            if (!glassVolumes.Keys.Contains(recipeNode.Attributes["Glass"].Value))
            {
                return(null);
            }
            double drinkVolume = glassVolumes[recipeNode.Attributes["Glass"].Value];

            foreach (XmlNode ingredient in recipeNode.SelectNodes("Ingredients/*"))
            {
                Ingredient ingred = Ingredient.CreateFromXml(ingredient, userNameLookup);
                if (ingred != null)
                {
                    recipe.Ingredients.Add(ingred);

                    // Get information so we can determine how much a part really is for this recipe.
                    if (ingred.AmountUnit == IngredientUnit.Part)
                    {
                        totalParts += ingred.AmountQuantity;
                    }
                    else
                    {
                        staticVolume += ingred.AmountQuantityInmL;
                    }
                }
                else
                {
                    return(null);
                }
            }
            double partVolume = (drinkVolume - staticVolume) / totalParts;

            if (partVolume < 0)
            {
                partVolume = drinkVolume / totalParts;
            }
            else if (partVolume == Double.PositiveInfinity)
            {
                partVolume = 0;
            }

            recipe.Ingredients.ForEach(i => i.SetPartAmount(partVolume));

            List <RecipeStepCall> calls = new List <RecipeStepCall>();

            calls.Add(new RecipeStepCall(factory.GetInitialStep(recipe.Name, recipeNode.Attributes["Glass"].Value)));
            foreach (XmlElement step in recipeNode.SelectNodes("Steps/Step").OfType <XmlElement>())
            {
                if (step.HasAttribute("Arguments"))
                {
                    foreach (String arg in step.Attributes["Arguments"].Value.Split(','))
                    {
                        if (recipe.Ingredients.Any(i => i.Key.Equals(arg)))
                        {
                            calls.Add(factory.GetRecipeStepCall(step.Attributes["Type"].Value, recipe.Ingredients.SingleOrDefault(i => i.Key.Equals(arg))));
                        }
                        else
                        {
                            calls.Add(factory.GetRecipeStepCall(step.Attributes["Type"].Value, arg.Replace('_', ' ')));
                        }
                    }
                }
                else
                {
                    calls.Add(factory.GetRecipeStepCall(step.Attributes["Type"].Value));
                }
            }

            calls.Reverse();
            foreach (RecipeStepCall call in calls)
            {
                call.AddNextStep(recipe.FirstStep);
                recipe.FirstStep = call;
            }
            return(recipe);
        }
Esempio n. 4
0
        public override string Speak()
        {
            base.Speak();
            Dialog phrase     = CurrentDialog;
            String subCommand = phrase.GetPropertyValue("Subcommand");
            IEnumerable <IBartenderController> controllers = ConfigManager.FindAllComponentsOfType <IBartenderController>();

            if (!controllers.Any())
            {
                ConversationIsOver = true;
                return(String.Empty);
            }
            else if (String.IsNullOrEmpty(subCommand) && _isCleaningPumps)
            {
                ConversationIsOver = true;
                if (Boolean.Parse(phrase.GetPropertyValue("answer")))
                {
                    foreach (IBartenderController controller in controllers)
                    {
                        foreach (String pump in controller.AvailableLiquids)
                        {
                            controller.DispenseLiquid(pump, 25);
                        }
                    }
                    return("Cleaning the pumps now.");
                }
                else
                {
                    return("Never mind.");
                }
            }
            else if (subCommand.Equals("cleanPumps"))
            {
                ConversationIsOver = false;
                _isCleaningPumps   = true;
                _nextGrammarName   = BartenderApp.ConfirmationRuleName;
                return("Make sure that the pumps are all no longer in the drinks. Pumps will run one at a time until all have been cleaned. Tell me when you are ready.");
            }
            else if (String.IsNullOrEmpty(subCommand))
            {
                ConversationIsOver = false;
                if (_call == null)
                {
                    _drinkBeingMade = phrase.GetPropertyValue("DrinkName");
                    DrinkRecipe recipe = _recipeProvider.Drinks.Single(d => d.Name.Equals(_drinkBeingMade));
                    _controllerInUse = controllers.FirstOrDefault(s => recipe.CanMakeFromRecipes(s.AvailableLiquids));
                    if (_controllerInUse == null)
                    {
                        ConversationIsOver = true;
                        return(String.Empty);
                    }
                    _call = recipe.Start();
                }
                _call = _call.Call(phrase, _controllerInUse);
                if (_call.IsDone)
                {
                    ConversationIsOver = true;
                    if (String.IsNullOrEmpty(_call.MessageToUser))
                    {
                        return(String.Format("Your {0} is now being made.", _drinkBeingMade));
                    }
                    else
                    {
                        return(_call.MessageToUser);
                    }
                }
                else if (_call.ShouldCancel)
                {
                    ConversationIsOver = true;
                    return("Never mind");
                }
                else
                {
                    _nextGrammarName = _call.NextGrammarNeeded;
                    return(_call.MessageToUser);
                }
            }
            else if (subCommand.Equals("drinkList"))
            {
                ConversationIsOver = true;
                IEnumerable <String>      ingredients = controllers.SelectMany(s => s.AvailableLiquids).ToList();
                IEnumerable <DrinkRecipe> recipes     = _recipeProvider.Drinks.Where(drink => drink.CanMakeFromRecipes(ingredients)).ToList();
                return(String.Format("I can make {0}.", SayList(recipes.Select(d => d.Name).ToList())));
            }
            else if (subCommand.Equals("ingredientList"))
            {
                ConversationIsOver = true;
                String      drinkBeingMade = phrase.GetPropertyValue("DrinkName");
                DrinkRecipe recipe         = _recipeProvider.Drinks.Single(d => d.Name.Equals(drinkBeingMade));
                return(String.Format("A {0} contains {1}.", recipe.Name, SayList(recipe.Ingredients.Select(d => d.Name).ToList())));
            }
            return(String.Empty);
        }