예제 #1
0
        private static string[] GetLinesWithPossibleMismatches(string[] actualOutputLines, string[] expectedOutputLines, out bool hasMismatch)
        {
            hasMismatch = false;
            string output = string.Empty;

            string[] mismatches = new string[actualOutputLines.Length];
            OutputWriter.WriteMessageOnNewLine("Comparing files...");
            int minOutputLines = actualOutputLines.Length;

            if (actualOutputLines.Length != expectedOutputLines.Length)
            {
                hasMismatch    = true;
                minOutputLines = Math.Min(actualOutputLines.Length, expectedOutputLines.Length);
                OutputWriter.DisplayExceptions(ExceptionMessages.ComparisonOfFilesWithDifferentSizes);
            }
            for (int i = 0; i < minOutputLines; i++)
            {
                string actualLine   = actualOutputLines[i];
                string expectedLine = expectedOutputLines[i];
                if (!actualLine.Equals(expectedLine))
                {
                    output      = string.Format("Mismatch at line {0} -- expected:\"{1}\", actual: \"{2}\"", i, expectedLine, actualLine);
                    output     += Environment.NewLine;
                    hasMismatch = true;
                }
                else
                {
                    output  = actualLine;
                    output += Environment.NewLine;
                }
                mismatches[i] = output;
            }
            return(mismatches);
        }
 private static void TryParseParametersForOrderAndTake(string takeCommand, string takeQunatity, string courseName, string order)
 {
     if (takeCommand == "take")
     {
         if (takeQunatity == "all")
         {
             StudentsRepository.OrderAndTake(courseName, order);
         }
         else
         {
             int  studentsToTake;
             bool hasParsed = int.TryParse(takeQunatity, out studentsToTake);
             if (hasParsed)
             {
                 StudentsRepository.OrderAndTake(courseName, order, studentsToTake);
             }
             else
             {
                 OutputWriter.DisplayExceptions(ExceptionMessages.InvalidTakeQuantityParameter);
             }
         }
     }
     else
     {
         OutputWriter.DisplayExceptions(ExceptionMessages.InvalidTakeCommand);
     }
 }
예제 #3
0
 public static void ChangeCurrentDirecotryAbsolute(string absolutePath)
 {
     if (!Directory.Exists(absolutePath))
     {
         OutputWriter.DisplayExceptions(ExceptionMessages.InvalidPath);
         return;
     }
     SessionData.currentPath = absolutePath;
 }
 private static bool IsQueryForStudentPossible(string courseName, string studentUserName)
 {
     if (IsQueryForCoursePossible(courseName) && studentsByCourse[courseName].ContainsKey(studentUserName))
     {
         return(true);
     }
     else
     {
         OutputWriter.DisplayExceptions(ExceptionMessages.InexistingStudentInDataBase);
     }
     return(false);
 }
 private static bool IsQueryForCoursePossible(string courseName)
 {
     if (isDataInitialized)
     {
         return(true);
     }
     else
     {
         OutputWriter.DisplayExceptions(ExceptionMessages.DataNotInitializedExceptionMessage);
     }
     return(false);
 }
예제 #6
0
        public static void CreateDirectoryInCurrentFolder(string name)
        {
            string path = Directory.GetCurrentDirectory() + "\\" + name;

            try
            {
                Directory.CreateDirectory(path);
            }
            catch (ArgumentException)
            {
                OutputWriter.DisplayExceptions(ExceptionMessages.ForbiddenSymbolsContainedInName);
            }
        }
예제 #7
0
 public static void CompareContent(string userOutputPath, string expectedOutputPath)
 {
     try
     {
         OutputWriter.WriteMessageOnNewLine("Reading files...");
         string   mismatchPath        = GetMismatchPath(expectedOutputPath);
         var      actualOutputLines   = File.ReadAllLines(userOutputPath);
         var      expectedOutputLines = File.ReadAllLines(expectedOutputPath);
         bool     hasMismatch;
         string[] mismatches = GetLinesWithPossibleMismatches(actualOutputLines, expectedOutputLines, out hasMismatch);
         PrintOutput(mismatches, hasMismatch, mismatchPath);
         OutputWriter.WriteMessageOnNewLine("Files read!");
     }
     catch (FileNotFoundException)
     {
         OutputWriter.DisplayExceptions(ExceptionMessages.InvalidPath);
     }
 }
예제 #8
0
 public static void FilterAndTake(Dictionary <string, List <int> > wantedData, string wanteFilter, int studentsToTake)
 {
     if (wanteFilter == "excellent")
     {
         FilterAndTake(wantedData, x => x >= 5, studentsToTake);
     }
     else if (wanteFilter == "average")
     {
         FilterAndTake(wantedData, x => x <= 5 && x >= 3.5, studentsToTake);
     }
     else if (wanteFilter == "poor")
     {
         FilterAndTake(wantedData, x => x < 3.5, studentsToTake);
     }
     else
     {
         OutputWriter.DisplayExceptions(ExceptionMessages.InvalidStudentFilter);
     }
 }
