public override void Execute()
 {
     if (this.Data.Length != 1)
     {
         throw new InvalidCommandException(this.Input);
     }
     this.Repository.UnloadData();
     OutputWriter.WriteMessageNewLine("Database Droped!");
 }
        public void GetAllStudentsFromCourse(string courseName)
        {
            if (IsQueryForCoursePossible(courseName))
            {
                OutputWriter.WriteMessageNewLine($"{courseName}");

                foreach (var studentMarksEntry in this.courses[courseName].StudentByName)
                {
                    this.GetStudentScoreFromCourse(courseName, studentMarksEntry.Key);
                }
            }
        }
Exemplo n.º 3
0
        private string[] GetLinesWithPossibleMismatches(
            string[] actualOutputLines, string[] expectedOutputLines, out bool hasMismatch)
        {
            hasMismatch = false;

            string output = string.Empty;

            string[] mismatches = new string[actualOutputLines.Length];

            OutputWriter.WriteMessageNewLine("Comparing files...");


            int minOutputLines = actualOutputLines.Length;

            if (actualOutputLines.Length != expectedOutputLines.Length)
            {
                hasMismatch    = true;
                minOutputLines = Math.Min(actualOutputLines.Length, expectedOutputLines.Length);
                OutputWriter.DisplayExpetion(ExceptionMessages.ComparisonOfFilesWithDifferentSizes);
            }

            for (int index = 0; index < minOutputLines; index++)
            {
                string actualLine   = actualOutputLines[index];
                string expectedLine = expectedOutputLines[index];



                if (!actualLine.Equals(expectedLine))
                {
                    output = string.Format("Mismatch at line {0} -- expected: \"{1}\", actual :\"{2}\"", index, expectedLine, actualLine);

                    output += Environment.NewLine;

                    hasMismatch = true;
                }
                else
                {
                    output = actualLine;

                    output += Environment.NewLine;
                }
                mismatches[index] = output;
            }
            return(mismatches);
        }
Exemplo n.º 4
0
        public void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIdentitation = SessionData.currentPath.Split('\\').Length;
            Queue <string> subFolder           = new Queue <string>();

            subFolder.Enqueue(SessionData.currentPath);

            while (subFolder.Count != 0)
            {
                string currentPath = subFolder.Dequeue();
                int    indentation = currentPath.Split('\\').Length - initialIdentitation;

                if (depth - indentation < 0)
                {
                    break;
                }



                try
                {
                    foreach (var file in Directory.GetFiles(currentPath))
                    {
                        int    indexOfLastSlash = file.LastIndexOf("\\");
                        string fileName         = file.Substring(indexOfLastSlash);
                        OutputWriter.WriteMessageNewLine(new string('-', indexOfLastSlash) + fileName);
                    }

                    foreach (var directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolder.Enqueue(directoryPath);
                    }

                    OutputWriter.WriteMessageNewLine(string.Format("{0}{1}", new string('-', indentation), currentPath));
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayExpetion(ExceptionMessages.UnauthorizedAccessExeptionMessage);
                }
            }
        }
Exemplo n.º 5
0
        private void PrintOutput(string[] mismatches, bool hasMismatch, string mismatchPath)
        {
            if (hasMismatch)
            {
                foreach (var line in mismatches)
                {
                    OutputWriter.WriteMessageNewLine(line);
                }
                try
                {
                    File.WriteAllLines(mismatchPath, mismatches);
                }
                catch (DirectoryNotFoundException)
                {
                    throw new InvalidPathException();
                }
                return;
            }

            OutputWriter.WriteMessageNewLine("Files are identical. There are no mismatches.");
        }
Exemplo n.º 6
0
        public void CompareContent(string userOutputPath, string expectedOutputPath)
        {
            try
            {
                OutputWriter.WriteMessageNewLine("Reading files...");

                string mismatchPath = GetMismatchPath(expectedOutputPath);

                string[] actualOutputLines = File.ReadAllLines(userOutputPath);

                string[] expectedOutputLines = File.ReadAllLines(expectedOutputPath);

                bool hasMismatch;

                string[] mistmatches = GetLinesWithPossibleMismatches(actualOutputLines, expectedOutputLines, out hasMismatch);

                PrintOutput(mistmatches, hasMismatch, mismatchPath);
                OutputWriter.WriteMessageNewLine("Files read!");
            }
            catch (IOException io)
            {
                OutputWriter.DisplayExpetion(io.Message);
            }
        }
        private void ReadData(string fileName)
        {
            string path = SessionData.currentPath + "\\" + fileName;



            if (File.Exists(path))
            {
                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]+)";

                Regex rgx = new Regex(pattern);

                string[] allInputLines = File.ReadAllLines(path);

                for (int line = 0; line < allInputLines.Length; line++)
                {
                    // var
                    if (!String.IsNullOrEmpty(allInputLines[line]) && rgx.IsMatch(allInputLines[line]))
                    {
                        Match currentMatch = rgx.Match(allInputLines[line]);

                        string courseName = currentMatch.Groups[1].Value;
                        string username   = currentMatch.Groups[2].Value;


                        string scoresStr = currentMatch.Groups[3].Value;

                        int[] scores = scoresStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
                                       .Select(int.Parse)
                                       .ToArray();

                        try
                        {
                            if (scores.Any(x => x > 100 || x < 0))
                            {
                                OutputWriter.DisplayExpetion(ExceptionMessages.InvalidScore);
                            }
                            if (scores.Length > Course.NumberOfTasksOnExam)
                            {
                                throw new InvalidNumberOfScoreException();
                            }

                            if (!this.students.ContainsKey(username))
                            {
                                this.students.Add(username, new Student(username));
                            }

                            if (!this.courses.ContainsKey(courseName))
                            {
                                this.courses.Add(courseName, new Course(courseName));
                            }

                            Course  course  = this.courses[courseName];
                            Student student = this.students[username];

                            student.EnrollInCourse(course);
                            student.SetMarkOnCourse(courseName, scores);

                            course.EnrollStudent(student);
                        }
                        catch (Exception fex)
                        {
                            OutputWriter.DisplayExpetion(fex.Message + $"at line : {line}");
                        }
                    }
                }
            }
            isDataInitialized = true;

            OutputWriter.WriteMessageNewLine("Data read!");
        }
Exemplo n.º 8
0
 public static void DisplayStudent(KeyValuePair <string, double> student)
 {
     OutputWriter.WriteMessageNewLine($"{student.Key} - {student.Value}");
 }