internal void CompareFiles(string userOutputPath, string expectedOutputPath) { string userOutputFile = IOManager.ExtractFileName(userOutputPath); userOutputPath = IOManager.BuildAbsolutePath(userOutputPath); string userOutputFilePath = $"{userOutputPath}\\{userOutputFile}"; string expectedOutputFile = IOManager.ExtractFileName(expectedOutputPath); expectedOutputPath = IOManager.BuildAbsolutePath(expectedOutputPath); string expectedOutputFilePath = $"{expectedOutputPath}\\{expectedOutputFile}"; var fileReadingFeedback = new FileReadingFeedback(); IOManager.OutputLine(typeof(Feedback), fileReadingFeedback.BeginMessage); try { var fileComparisonFeedback = new FileComparisonFeedback(); string[] actualOutput = File.ReadAllLines(userOutputFilePath); string[] expectedOutput = File.ReadAllLines(expectedOutputFilePath); IOManager.OutputLine(typeof(Feedback), fileReadingFeedback.ProgressMessage); bool hasMismatch; string[] comparisonResults = Compare(actualOutput, expectedOutput, out hasMismatch); if (hasMismatch) { string mismatchesFilePath = $"{expectedOutputPath}\\mismatches.txt"; FSManager.CreateFile(mismatchesFilePath, comparisonResults); string[] mismatches = FSManager.ReadFile(mismatchesFilePath); IOManager.OutputLine(typeof(Feedback), fileComparisonFeedback.ProgressMessage); IOManager.DisplayFileContents(mismatches); IOManager.OutputLine(typeof(Feedback), String.Format( fileComparisonFeedback.ResultMessage, mismatchesFilePath)); } else if (comparisonResults != null) { IOManager.OutputLine(typeof(Feedback), fileComparisonFeedback.EndMessage); } } catch (Exception exception) { if (exception is DirectoryNotFoundException || exception is FileNotFoundException) { throw new InvalidPathException(); } else if (exception is UnauthorizedAccessException) { throw new InsufficientPrivilegesException(); } } }
public override void Execute() { Validate(Parameters); string path = Parameters[1]; var fileReadingFeedback = new FileReadingFeedback(); IOManager.OutputLine(typeof(Feedback), fileReadingFeedback.BeginMessage); string[] fileContents = FSManager.ReadFile(path); if (fileContents != null) { IOManager.OutputLine(typeof(Feedback), fileReadingFeedback.ProgressMessage); } if (fileContents.Length > 0) { IOManager.OutputLine(typeof(Feedback), fileReadingFeedback.ResultMessage); IOManager.DisplayFileContents(fileContents); } else { IOManager.OutputLine(typeof(Feedback), fileReadingFeedback.EndMessage); } }