예제 #9
0
 public static void OrderAndTake(Dictionary <string, List <int> > wantedData, string comparison, int studentsToTake)
 {
     comparison = comparison.ToLower();
     if (comparison == "ascending")
     {
         PrintStudents(wantedData.OrderBy(x => x.Value.Sum())
                       .Take(studentsToTake)
                       .ToDictionary(pair => pair.Key, pair => pair.Value));
     }
     else if (comparison == "descending")
     {
         PrintStudents(wantedData.OrderByDescending(x => x.Value.Sum())
                       .Take(studentsToTake)
                       .ToDictionary(pair => pair.Key, pair => pair.Value));
     }
     else
     {
         OutputWriter.DisplayExceptions(ExceptionMessages.InvalidComparisonQuery);
     }
 }
예제 #10
0
 private static void PrintOutput(string[] mismatches, bool hasMismatch, string mismatchPath)
 {
     if (hasMismatch)
     {
         foreach (var line in mismatches)
         {
             OutputWriter.WriteMessageOnNewLine(line);
         }
         try
         {
             File.WriteAllLines(mismatchPath, mismatches);
         }
         catch (DirectoryNotFoundException)
         {
             OutputWriter.DisplayExceptions(ExceptionMessages.InvalidPath);
         }
         return;
     }
     else
     {
         OutputWriter.WriteMessageOnNewLine("Files are identical. There are no mismatches.");
     }
 }
예제 #11
0
 public static void ChangeCurrentDirectoryRelative(string relativePath)
 {
     if (relativePath == "..")
     {
         try
         {
             var currentPath      = SessionData.currentPath;
             var indexOfLastSlash = currentPath.LastIndexOf("\\");
             var newPath          = currentPath.Substring(0, indexOfLastSlash);
             SessionData.currentPath = newPath;
         }
         catch (ArgumentOutOfRangeException)
         {
             OutputWriter.DisplayExceptions(ExceptionMessages.UnabelToGoHigherInPartitionHierarchy);
         }
     }
     else
     {
         var currentPath = SessionData.currentPath;
         currentPath += "\\" + relativePath;
         ChangeCurrentDirectoryRelative(currentPath);
     }
 }
 private static void TryTraverseFolders(string input, string[] data)
 {
     if (data.Length == 1)
     {
         IOManager.TraverseDirectorty(0);
     }
     else if (data.Length == 2)
     {
         int  depth;
         bool hasParsed = int.TryParse(data[1], out depth);
         if (hasParsed)
         {
             IOManager.TraverseDirectorty(depth);
         }
         else
         {
             OutputWriter.DisplayExceptions(ExceptionMessages.UnableToParseNumber);
         }
     }
     else
     {
         DisplayInvalidCommandMessage(input);
     }
 }
        private static void ReadData(string fileName)
        {
            string path = SessionData.currentPath + "\\" + fileName;

            if (File.Exists(path))
            {
                var      pattern       = @"([A-Z][a-zA-Z#+]*_[A-Z][a-z]{2}_\d{4})\s+(([A-Z][a-z]{0,3})\d{2}_\d{2,4})\s+(\d+)";
                var      regex         = new Regex(pattern);
                string[] allInputLines = File.ReadAllLines(path);
                for (int i = 0; i < allInputLines.Length; i++)
                {
                    if (!string.IsNullOrEmpty(allInputLines[i]) && regex.IsMatch(allInputLines[i]))
                    {
                        Match currentMatch = regex.Match(allInputLines[i]);
                        var   courseName   = currentMatch.Groups[1].Value;
                        var   userName     = currentMatch.Groups[2].Value;
                        int   studentScoreOnTask;
                        bool  hasParsedScore = int.TryParse(currentMatch.Groups[4].Value, out studentScoreOnTask);
                        var   data           = allInputLines[i].Split(' ');
                        if (hasParsedScore && (studentScoreOnTask >= 0 && studentScoreOnTask <= 100))
                        {
                            if (!studentsByCourse.ContainsKey(courseName))
                            {
                                studentsByCourse.Add(courseName, new Dictionary <string, List <int> >());
                            }
                            if (!studentsByCourse[courseName].ContainsKey(userName))
                            {
                                studentsByCourse[courseName].Add(userName, new List <int>());
                            }
                            studentsByCourse[courseName][userName].Add(studentScoreOnTask);
                        }
                    }
                }
            }
            else
            {
                OutputWriter.DisplayExceptions(ExceptionMessages.InvalidPath);
            }
            isDataInitialized = true;
            OutputWriter.WriteMessageOnNewLine("Data read!");

            //var input = Console.ReadLine();
            //while (!string.IsNullOrEmpty(input))
            //{
            //    var tokens = input.Split(' ');
            //    var course = tokens[0];
            //    var student = tokens[1];
            //    var mark = int.Parse(tokens[2]);

            //    if (!studentsByCourse.ContainsKey(course))
            //    {
            //        studentsByCourse.Add(course, new Dictionary<string, List<int>>());
            //    }
            //    if (!studentsByCourse[course].ContainsKey(student))
            //    {
            //        studentsByCourse[course].Add(student, new List<int>());
            //    }
            //    studentsByCourse[course][student].Add(mark);
            //    input = Console.ReadLine();
            //}
        }