public override void Execute() { if (this.Data.Length != 1) { throw new InvalidCommandException(this.Input); } this.Repository.UnloadData(); OutputWriter.DisplaySuccessfulMessage("Database dropped!"); }
private void PrintOutput(string[] mismatches, bool hasMismatch, string mismatchPath) { if (hasMismatch) { foreach (string line in mismatches) { OutputWriter.WriteMessageOnNewLine(line); } File.WriteAllLines(mismatchPath, mismatches); return; } OutputWriter.DisplaySuccessfulMessage("Files are identical. There are no mismatches."); }
public void CompareContent(string userOutputPath, string expectedOutputPath) { try { OutputWriter.DisplayWaitingMessage("Reading files..."); string mismatchPath = this.GetMismatchPath(expectedOutputPath); string[] actualOutputLines = File.ReadAllLines(userOutputPath); string[] expectedOutputLines = File.ReadAllLines(expectedOutputPath); bool hasMismatch; string[] mismatches = this.GetLinesWithPossibleMismatches(actualOutputLines, expectedOutputLines, out hasMismatch); this.PrintOutput(mismatches, hasMismatch, mismatchPath); OutputWriter.DisplaySuccessfulMessage("Files read!"); } catch (IOException ioException) { OutputWriter.DisplayMessage(ioException.Message); } }
private void ReadData(string fileName) { string pattern = @"([A-Z][a-zA-Z#\+]*_[A-Z][a-z]{2}_\d{4})\s+([A-Za-z]+\d{2}_\d{2,4})\s([\s0-9]+)"; string path = SessionData.currentPath + "\\" + fileName; if (File.Exists(path)) { string[] allInputLines = File.ReadAllLines(path); for (int i = 0; i < allInputLines.Length; i++) { if (!string.IsNullOrEmpty(allInputLines[i]) && Regex.IsMatch(allInputLines[i], pattern)) { Match match = Regex.Match(allInputLines[i], pattern); string courseName = match.Groups[1].Value; string username = match.Groups[2].Value; string scoresString = match.Groups[3].Value; try { int[] scores = scoresString.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries) .Select(int.Parse).ToArray(); if (scores.Any(s => s > 100 || s < 0)) { throw new InvalidScoreException(); } if (scores.Length > Course.NumberOfTasksOnExam) { OutputWriter.DisplayMessage(ExceptionMessages.InvalidNumberOfScores); continue; } if (!this.students.ContainsKey(username)) { this.students.Add(username, new Student(username)); } if (!this.courses.ContainsKey(courseName)) { this.courses.Add(courseName, new Course(courseName)); } ICourse course = this.courses[courseName]; IStudent student = this.students[username]; student.EnrollInCourse(course); student.SetMarkOnCourse(courseName, scores); course.EnrollStudent(student); } catch (FormatException fe) { OutputWriter.DisplayMessage(fe.Message + $"at line: {i}"); } } } } else { throw new InvalidPathException(); } this.isDataInitialized = true; OutputWriter.DisplaySuccessfulMessage("Data read!"); }