Commander now shows where the bad command is

This commit is contained in:
Lukasz Baldyga committed 2020-10-25 10:18:50 +00:00
1 parent 72d94cddc6
commit c136093ab3
2 files changed
+18 -17

No files matched your search

@@ -71,6 +71,7 @@
<Compile Include="Verbs\DrawingVerbs\Dot.cs" /> <Compile Include="Verbs\DrawingVerbs\Dot.cs" />
<Compile Include="Verbs\DrawingVerbs\DrawLines.cs" /> <Compile Include="Verbs\DrawingVerbs\DrawLines.cs" />
<Compile Include="Verbs\DrawingVerbs\DrawTo.cs" /> <Compile Include="Verbs\DrawingVerbs\DrawTo.cs" />
<Compile Include="Verbs\DrawingVerbs\FillColor.cs" />
<Compile Include="Verbs\DrawingVerbs\MoveTo.cs" /> <Compile Include="Verbs\DrawingVerbs\MoveTo.cs" />
<Compile Include="Verbs\DrawingVerbs\PenColor.cs" /> <Compile Include="Verbs\DrawingVerbs\PenColor.cs" />
<Compile Include="Verbs\DrawingVerbs\Quadrilateral.cs" /> <Compile Include="Verbs\DrawingVerbs\Quadrilateral.cs" />
@@ -43,42 +43,42 @@ namespace Advanced_Software_Engineering {
} }
public void ProcessCommands(string rawCommands) { public void ProcessCommands(string rawCommands) {
try {
//ignore case //ignore case
rawCommands = rawCommands.ToLower(); rawCommands = rawCommands.ToLower();
Console.WriteLine("Processing:\n" + rawCommands); Console.WriteLine("Processing:\n" + rawCommands);
//remove windows \r if they exist
rawCommands = rawCommands.Replace("\r", "");
//isolate commands //isolate commands
string[] commands = rawCommands.Split(Environment.NewLine.ToCharArray()); string[] commands = rawCommands.Split("\n"[0]);
Console.WriteLine("\nThe rawCommand processed:"); Console.WriteLine("\nThe rawCommand processed:");
int lineNumber = 0;
bool failed = false;
foreach (string rawCommand in commands) { foreach (string rawCommand in commands) {
lineNumber++;
if (rawCommand == "") continue; if (rawCommand == "") continue;
try {
AddCommand(VerbFactory.MakeVerb(drawer, rawCommand)); AddCommand(VerbFactory.MakeVerb(drawer, rawCommand));
Console.WriteLine(rawCommand); Console.WriteLine(rawCommand);
} catch (Exception e) {
Console.WriteLine("Error!");
new ErrorWindow(e.Message, e.Message + " at line " + lineNumber, "While trying to process '" + rawCommand + "' an exception occured.\nMessage:\n" + e.Message + "\nStack Trace:\n" + e.StackTrace, ErrorWindow.ERROR_MESSAGE).Show();
failed = true;
break;
} }
}
if (failed) RemoveAllCommands();
Console.WriteLine("\n\nHere is what the program is going to do:"); Console.WriteLine("\n\nHere is what the program is going to do:");
Console.WriteLine("Set origin to 0, 0"); Console.WriteLine("Set origin to 0, 0");
foreach (Verb verb in this.commands) { foreach (Verb verb in this.commands) {
Console.WriteLine(verb.GetDescription()); Console.WriteLine(verb.GetDescription());
} }
} catch (Exception e) {
Console.WriteLine("Error: Unknown error.");
try {
new ErrorWindow(
"Unexpected error parsing commands",
"The program phraser has encountered an undexpected error." + Environment.NewLine,
e.Message + Environment.NewLine + e.StackTrace,
ErrorWindow.ERROR_MESSAGE
).Show();
} catch (Exception windowError) {
Console.WriteLine("Failed to display error window!");
throw windowError;
}
RemoveAllCommands();
}
} }
public void ProcessCommandsAndExecute(string rawCommands) { public void ProcessCommandsAndExecute(string rawCommands) {