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); } } }
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); }
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); }
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); }