示例#1
0
        public void Execute(Query query)
        {
            if (PrintExecutedCommand)
            {
                OnMessage.Invoke(new Message(EMessageType.Execution, query.RawQuery));
            }
            AConsoleCommand command = FindCommand(query.Name.Value);

            if (command == null)
            {
                OnMessage.Invoke(new Message(EMessageType.Error, Localization.Get(ELocKey.LogicCommandNotFound, query.Name.Value)));
                return;
            }
            CommandMethod method = command.Method;

            if (MapQuery(method, query) && ParseQueryValues(query))
            {
                if (Locked && command.ObeyLock)
                {
                    OnMessage.Invoke(new Message(EMessageType.Warning, Localization.Get(ELocKey.LogicConsoleLocked)));
                    return;
                }

                object[] parsed = query.GetParsedValues();
                Message  result = command.Execute(parsed);
                if (result != null)
                {
                    OnMessage.Invoke(result);
                }
            }
        }
示例#2
0
        private IEnumerator ProcessNextQuery()
        {
            Query query = m_CurrentQueries.Pop();

            if (PrintExecutedCommand && !query.IsOption)
            {
                OnMessage.Invoke(new Message(EMessageType.Execution, query.RawQuery));
            }
            AConsoleCommand command = FindCommand(query.Name.Value);

            if (command == null)
            {
                OnMessage.Invoke(new Message(EMessageType.Error, Localization.Get(ELocKey.LogicCommandNotFound, query.Name.Value)));
                return(null);
            }
            CommandMethod method = command.Method;

            if (MapQuery(method, query) && ParseQueryValues(query))
            {
                if (Locked && command.ObeyLock)
                {
                    OnMessage.Invoke(new Message(EMessageType.Warning, Localization.Get(ELocKey.LogicConsoleLocked)));
                    return(null);
                }

                object[] parsed = query.GetParsedValues();
                object   result = command.Execute(parsed);

                m_CurrentEnumerator = result as IEnumerator;
                if (m_CurrentEnumerator != null)
                {
                    return(m_CurrentEnumerator);
                }

                Message message = result as Message;
                if (message != null)
                {
                    OnMessage.Invoke(message);
                }
            }
            return(null);
        }
示例#3
0
        public static CommandMethod CreateCommandMethod(MethodInfo info)
        {
            if (info == null)
            {
                throw new ArgumentNullException();
            }
            if (info.ReturnType != typeof(Message))
            {
                throw new IncorrectReturnTypeException(info, info.ReturnType);
            }
            CommandMethod method = new CommandMethod(info);

            CommandParameter[] parameters = ParseParameters(info);
            method.ClearParameters();
            for (int x = 0; x < parameters.Length; x++)
            {
                method.AddParameter(parameters[x]);
            }
            return(method);
        }
示例#4
0
 private bool MapQuery(CommandMethod method, Query query)
 {
     try
     {
         method.MapArguments(query);
     }
     catch (NotEnoughtArgumentsException e)
     {
         OnMessage.Invoke(new Message(EMessageType.Error, Localization.Get(e)));
         return(false);
     }
     catch (NamedArgumentNotFoundException e)
     {
         OnMessage.Invoke(new Message(EMessageType.Error, Localization.Get(e)));
         return(false);
     }
     catch (TooManyArgumentsException e)
     {
         OnMessage.Invoke(new Message(EMessageType.Error, Localization.Get(e)));
         return(false);
     }
     return(true);
 }