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);
                }
            }
        }
 public void Execute(List <Query> queries)
 {
     for (int x = 0; x < queries.Count; x++)
     {
         Query query = queries[x];
         if (!query.IsOption && (x == queries.Count - 1 || !queries[x + 1].IsOption))
         {
             ExecuteStack(ExecutionStack.Count > 1);
         }
         if (query.IsOption)
         {
             if (ExecutionStack.Count == 0)
             {
                 OnMessage.Invoke(new Message(EMessageType.Error, Localization.Get(ELocKey.LogicOptionWithoutCommand)));
                 return;
             }
             else
             {
                 AConsoleCommand option  = query.GetCommand(this);
                 AConsoleCommand command = ExecutionStack[0].GetCommand(this);
                 if (!command.IsOptionValid(option.GetType()))
                 {
                     string message = Localization.Get(ELocKey.LogicOptionInvalid, option.Name, command.Name);
                     OnMessage.Invoke(new Message(EMessageType.Error, message));
                     return;
                 }
             }
         }
         ExecutionStack.Add(query);
     }
     ExecuteStack(ExecutionStack.Count > 1);
     ExecutionStack.Clear();
 }
 public void AddCommonOption(AConsoleCommand command)
 {
     if (command == null || !command.IsOption)
     {
         throw new ArgumentException();
     }
     m_DefaultOptions.Add(command);
 }
 private int IndexOfCommand(string name)
 {
     for (int x = 0; x < m_Commands.Count; x++)
     {
         AConsoleCommand command = m_Commands[x];
         if (command.Name.Equals(name, StringComparison.OrdinalIgnoreCase))
         {
             return(x);
         }
     }
     return(-1);
 }
Exemple #5
0
        protected override string[] GetAllOptions()
        {
            List <string> options = new List <string>(m_Commands.Count);

            for (int x = 0; x < m_Commands.Count; x++)
            {
                AConsoleCommand command = m_Commands[x];
                if (command.IsValid && command.IsOption == m_IsOption)
                {
                    options.Add(command.Name);
                }
            }

            return(options.ToArray());
        }
Exemple #6
0
        public Message Command(EListMode mode = EListMode.Commands)
        {
            string list = "";
            IEnumerator <AConsoleCommand> commands = Console.GetCommandEnumerator();

            while (commands.MoveNext())
            {
                AConsoleCommand command = commands.Current;
                bool            isMacro = command is MacroPlayerCommand;
                switch (mode)
                {
                case EListMode.Commands:
                    if (!command.IsOption && !isMacro)
                    {
                        list += command.Name + ", ";
                    }
                    break;

                case EListMode.Options:
                    if (command.IsOption)
                    {
                        list += command.Name + ", ";
                    }
                    break;

                case EListMode.Macro:
                    if (isMacro)
                    {
                        list += command.Name + ", ";
                    }
                    break;

                case EListMode.All:
                    if (command.IsOption)
                    {
                        list += ParserConst.OPTION + command.Name + ", ";
                    }
                    else
                    {
                        list += command.Name + ", ";
                    }
                    break;
                }
            }

            return(new Message(EMessageType.Normal, list));
        }
        private void HandleQueries(List <Query> queries)
        {
            bool          processingOptions = false;
            Stack <Query> batch             = new Stack <Query>();

            for (int x = 0; x < queries.Count; x++)
            {
                Query query = queries[x];
                if (processingOptions && !query.IsOption)
                {
                    m_PendingBatches.Enqueue(batch);
                    batch = new Stack <Query>();
                }
                processingOptions = query.IsOption;

                if (processingOptions)
                {
                    if (batch.Count == 0)
                    {
                        OnMessage.Invoke(new Message(EMessageType.Error, Localization.Get(ELocKey.LogicOptionWithoutCommand)));
                        return;
                    }
                    else
                    {
                        AConsoleCommand option  = query.GetCommand(this);
                        AConsoleCommand command = batch.Peek().GetCommand(this);
                        if (command == null)
                        {
                            OnMessage.Invoke(new Message(EMessageType.Error, Localization.Get(ELocKey.LogicCommandNotFound, query.Name.Value)));
                        }
                        else if (!command.IsOptionValid(option.GetType()))
                        {
                            string message = Localization.Get(ELocKey.LogicOptionInvalid, option.Name, command.Name);
                            OnMessage.Invoke(new Message(EMessageType.Error, message));
                            return;
                        }
                    }
                }
                batch.Push(query);
            }
            if (batch.Count > 0)
            {
                m_PendingBatches.Enqueue(batch);
            }
        }
Exemple #8
0
 private AHint GetHint(AConsoleCommand command, Query query, Argument argument)
 {
     if (argument != null)
     {
         if (argument.Parameter != null)
         {
             return(command.GetHintFor(m_HintsManager, argument.Parameter.Index));
         }
         else if (argument.IsCommandName)
         {
             return(query.IsOption ? m_Console.OptionHint : m_Console.NameHint);
         }
     }
     else
     {
         return(m_Console.NameHint);
     }
     return(null);
 }
        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 void AddCommand(AConsoleCommand command)
        {
            AConsoleCommand existing = FindCommand(command.Name);

            if (existing != null)
            {
                throw new DuplicatedCommandException(existing, command);
            }
            if (command.Method == null)
            {
                command.ParseMethod();
            }
            m_Commands.Add(command);
            NameHint.InvalidateCache();
            OptionHint.InvalidateCache();

            for (int x = 0; x < m_DefaultOptions.Count; x++)
            {
                command.AddValidOption(m_DefaultOptions[x].GetType());
            }
        }
Exemple #11
0
 private void MapAndParseQuery(AConsoleCommand command, Query query, List <ConsoleException> issues)
 {
     if (command != null)
     {
         try
         {
             command.Method.MapArguments(query);
         }
         catch (ConsoleException e)
         {
             issues.Add(e);
         }
         try
         {
             m_Console.ParseValues(query);
         }
         catch (ConsoleException e)
         {
             issues.Add(e);
         }
     }
 }
Exemple #12
0
        public AHintIterator GetHintIterator(string input, int cursor, List <ConsoleException> issues = null)
        {
            List <Query> queries;

            try
            {
                queries = m_Console.ParseQuery(input);
            }
            catch (ConsoleException e)
            {
                queries = new List <Query>();
                issues.Add(e);
            }

            Query           query    = null;
            Argument        argument = null;
            AConsoleCommand command  = null;

            FindQueryAndArgument(queries, cursor, out query, out argument);

            if (query != null)
            {
                command = m_Console.FindCommand(query.Name.Value);
                MapAndParseQuery(command, query, issues);
            }

            AHint hint = GetHint(command, query, argument);

            if (hint != null)
            {
                if (argument == null)
                {
                    argument = new Argument(true);
                }
                return(hint.GetIterator(query, argument));
            }

            return(null);
        }
 private int IndexOfCommand(AConsoleCommand command)
 {
     return(IndexOfCommand(command.Name));
 }
 public bool RemoveCommand(AConsoleCommand command)
 {
     return(RemoveCommand(command.Name));
 }
Exemple #15
0
        private bool CanUseName(string name)
        {
            AConsoleCommand command = Console.FindCommand(name);

            return(command == null || (command is MacroPlayerCommand));
        }