예제 #1
0
        // Important method because additional commands can be supported by including new subclasses of CanvasCommand
        public string GetUsage(string newLineChar)
        {
            StringBuilder usageString = new StringBuilder("");

            foreach (char key in _commandList.Keys)
            {
                CanvasCommand canvasCommand = _commandList[key];
                usageString.Append(newLineChar + canvasCommand.Usage);
            }

            return(usageString.ToString());
        }
예제 #2
0
        // Looks for all Classes in the current assembly which inherit from CanvasCommand, instantiates them and adds them to the list of supported commands
        public void LoadSupportedCommands()
        {
            Assembly assembly = Assembly.GetExecutingAssembly();

            foreach (Type type in assembly.GetTypes())
            {
                if (type.IsSubclassOf(typeof(CanvasCommand)))
                {
                    CanvasCommand canvasCommand = (CanvasCommand)Activator.CreateInstance(type);
                    canvasCommand.SetCanvas(this);
                    _commandList.Add(canvasCommand.SupportedCommand, canvasCommand);
                }
            }
        }
예제 #3
0
        public void ExecuteCommand(string fullCommand)
        {
            char mainCommand = char.ToUpper(fullCommand.First <char>());

            if (_commandList.ContainsKey(mainCommand))
            {
                CanvasCommand canvasCommand = _commandList[mainCommand];

                canvasCommand.ProcessCommand(fullCommand);
            }
            else
            {
                throw new CommandException(fullCommand + " is an unrecognised command.");
            }
        }