示例#1
0
        public CommandResult Submit(string command, string args)
        {
            if (command.StartsWith("?"))
            {
                if (!commandList.ContainsKey(command.Substring(1)))
                {
                    return new CommandResult()
                           {
                               ResultTypes = ResultType.NONE
                           }
                }
                ;
                try
                {
                    MethodInfo m = commandList[command.Substring(1)];

                    Attribute[] attrs = m.GetCustomAttributes(Type.GetType("Philosophical_Artificial_Intelligence.CMD"), false) as Attribute[];
                    if (attrs == null || attrs.Length == 0)
                    {
                        return new CommandResult()
                               {
                                   ResultTypes = ResultType.NONE
                               }
                    }
                    ;
                    CMD info = new CMD();

                    for (int i = 0; i < attrs.Length; i++)
                    {
                        if (attrs[i] is CMD)
                        {
                            info = attrs[i] as CMD;
                        }
                    }

                    return(new CommandResult()
                    {
                        ResultTypes = ResultType.INFORMATION, Result = info.Help + "\r\n"
                    });
                }
                catch (MissingMethodException)
                {
                    return(new CommandResult()
                    {
                        ResultTypes = ResultType.ERROR, Result = "ERROR : Wrong Method\r\n"
                    });
                }
                catch (TargetParameterCountException)
                {
                    return(new CommandResult()
                    {
                        ResultTypes = ResultType.ERROR, Result = "ERROR : Wrong Parameters\r\n"
                    });
                }
            }
            else
            {
                if (!commandList.ContainsKey(command))
                {
                    return new CommandResult()
                           {
                               ResultTypes = ResultType.NONE
                           }
                }
                ;
                try
                {
                    MethodInfo m = commandList[command];

                    ParameterInfo[] infos = m.GetParameters();

                    object parameters = Activator.CreateInstance(Type.GetType("Philosophical_Artificial_Intelligence.Command"));

                    return(string.IsNullOrWhiteSpace(args) ? (CommandResult)(m.Invoke(parameters, new object[] {})) : (CommandResult)(m.Invoke(parameters, new object[] { args })));
                }
                catch (MissingMethodException)
                {
                    return(new CommandResult()
                    {
                        ResultTypes = ResultType.ERROR, Result = "ERROR : Wrong Method\r\n"
                    });
                }
                catch (TargetParameterCountException)
                {
                    return(new CommandResult()
                    {
                        ResultTypes = ResultType.ERROR, Result = "ERROR : Wrong Parameters\r\n"
                    });
                }
            }
        }