From 0fd02dd9aca97a8f96e4e3eb1b25a307c5c4405d Mon Sep 17 00:00:00 2001 From: Brychan Dempsey Date: Wed, 24 Mar 2021 12:50:33 +1300 Subject: [PATCH] Swapped order of printwords and printwordcount, (Closes #8) --- Assignment 1/Program.cs | 22 ++++++++++----------- Assignment 1/Properties/launchSettings.json | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/Assignment 1/Program.cs b/Assignment 1/Program.cs index f7afa91..f7e0cb1 100644 --- a/Assignment 1/Program.cs +++ b/Assignment 1/Program.cs @@ -87,10 +87,10 @@ namespace Assignment_1 Environment.Exit(0); } ConsoleKeyInfo ck = new(); - while (ck.Key != ConsoleKey.Y || ck.Key != ConsoleKey.N) + while (ck.Key != ConsoleKey.Y && ck.Key != ConsoleKey.N) { - Console.WriteLine("\nWould you like to parse more programs? Y/n:"); - ck = Console.ReadKey(); + Console.WriteLine("\nWould you like to parse another program? Y/n:"); + ck = Console.ReadKey(true); } if (ck.Key == ConsoleKey.N) { @@ -100,10 +100,10 @@ namespace Assignment_1 { // Need the logic to prep the next source stream ck = new(); - while (ck.Key != ConsoleKey.Y || ck.Key != ConsoleKey.N) + while (ck.Key != ConsoleKey.Y && ck.Key != ConsoleKey.N) { Console.WriteLine("\nWould you like to pipe data from source file? Y/n:"); - ck = Console.ReadKey(); + ck = Console.ReadKey(true); } if (ck.Key == ConsoleKey.N) { @@ -127,8 +127,6 @@ namespace Assignment_1 } } } - // GC already done, just loop back to program start - } } @@ -209,7 +207,7 @@ namespace Assignment_1 switch ((Statements)statementType) { case Statements.exit: - result = Exit(source, initSourceLength); + result = Exit(source, initSourceLength, dynamicInput); break; case Statements.append: result = AppendSet(source); @@ -232,10 +230,10 @@ namespace Assignment_1 case Statements.printlength: result = Print(source, 1); break; - case Statements.printwordcount: + case Statements.printwords: result = Print(source, 2); break; - case Statements.printwords: + case Statements.printwordcount: result = Print(source, 3); break; case Statements.set: @@ -445,11 +443,11 @@ namespace Assignment_1 return () => Console.WriteLine(consoleOutput.ToString()); } - Action Exit(Stream source, long initialStreamLength) + Action Exit(Stream source, long initialStreamLength, bool isDynamicInput=false) { Action exitAction = () => { - if (source.Length != initialStreamLength) + if (source.Length != initialStreamLength && isDynamicInput) { Console.WriteLine("Commands list has been modified; would you like to save it to a file?"); string commandState = ""; diff --git a/Assignment 1/Properties/launchSettings.json b/Assignment 1/Properties/launchSettings.json index 9f75985..2c1322f 100644 --- a/Assignment 1/Properties/launchSettings.json +++ b/Assignment 1/Properties/launchSettings.json @@ -6,7 +6,7 @@ "newProfile1": { "commandName": "Executable", "executablePath": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", - "commandLineArgs": "-command \"& type .\\outtest.txt | & '.\\Assignment 1.exe'\"" + "commandLineArgs": "-command \"& type .\\ExampleOutput.txt | & '.\\Assignment 1.exe'\"" } } } \ No newline at end of file