Пример #1
0
        private async Task <DialogTurnResult> ExecuteCommand(WaterfallStepContext stepContext, CancellationToken cancellationToken)
        {
            string resultText;
            var    prePromptUtterance = (await _storage.ReadAsync <Utterance>(new string[] { _prePromptUtteranceKey }))?.FirstOrDefault().Value;

            if (prePromptUtterance != null)
            {
                resultText = prePromptUtterance.Text;
                await _storage.DeleteAsync(new string[] { _prePromptUtteranceKey }, cancellationToken);
            }
            else
            {
                resultText = stepContext.Result.ToString().ToLower();
            }

            switch (resultText)
            {
            case "status":
                await SendStatus(stepContext, cancellationToken);

                return(await stepContext.ReplaceDialogAsync(_smokerLoopKey, null, cancellationToken));

            case "hold":
                var promptOptions = new PromptOptions
                {
                    Prompt      = MessageFactory.Text("What temperature?"),
                    RetryPrompt = MessageFactory.Text("Please enter a numerical value."),
                };
                return(await stepContext.PromptAsync(_setpointKey, promptOptions, cancellationToken));

            case "shutdown":
                return(await stepContext.PromptAsync(_shutdownKey, new PromptOptions { Prompt = MessageFactory.Text("Are you sure you want to shut down? The smoker will be in shutdown mode for 10 minutes and unable to accept any other commands.") }, cancellationToken));

            case "smoke":
                await SetSmoke(stepContext);

                return(await stepContext.ReplaceDialogAsync(_smokerLoopKey, null, cancellationToken));
            }

            int setpoint;

            if (resultText.StartsWith("hold") &&
                int.TryParse(resultText.Substring(4), out setpoint))
            {
                await SetHold(setpoint, stepContext, cancellationToken);

                return(await stepContext.ReplaceDialogAsync(_smokerLoopKey, null, cancellationToken));
            }

            await stepContext.Context.SendActivityAsync(MessageFactory.Text("I'm sorry, I don't understand that."), cancellationToken);

            return(await stepContext.ReplaceDialogAsync(_smokerLoopKey, null, cancellationToken));
        }