Esempio n. 1
0
        /// <exception cref="InvalidOperationException">Cannot add commands to the root node.</exception>
        public void AddCommand(CommandService service, string text, int index, CommandInfo command)
        {
            int    nextSegment = NextSegment(text, index, service._separatorChar);
            string name;

            lock (_lockObj)
            {
                if (text == "")
                {
                    if (_name == "")
                    {
                        throw new InvalidOperationException("Cannot add commands to the root node.");
                    }
                    _commands = _commands.Add(command);
                }
                else
                {
                    if (nextSegment == -1)
                    {
                        name = text.Substring(index);
                    }
                    else
                    {
                        name = text.Substring(index, nextSegment - index);
                    }

                    string         fullName = _name == "" ? name : _name + service._separatorChar + name;
                    CommandMapNode nextNode = _nodes.GetOrAdd(name, x => new CommandMapNode(fullName));
                    nextNode.AddCommand(service, nextSegment == -1 ? "" : text, nextSegment + 1, command);
                }
            }
        }
Esempio n. 2
0
 public CommandMap(CommandService service)
 {
     _service = service;
     _root    = new CommandMapNode("");
 }