Exemplo n.º 1
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;
        }
Exemplo n.º 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);
        }