public static void Execute() { while (true) { Execute(Console.ReadLine()); ConsoleHandler.ClearCommand(); Thread.Yield(); // Other threads should be able to run after each command } }
// Used to check if position information is required public static void UpdatePositionInformation() { Graph g = Database.Instance.Data.Graphs.FirstOrDefault().Value; Forklift f = Database.Instance.Data.Forklifts.FirstOrDefault().Value; if (f.RearNode == null || f.FrontNode == null) { ConsoleHandler.AddMessage(MessageType.REGULAR, "Information about PALL-E position is required."); bool result; do { Node rearNode = null; Node frontNode = null; // The user must enter a faceing node while (frontNode == null) { try { ConsoleHandler.AddMessage(MessageType.REGULAR, "Enter name of front node..."); String faceing = Console.ReadLine(); ConsoleHandler.ClearCommand(); frontNode = g.getNode(faceing); } catch (NodeException e) { ConsoleHandler.AddMessage(MessageType.ERROR, "Error when finding node: '" + e.Message + "'"); } } // The user must enter a last node while (rearNode == null) { try { ConsoleHandler.AddMessage(MessageType.REGULAR, "Enter name of rear node..."); String last = Console.ReadLine(); ConsoleHandler.ClearCommand(); rearNode = g.getNode(last); } catch (NodeException e) { ConsoleHandler.AddMessage(MessageType.ERROR, "Error when finding node: '" + e.Message + "'"); } } // Update node information result = f.UpdateNodes(frontNode, rearNode); Commands.PrintSuccess("Position updated"); Commands.Position(); }while (!result); } else { ConsoleHandler.AddMessage(MessageType.REGULAR, ConsoleHandler.DNS + " position information:"); ConsoleHandler.AddMessage(MessageType.REGULAR, "Front-node: '" + f.FrontNode.Name + "'. Rear-node: '" + f.RearNode.Name + "'"); } }
private static void Execute(string command) { command = command.ToLower(); // No command provided, user must need help if (String.IsNullOrEmpty(command)) { PrintInvalidCommand(); return; } // Split the string into command and arguments List <String> commandAndArguments = command.Split('-').ToList(); // No command provided, user must need help if (String.IsNullOrEmpty(commandAndArguments[0])) { PrintInvalidCommand(); return; } // Split the command at every space List <string> commandSplit = commandAndArguments[0].Split(' ').ToList(); // Remove empty commands (occours when multiple spaces are entered) commandSplit.RemoveAll(s => s == ""); // Save the first part of the command string commandIdentifier = commandSplit[0]; // Remove the first part of the command commandSplit.RemoveAt(0); int arguments = commandSplit.Count; commandSplit.RemoveAll(s => s == ""); // Check if the command argument is "clear" List <String> argumentList = commandAndArguments.Skip(1).ToList(); // Trim all command arguments for (int i = 0; i < argumentList.Count; i++) { argumentList[i] = argumentList[i].Trim(); } // Check if an argument is to clear the display if (argumentList.Contains(COMMAND_ARGUMENT_CLEAR)) { argumentList.RemoveAll(x => x == COMMAND_ARGUMENT_CLEAR); Clear(); } // Check if there are unprocessed arguments if (argumentList.Count > 0) { String error = "Unknown command arguments: "; foreach (string s in argumentList) { if (s != argumentList.FirstOrDefault()) { error += ", "; } error += "'" + s + "'"; } error += "\n"; ConsoleHandler.AddMessage(MessageType.ERROR, error); return; } // Check if the command is "help" if (commandIdentifier == HELP) { if (arguments == 0) { Help(); } else { PrintIncorrectUse(); HelpHelp(); } } else if (commandIdentifier == COMMAND_STATUS) { if (arguments == 0) { Status(); } else { PrintIncorrectUse(); StatusHelp(); } } // Check if the command is "joblist" else if (commandIdentifier == COMMAND_JOBLIST) { if (arguments == 0) { Joblist(); } else if (arguments == 1) { Joblist(commandSplit[0]); } else if (arguments == 2) { Joblist(commandSplit[0], commandSplit[1]); } else { PrintIncorrectUse(); JoblistHelp(); } } else if (commandIdentifier == COMMAND_CURRENTJOB) { if (arguments == 0) { CurrentJob(); } else { PrintIncorrectUse(); CurrentJobHelp(); } } // Check if the command is "deliver", "fetch" or "navigate" else if (commandIdentifier == COMMAND_FETCH) { if (arguments == 2) { if (commandSplit[0] == "node") { FetchNode(commandSplit[1]); } else if (commandSplit[0] == "pallet") { FetchPallet(commandSplit[1]); } else { PrintIncorrectUse(); FetchNodeHelp(); FetchPalletHelp(); } } else { PrintIncorrectUse(); FetchNodeHelp(); FetchPalletHelp(); } } else if (commandIdentifier == COMMAND_DELIVER || commandIdentifier == COMMAND_NAVIGATE) { if (arguments == 1) { DeliverNavigate(commandIdentifier, commandSplit[0]); } else { PrintIncorrectUse(); DeliverNavigateHelp(); } } else if (commandIdentifier == COMMAND_DEBUG) { if (arguments == 1) { Debug(commandSplit[0]); } } else if (commandIdentifier == COMMAND_POSITION) { if (arguments == 0) { Position(); } else if (arguments == 2) { Position(commandSplit[0], commandSplit[1]); } else { PrintIncorrectUse(); PositionHelp(); } } else if (commandIdentifier == COMMAND_CLEAR) { if (arguments == 0) { Clear(); } else { PrintIncorrectUse(); ClearHelp(); } } else if (commandIdentifier == COMMAND_PALLETLIST) { if (arguments == 0) { Palletlist(); } else if (arguments == 1) { Palletlist(commandSplit[0]); } else if (arguments == 2) { Palletlist(commandSplit[0], commandSplit[1]); } else if (arguments == 3) { Palletlist(commandSplit[0], commandSplit[1], commandSplit[2]); } else { PrintIncorrectUse(); PalletlistHelp(); } } else if (commandIdentifier == COMMAND_PAYLOAD) { if (arguments == 0) { Payload(); } else if (arguments == 1) { Payload(commandSplit[0]); } else { PrintIncorrectUse(); PayloadHelp(); } } else if (commandIdentifier == COMMAND_NODE) { if (arguments == 1) { Node(commandSplit[0]); } else { NodeHelp(); } } else if (commandIdentifier == COMMAND_UNBLOCK) { if (arguments == 2) { Unblock(commandSplit[0], commandSplit[1]); } else if (arguments == 1) { Unblock(commandSplit[0]); } else { UnblockHelp(); } } else if (commandIdentifier == COMMAND_RELOAD) { if (arguments == 0) { Reload(); } else { PrintIncorrectUse(); ReloadHelp(); } } else if (commandIdentifier == COMMAND_SAVE) { if (arguments == 0) { Save(); } else { PrintIncorrectUse(); SaveHelp(); } } else if (commandIdentifier == COMMAND_EXIT) { if (arguments == 0) { Exit(); } else { PrintIncorrectUse(); ExitHelp(); } } // Some unknown command, show the help else { PrintInvalidCommand(); } ConsoleHandler.ClearCommand(); }