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
+30 -29

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);
//isolate commands //remove windows \r if they exist
string[] commands = rawCommands.Split(Environment.NewLine.ToCharArray()); rawCommands = rawCommands.Replace("\r", "");
Console.WriteLine("\nThe rawCommand processed:"); //isolate commands
foreach (string rawCommand in commands) { string[] commands = rawCommands.Split("\n"[0]);
if (rawCommand == "") continue;
AddCommand(VerbFactory.MakeVerb(drawer, rawCommand));
Console.WriteLine(rawCommand);
}
Console.WriteLine("\n\nHere is what the program is going to do:"); Console.WriteLine("\nThe rawCommand processed:");
Console.WriteLine("Set origin to 0, 0"); int lineNumber = 0;
foreach (Verb verb in this.commands) { bool failed = false;
Console.WriteLine(verb.GetDescription()); foreach (string rawCommand in commands) {
} lineNumber++;
} catch (Exception e) { if (rawCommand == "") continue;
Console.WriteLine("Error: Unknown error.");
try { try {
new ErrorWindow( AddCommand(VerbFactory.MakeVerb(drawer, rawCommand));
"Unexpected error parsing commands", Console.WriteLine(rawCommand);
"The program phraser has encountered an undexpected error." + Environment.NewLine, } catch (Exception e) {
e.Message + Environment.NewLine + e.StackTrace, Console.WriteLine("Error!");
ErrorWindow.ERROR_MESSAGE 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();
).Show(); failed = true;
} catch (Exception windowError) { break;
Console.WriteLine("Failed to display error window!");
throw windowError;
} }
RemoveAllCommands();
} }
if (failed) RemoveAllCommands();
Console.WriteLine("\n\nHere is what the program is going to do:");
Console.WriteLine("Set origin to 0, 0");
foreach (Verb verb in this.commands) {
Console.WriteLine(verb.GetDescription());
}
} }
public void ProcessCommandsAndExecute(string rawCommands) { public void ProcessCommandsAndExecute(string rawCommands) {