Esempio n. 1
0
    // build informations about all classes derived from ConsoleCmdBase
    static void BuildClassInfo()
    {
        Assembly assembly = Assembly.GetExecutingAssembly();

        Type baseType = typeof(ConsoleCmdBase);

        // grab all types
        Type[] types = assembly.GetTypes();

        foreach (var type in types)
        {
            if (!type.IsClass)
            {
                continue;
            }

            if (type.IsSubclassOf(baseType))
            {
                ConsoleCmdBase cmd = CreateCmdObjectByType(type);

                if (null != cmd)
                {
                    CommandObjects.Add(cmd);
                }
            }
        }
    }
Esempio n. 2
0
    // handle new command from input box
    void CommandLine(string _Command)
    {
        string Result     = string.Empty;
        string CmdKeyword = string.Empty;

        string Command = _Command.Trim().ToLower();

        string[] Words = Command.Split(' ');

        // use first word as command identifier
        if (Words.Length > 0)
        {
            CmdKeyword = Words[0];

            ConsoleCmdBase Cmd = CommandObjects.FindByName(CmdKeyword);

            if (null != Cmd)
            {
                Result = Cmd.ProceedCommand(Words);
            }
        }

        // output section

        AddLine(">" + Command, "", LineType.Console);

        if (Result != string.Empty)
        {
            AddLine(Result, "", LineType.Console);
        }
        else
        {
            AddLine("Command '" + CmdKeyword + "' not found.", "", LineType.Console);
        }
    }
Esempio n. 3
0
    // @see ConsoleCmdBase.ProceedCommand()
    public override string ProceedCommand(string[] CommandLineWords)
    {
        if (null != CommandLineWords && CommandLineWords.Length > 1)
        {
            ConsoleCmdBase Cmd = Console.CommandObjects.FindByName(CommandLineWords[1]);

            if (null != Cmd)
            {
                return(Cmd.GetHelpString());
            }

            return("Command '" + CommandLineWords[1] + "' does not exist.");
        }

        return(GetHelpString());
    }