public void ExecuteCommand(CommandString cmdStr) { Program prog; string param = cmdStr.parameters.Dequeue(); int index; switch (cmdStr.command) { case ShellCommand.List: allPrograms.ForEach(delegate(Program p) { term.ReportLine(p.Name); }); term.ReportLine("...found " + allPrograms.Count + " programs."); break; case ShellCommand.Clear: term.Clear(); break; case ShellCommand.Promote: prog = allPrograms.Find(m => m.Name.Equals(param)); if (prog == null) { term.ReportLine("Error: Program " + param + " not found."); break; } index = allPrograms.IndexOf(prog); if (index > 0) { allPrograms.RemoveAt(index); allPrograms.Insert(index - 1, prog); } term.ReportLine("Program " + param + " has been promoted in the run order."); break; case ShellCommand.Demote: prog = allPrograms.Find(m => m.Name.Equals(param)); if (prog == null) { term.ReportLine("Error: Program " + param + " not found."); break; } int index1 = allPrograms.IndexOf(prog); if (index1 < allPrograms.Count-1) { allPrograms.RemoveAt(index1); allPrograms.Insert(index1+1, prog); } term.ReportLine("Program " + param + " has been demoted in the run order."); break; case ShellCommand.Edit: prog = allPrograms.Find(m => m.Name.Equals(param)); if (prog == null) { prog = new Program(param, new List<string>()); allPrograms.Add(prog); } this.EditProgram = prog; this.editMode = true; term.ReportLine("Editting Program: " + param + " (Press F1 to Save and Quit)"); term.ReportLine("Note: Maximum buffer size is 256 characters."); term.ReportLine("-----------------------------------------------------------"); foreach (string s in EditProgram.Buffer) { term.WriteLine(s); } break; case ShellCommand.Registers: string[] regs = term.Registers.ToArray(); for (int i=0; i<regs.Length; i+=5) { string s = String.Format("|{0,10}{1,10}{2,10}{3,10}{4,10}|", (i) + ":" + regs[i].ToString(), (i+1) + ":" + regs[i + 1].ToString(), (i+2) + ":" + regs[i + 2].ToString(), (i+3) + ":" + regs[i + 3].ToString(), (i+4) + ":" + regs[i + 4].ToString()); term.ReportLine(s); } break; case ShellCommand.Help: ShellCommand sc = ShellCommand.None; try { param = cmdStr.parameters.Dequeue(); } catch { param = String.Empty; } try { sc = (ShellCommand) Enum.Parse(typeof(ShellCommand), param, true); } catch { } //term.ReportLine(param); term.ReportLine(GetHelpText(sc)); break; case ShellCommand.Delete: prog = allPrograms.Find(pr => pr.Name.Equals(param)); if (prog == null) term.ReportLine("Error: Program " + param + " does not exist."); else { allPrograms.Remove(prog); term.ReportLine("Program " + prog.Name + " successfully deleted."); } break; case ShellCommand.Log: term.Clear(); term.ReportLine("Program Execution Log"); term.ReportLine(programLog.ToString()); break; case ShellCommand.Notes: break; } }
public void ParseCommand(string cmdStr) { string[] fields = cmdStr.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries); CommandString cs = new CommandString(ShellCommand.None, new List<string>()); term.Clear(); if (fields.Length == 0) { term.ReportWrite("No command specified. Please enter a valid command!"); return; } else try { switch (fields[0].ToUpperInvariant()) { case "LIST": cs = new CommandString(ShellCommand.List, fields); break; case "CLEAR": cs = new CommandString(ShellCommand.Clear, fields); break; case "EDIT": if (fields.Length < 2) throw new ArgumentNullException(); else cs = new CommandString(ShellCommand.Edit, fields.Skip(1)); break; case "PROMOTE": if (fields.Length < 2) throw new ArgumentNullException(); cs = new CommandString(ShellCommand.Promote, fields.Skip(1)); break; case "DEMOTE": if (fields.Length < 2) throw new ArgumentNullException(); cs = new CommandString(ShellCommand.Demote, fields.Skip(1)); break; case "DELETE": if (fields.Length < 2) throw new ArgumentNullException(); cs = new CommandString(ShellCommand.Delete, fields.Skip(1)); break; case "REGISTERS": cs = new CommandString(ShellCommand.Registers, fields); break; case "LOG": cs = new CommandString(ShellCommand.Log, fields); break; case "NOTES": cs = new CommandString(ShellCommand.None, fields); return; case "HELP": cs = new CommandString(ShellCommand.Help, fields); break; case "LDTDBADD": demo.DebugMode.oBoard.DebugAdder(); return; case "LDTDBSUB": demo.DebugMode.oBoard.DebugSubtractor(); return; case "LDTDBVENT": demo.DebugMode.vBoard.DebugThermostat(); return; default: term.ReportLine("Error: " + fields[0] + " is not a valid command. Try HELP for PAL assistance."); return; } } catch (ArgumentNullException e) { term.ReportLine("Error: Invalid parameters or command syntax."); return; } ExecuteCommand(cs); }