Пример #1
0
 /// <summary>
 /// Process the command by the base command type. Calls the methods
 /// that are capable to responding to a particular base command.
 /// </summary>
 /// <param name="command">The command to process.</param>
 private static void ProcessCommand(Command command)
 {
     switch (command.BaseType)
     {
         case CommandType.Load:
             loadTool.RunCommand(command.RawCommands);
             break;
         case CommandType.Run:
             RunHandler(command.RawCommands);
             break;
         case CommandType.Save:
             saveTool.RunCommand(command.RawCommands);
             break;
         case CommandType.Status:
             StatusHandler(command.RawCommands);
             break;
         case CommandType.Update:
             updateTool.RunCommand(command.RawCommands);
             break;
         case CommandType.Help:
             HelpHandler(command.RawCommands);
             break;
         case CommandType.Command:
             CommandScriptHandler(command.RawCommands);
             break;
         case CommandType.App:
             AppLauncherHandler(command.RawCommands);
             break;
         case CommandType.Bad:
         default:
             DefaultHandler();
             break;
     }
 }
Пример #2
0
        /// <summary>
        /// Creates a Command object from a line of text. This is usualy the next line from
        /// the command line.
        /// </summary>
        /// <param name="raw">The raw unprocessed string that contains the
        /// command line commands</param>
        /// <returns></returns>
        private static Command RetrieveCommand(string raw)
        {
            string[] split = raw.Split(' ');
            List<RawCommand> rawCommands = new List<RawCommand>();
            //Creates a list of raw commands
            for (int i = 0; i < split.Length; i++)
            {
                if (split[i][0] == '-' && split[i].Length > 1)
                {
                    RawCommand tempCommand = new RawCommand();
                    tempCommand.CommandChar = split[i][1];
                    rawCommands.Add(tempCommand);
                }
                else if(rawCommands.Count > 0)
                {
                    if (rawCommands[rawCommands.Count - 1].Value == "")
                    {
                        rawCommands[rawCommands.Count - 1].Value = split[i];
                    }
                    else
                    {
                        rawCommands[rawCommands.Count - 1].Value =
                            rawCommands[rawCommands.Count - 1].Value + " " + split[i];
                    }
                }
            }

            Command command = new Command();
            //maps the first command to the proper root command
            if (rawCommands.Count == 0)
            {
                command.BaseType = CommandType.Bad;
            }
            else if (rawCommands[0].CommandChar == 'h')
            {
                command.BaseType = CommandType.Help;
            }
            else if (rawCommands[0].CommandChar == 'r')
            {
                command.BaseType = CommandType.Run;
            }
            else if (rawCommands[0].CommandChar == 'l')
            {
                command.BaseType = CommandType.Load;
            }
            else if (rawCommands[0].CommandChar == 's')
            {
                command.BaseType = CommandType.Save;
            }
            else if (rawCommands[0].CommandChar == 'u')
            {
                command.BaseType = CommandType.Update;
            }
            else if (rawCommands[0].CommandChar == 'i')
            {
                command.BaseType = CommandType.Status;
            }
            else if (rawCommands[0].CommandChar == 'c')
            {
                command.BaseType = CommandType.Command;
            }
            else if (rawCommands[0].CommandChar == 'a')
            {
                command.BaseType = CommandType.App;
            }
            else if (rawCommands[0].CommandChar == 'e')
            {
                command.BaseType = CommandType.Exit;
            }
            else command.BaseType = CommandType.Bad;

            command.RawCommands = rawCommands;
            return command;
        }