private async Task <DeviceCommand> CallLuisAsync(string input)
        {
            var parsedMessage = await luisClient.parseInput(input);

            CommandBase command;

            switch (parsedMessage.topScoringIntent.intent)
            {
            case "Count":
                command = new CountCommand(parsedMessage.entities);
                break;

            case "Location":
                command = new LocationCommand(parsedMessage.entities);
                break;

            case "Calculation":
                command = new CalculationCommand(parsedMessage.entities);
                break;

            case "Timer":
                command = new TimerCommand(parsedMessage.entities);
                break;

            default:
                command = new NoneCommand();
                break;
            }

            return(await command.Run());
        }
Beispiel #2
0
 // The App class accepts its commands via constructor-injection
 public App(CircleCommand circleCommand, TriangleCommand triangleCommand, SquareCommand squareCommand, NoneCommand noneCommand)
 {
     _circleCommand   = circleCommand;
     _triangleCommand = triangleCommand;
     _squareCommand   = squareCommand;
     _noneCommand     = noneCommand;
 }
Beispiel #3
0
        public void Show_Help_When_UnkownArg_Passed()
        {
            CommandParser parser  = new CommandParser();
            CommandData   data    = parser.Parse(new string [] { "-invalidarg" });
            NoneCommand   command = (NoneCommand)data.GetCommand();

            command.Out = new StringWriter();
            command.Execute();
            StringAssert.Contains("Error: The command line switch -invalidarg is unknown", command.Out.ToString());
        }
Beispiel #4
0
        public void Show_Help_When_No_Arg_Passed()
        {
            CommandParser parser  = new CommandParser();
            CommandData   data    = parser.Parse(new string[0]);
            NoneCommand   command = (NoneCommand)data.GetCommand();

            command.Out = new StringWriter();
            command.Execute();
            StringAssert.Contains("Options: ", command.Out.ToString());
        }
Beispiel #5
0
        /// <summary>
        /// Parses text that has been marked up using Marker.
        /// </summary>
        /// <param name="text">The marked up string of text.</param>
        /// <returns>A <see cref="TextSequence" /> based on the marked up text.</returns>
        public static List <IInstruction> Parse(string text)
        {
            var instructions = new List <IInstruction>();

            if (string.IsNullOrWhiteSpace(text))
            {
                return(instructions);
            }

            var sb           = new StringBuilder();
            var skip         = false;
            var substitution = false;

            foreach (var ch in text)
            {
                IInstruction command;
                if (substitution)
                {
                    // Get the contents of the substitution token and parse it.
                    if (ch == '}')
                    {
                        substitution = false;
                        instructions.Add(ParseSubstitution(sb.ToString()));
                        sb = new StringBuilder();
                        continue;
                    }
                }

                if (skip)
                {
                    command = new NoneCommand();
                    skip    = false;
                }
                else
                {
                    command = Token.TokenList.ContainsKey(ch) ? Token.TokenList[ch] : new NoneCommand();
                }

                switch (command.Command)
                {
                case Command.Escape:
                    skip = true;
                    continue;

                case Command.TextStyle:
                    if (sb.Length > 0)
                    {
                        instructions.Add(new TextCommand {
                            Text = sb.ToString()
                        });
                        sb = new StringBuilder();
                    }
                    instructions.Add(command);
                    break;

                case Command.Substitution:
                    if (sb.Length > 0)
                    {
                        instructions.Add(new TextCommand {
                            Text = sb.ToString()
                        });
                        sb = new StringBuilder();
                    }
                    substitution = true;
                    break;

                default:
                    sb.Append(ch);
                    break;
                }
            }

            // If there is anything in our StringBuilder, flush it.
            if (sb.Length > 0)
            {
                instructions.Add(new TextCommand {
                    Text = sb.ToString()
                });
            }

            return(instructions);
        }