Example #1
0
        private static bool ExecuteCommand(CommandContext context, List<string> commandAndArgs)
        {
            if (commandAndArgs.Count == 0)
                return true;

            // Look up the command
            var command = context.GetCommand(commandAndArgs[0]);
            if (command == null)
                return false;

            // Execute it
            commandAndArgs.RemoveAt(0);
            try
            {
                ExecuteCommand(command, commandAndArgs);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.ToString());
            }
            return true;
        }
 /// <summary>
 /// Pushes a context onto the stack, making it active.
 /// </summary>
 /// <param name="context">The context to push.</param>
 public void Push(CommandContext context)
 {
     _contextStack.Push(context);
 }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CommandContext"/> class.
 /// </summary>
 /// <param name="parent">The parent context. Can be <c>null</c> if none.</param>
 /// <param name="name">The context's name.</param>
 public CommandContext(CommandContext parent, string name)
 {
     Parent = parent;
     Name = name;
 }