Пример #1
0
 public override void DoStep(Dialog userInput, IBartenderController controller, String garnish)
 {
     MessageToUser     = String.Format("Garnish the drink with {0}.", garnish);
     NextGrammarNeeded = BartenderApp.ConfirmationRuleName;
     IsStepDone        = true;
     ShouldCancel      = false;
 }
Пример #2
0
 public virtual void DoStep(Dialog d, IBartenderController controller)
 {
     IsStepDone        = true;
     ShouldCancel      = false;
     MessageToUser     = null;
     NextGrammarNeeded = null;
 }
Пример #3
0
 public override void DoStep(Dialog userInput, IBartenderController controller, Ingredient ingredient)
 {
     controller.DispenseLiquid(ingredient.GetAvailableKeys(controller.AvailableLiquids).First(), ingredient.AmountQuantityInmL);
     IsStepDone        = true;
     ShouldCancel      = false;
     MessageToUser     = null;
     NextGrammarNeeded = null;
 }
Пример #4
0
 public RecipeStepCall Call(Dialog userResponse, IBartenderController controller)
 {
     CallInternal(userResponse, controller);
     if (!_step.IsStepDone || ShouldCancel || _nextStep == null)
     {
         return(this);
     }
     return(_nextStep.Call(null, controller));
 }
Пример #5
0
 public override void DoStep(Dialog d, IBartenderController controller)
 {
     if (_endAfterCall || DoStepIsCalled)
     {
         IsStepDone = true;
     }
     else
     {
         IsStepDone = false;
     }
     DoStepIsCalled = true;
 }
Пример #6
0
        private static void TestDoStepAllTrueAnswers(ShakeStep step, IBartenderController bartender, int numTrueAnswers, String expectedAnswer, bool shouldBeFinished)
        {
            Dictionary <String, String> trueInput = new Dictionary <string, string>
            {
                { "answer", "true" },
            };

            for (int i = 0; i < numTrueAnswers + 1; i++)
            {
                step.DoStep(new Dialog(trueInput, "Test Phrase"), bartender);
            }
            Assert.AreEqual(expectedAnswer, step.MessageToUser);
            Assert.AreEqual(shouldBeFinished, step.IsStepDone);
            Assert.AreEqual("Shake", step.Name);
            Assert.AreEqual(shouldBeFinished ? null : BartenderApp.ConfirmationRuleName, step.NextGrammarNeeded);
            Assert.AreEqual(false, step.ShouldCancel);
        }
Пример #7
0
 public override void DoStep(Dialog userInput, IBartenderController controller, Ingredient ingredient)
 {
     if (userInput == null || String.IsNullOrEmpty(userInput.GetPropertyValue("answer")))
     {
         MessageToUser     = String.Format("Add {0} to the glass and tell me when you are done.", ingredient.Name);
         NextGrammarNeeded = BartenderApp.ConfirmationRuleName;
         IsStepDone        = false;
         ShouldCancel      = false;
     }
     else
     {
         IsStepDone        = true;
         ShouldCancel      = !Boolean.Parse(userInput.GetPropertyValue("answer"));
         MessageToUser     = null;
         NextGrammarNeeded = null;
     }
 }
Пример #8
0
 public override void DoStep(Dialog userInput, IBartenderController controller)
 {
     if (userInput == null || String.IsNullOrEmpty(userInput.GetPropertyValue("answer")))
     {
         MessageToUser     = String.Format("Strain the drink.");
         NextGrammarNeeded = BartenderApp.ConfirmationRuleName;
         IsStepDone        = false;
         ShouldCancel      = false;
     }
     else
     {
         IsStepDone        = true;
         ShouldCancel      = !Boolean.Parse(userInput.GetPropertyValue("answer"));
         MessageToUser     = null;
         NextGrammarNeeded = null;
     }
 }
Пример #9
0
 public override void DoStep(Dialog userInput, IBartenderController controller)
 {
     if (userInput == null || String.IsNullOrEmpty(userInput.GetPropertyValue("answer")))
     {
         MessageToUser     = String.Format("Place a {1} glass underneath the spout of the bartender so I can make you a {0}.", _drinkName, _glassName);
         NextGrammarNeeded = BartenderApp.ConfirmationRuleName;
         IsStepDone        = false;
         ShouldCancel      = false;
     }
     else
     {
         ShouldCancel      = !Boolean.Parse(userInput.GetPropertyValue("answer"));
         IsStepDone        = true;
         MessageToUser     = null;
         NextGrammarNeeded = null;
     }
 }
Пример #10
0
        public override void DoStep(Dialog userInput, IBartenderController controller)
        {
            switch (_state)
            {
            case ShakeStepState.Start:
                MessageToUser     = String.Format("Pour the drink into a shaker.");
                NextGrammarNeeded = BartenderApp.ConfirmationRuleName;
                IsStepDone        = false;
                ShouldCancel      = false;
                _state            = ShakeStepState.HasSwitchedGlasses;
                break;

            case ShakeStepState.HasSwitchedGlasses:
                ShouldCancel      = !Boolean.Parse(userInput.GetPropertyValue("answer"));
                IsStepDone        = ShouldCancel;
                MessageToUser     = ShouldCancel ? null : String.Format("Shake the drink.");
                NextGrammarNeeded = ShouldCancel ? null : BartenderApp.ConfirmationRuleName;
                _state            = ShakeStepState.HasShaken;
                break;

            case ShakeStepState.HasShaken:
                ShouldCancel      = !Boolean.Parse(userInput.GetPropertyValue("answer"));
                IsStepDone        = ShouldCancel;
                MessageToUser     = ShouldCancel ? null : String.Format("Pour the drink back into the glass.");
                NextGrammarNeeded = ShouldCancel ? null : BartenderApp.ConfirmationRuleName;
                _state            = ShakeStepState.HasReturnedToGlass;
                break;

            case ShakeStepState.HasReturnedToGlass:
                IsStepDone        = true;
                ShouldCancel      = !Boolean.Parse(userInput.GetPropertyValue("answer"));
                MessageToUser     = null;
                NextGrammarNeeded = null;
                break;

            default:
                break;
            }
        }
Пример #11
0
        private static void TestDoStepFalseAnswer(ShakeStep step, IBartenderController bartender, int numTrueAnswers)
        {
            Dictionary <String, String> trueInput = new Dictionary <string, string>
            {
                { "answer", "true" },
            };
            Dictionary <String, String> falseInput = new Dictionary <string, string>
            {
                { "answer", "false" },
            };

            for (int i = 0; i < numTrueAnswers + 1; i++)
            {
                step.DoStep(new Dialog(trueInput, "Test Phrase"), bartender);
            }
            step.DoStep(new Dialog(falseInput, "Test Phrase"), bartender);
            Assert.AreEqual(null, step.MessageToUser);
            Assert.AreEqual(true, step.IsStepDone);
            Assert.AreEqual("Shake", step.Name);
            Assert.AreEqual(null, step.NextGrammarNeeded);
            Assert.AreEqual(true, step.ShouldCancel);
        }
Пример #12
0
 protected virtual void CallInternal(Dialog userResponse, IBartenderController controller)
 {
     _step.DoStep(userResponse, controller);
 }
Пример #13
0
 public virtual void DoStep(Dialog d, IBartenderController controller, T argument)
 {
     base.DoStep(d, controller);
 }
Пример #14
0
 protected override void CallInternal(Dialog userResponse, IBartenderController controller)
 {
     (_step as RecipeStep <T>).DoStep(userResponse, controller, _argument);
 }
Пример #15
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);
        }