Ejemplo n.º 1
0
        public string getManString(string command)
        {
            // testing purpose
            //return "yummy text";

            if (command == "") command = "man";

            CommandParser cmd2 = new CommandParser(command);
            string cmdString = CommandParser.CmdText[(int)cmd2.getCommandCode()][0];

            const string FILEPATH = "man.xml";
            if (!File.Exists(FILEPATH))
            {
                return "Documentation file missing! \n Use 'add' command to add a task, 'rm' \nto delete and 'ls' to list tasks.";
            }

            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(FILEPATH);
            XmlNodeList xmlNodeList_man = xmlDoc.ChildNodes;
            XmlNodeList xmlNodeList_commands = xmlNodeList_man[0].ChildNodes;

            string man = "";

            foreach (XmlNode x in xmlNodeList_commands)
            {
                    if (x.Name.ToString().Equals(cmdString))
                    {
                        man = x.InnerText.ToString();
                    }
            }
            return man;
        }
Ejemplo n.º 2
0
        public void execute(String cmdStr)
        {
            //parsing the command
            CommandParser cmd = new CommandParser(cmdStr);
            if (cmd.isInvalidCommand())
            {
                sendUpdateStatus("Invalid command: '" + cmdStr + "'");
                return;
            }

            //based on the command code to execute correct functions
            //sendUpdateStatus("Executing the command");
            //tm.broadcastChange();

            int cmdCode = cmd.getCommandCode();
            switch (cmdCode)
            {
                case (int)CommandParser.CmdCode.Add:
                    addTask(cmd.getMainParam(),
                            cmd.getOptionalParam("-t"),
                            cmd.getOptionalParam("-s"),
                            cmd.getOptionalParam("-d"));
                    break;

                case (int)CommandParser.CmdCode.Remove:
                    removeTask(cmd.getMainParam());
                    break;

                case (int)CommandParser.CmdCode.Edit:
                    if (cmd.noFlag())
                    {
                        sendUpdateStatus("Edit must have a flag");
                        break;
                    }
                    editTask(cmd.getMainParam(), "name", cmd.getOptionalParam("-n"));
                    editTask(cmd.getMainParam(), "deadline", cmd.getOptionalParam("-t"));
                    editTask(cmd.getMainParam(), "star", cmd.getOptionalParam("-s"));
                    editTask(cmd.getMainParam(), "description", cmd.getOptionalParam("-d"));
                    break;

                case (int)CommandParser.CmdCode.Ls:
                    displayTask();
                    break;

                case (int)CommandParser.CmdCode.Man:
                    manUpdate(getManString(cmd.getMainParam()));
                    sendUpdateStatus("Executing MAN");
                    break;

                // hmm i think the exit command shouldn't be handled by api
                // because it's closing the application, which is out of the scope of the api
                // ex: what happend if it's a textUI thing that doesn't have Application..Exit like WPF
                // i add it as a special handling in commandLine_keyup
                case (int)CommandParser.CmdCode.Exit:
                    sendUpdateStatus("Executing Exit");
                    break;

                case (int)CommandParser.CmdCode.TextView:
                    sendViewChange("TextUI");
                    tm.refreshDisplay();
                    break;

                case (int)CommandParser.CmdCode.GUIView:
                    sendViewChange("GUI");
                    tm.refreshDisplay();
                    break;

                case (int)CommandParser.CmdCode.Undo:
                    if (tm.revert() == 0)
                    {
                        sendUpdateStatus("Revert successfully");
                    }
                    else
                    {
                        sendUpdateStatus("At the last change");
                    }
                    break;
                case (int)CommandParser.CmdCode.Done:
                    if (cmd.getMainParam() == "")
                        tm.listDoneTasks();
                    else
                        doneTask(cmd.getMainParam(), true);
                    break;
                case (int)CommandParser.CmdCode.Star:
                    if (cmd.getMainParam() == "")
                        tm.listStarTasks();
                    else
                        editTask(cmd.getMainParam(), "star", "True");
                    break;
                case (int)CommandParser.CmdCode.Show:
                    showTask(cmd.getMainParam());
                    break;
            }
        }