예제 #1
0
        private static void AddCommand(string CommandName, byte ArgumentCount, string CommandHelp, TCALLBACKCommandProc CommandProc)
        {
            if (!String.IsNullOrEmpty(CommandName))
            {
                string[] CommandWithParameters = Tokenize(CommandName);
                CommandName = CommandWithParameters[0];

                if (!Commands.ContainsKey(CommandName))
                {
                    CommandNode Node = new CommandNode();

                    Node.Name        = CommandName;
                    Node.ParamCount  = ArgumentCount;
                    Node.Help        = CommandHelp;
                    Node.CommandProc = CommandProc;

                    Commands.Add(CommandName, Node);
                }
            }
        }
예제 #2
0
        public static void ExecuteCommand(string CommandLine)
        {
            CommandLine = CommandStandardization(CommandLine);

            if (!String.IsNullOrEmpty(CommandLine))
            {
                string[] CommandWithParameters = Tokenize(CommandLine);
                string   CommandName           = CommandWithParameters[0];
                string[] Parameters            = null;

                // If the command with its parameters presents
                if (CommandWithParameters.Length > 1)
                {
                    Parameters = new string[CommandWithParameters.Length - 1];

                    for (ushort Counter = 1; Counter < CommandWithParameters.Length; Counter++)
                    {
                        Parameters[Counter - 1] = CommandWithParameters[Counter];
                    }
                }

                if (Commands.ContainsKey(CommandName))
                {
                    CommandNode Node = Commands[CommandName];

                    if (Node.CommandProc != null)
                    {
                        Node.CommandProc(Parameters);
                    }
                    else
                    {
                        ConsoleManager.WriteLine("Error! Command delegate not defined!");
                    }
                }
                else
                {
                    ConsoleManager.WriteLine("Error! Invalid command!");
                }
            }
        }