public static void GetAllStudentFromCourse(string courseName)
 {
     if (isQueryForCoursePossible(courseName))
     {
         OutputWriter.WriteMessegesOnNewLine($"{courseName}");
         foreach (var item in studentsByCourse[courseName])
         {
             OutputWriter.PrintStudent(item);
         }
     }
 }
 public static void InitializeData(string fileName)
 {
     if (!isDataInitilize)
     {
         OutputWriter.WriteMessegesOnNewLine("Read Data...");
         studentsByCourse = new Dictionary <string, Dictionary <string, List <int> > >();
         ReadData(fileName);
         isDataInitilize = true;
     }
     else
     {
         OutputWriter.WriteMessegesOnNewLine(ExceptionMessages.DataAlreadyInitializedException);
     }
 }
Example #3
0
 private static void TryGetHelp(string input, string[] data)
 {
     OutputWriter.WriteMessegesOnNewLine($"{new string('_', 100)}");
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "make directory - mkdir: path "));
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "traverse directory - ls: depth "));
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "comparing files - cmp: path1 path2"));
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "change directory - changeDirREl:relative path"));
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "change directory - changeDir:absolute path"));
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "read students data base - readDb: path"));
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "filter {courseName} excelent/average/poor  take 2/5/all students - filterExcelent (the output is written on the console)"));
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "order increasing students - order {courseName} ascending/descending take 20/10/all (the output is written on the console)"));
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "download file - download: path of file (saved in current directory)"));
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "download file asinchronously - downloadAsynch: path of file (save in the current directory)"));
     OutputWriter.WriteMessegesOnNewLine(string.Format("|{0, -98}|", "get help – help"));
     OutputWriter.WriteMessegesOnNewLine($"{new string('_', 100)}");
     OutputWriter.WriteEmptyLine();
 }
Example #4
0
        private static void PrintOutput(string[] mismatches, bool hasMismatch, string mismatchPath)
        {
            if (hasMismatch)
            {
                foreach (var item in mismatches)
                {
                    OutputWriter.WriteMessegesOnNewLine(item);
                }
                try
                {
                    File.WriteAllLines(mismatchPath, mismatches);
                }
                catch (DirectoryNotFoundException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.InvalidPath);
                }

                return;
            }
            OutputWriter.WriteMessegesOnNewLine("Files are identical. There are no mismatches");
        }
Example #5
0
        public static void TraverseDirectory(int depth)
        {
            OutputWriter.WriteEmptyLine();
            int            initialIdentation = SessionData.currentPath.Split('\\').Length;
            Queue <string> subFolder         = new Queue <string>();

            subFolder.Enqueue(SessionData.currentPath);

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

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

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

                    foreach (var directoryPath in Directory.GetDirectories(currentPath))
                    {
                        subFolder.Enqueue(directoryPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    OutputWriter.DisplayException(ExceptionMessages.UnauthorizedAccessException);
                }
            }
        }
        private static void ReadData(string fileName)
        {
            string path = SessionData.currentPath + "\\" + fileName;

            if (Directory.Exists(path))
            {
                string[] tokens  = path.Split(' ');
                string   course  = tokens[0];
                string   student = tokens[1];
                int      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);

                string[] allInputLines = File.ReadAllLines(path);
                for (int i = 0; i < allInputLines.Length; i++)
                {
                    if (!string.IsNullOrEmpty(allInputLines[i]))
                    {
                        string[] data = allInputLines[i].Split(' ');
                    }
                }
            }
            else
            {
                OutputWriter.DisplayException(ExceptionMessages.InvalidPath);
            }

            isDataInitilize = true;
            OutputWriter.WriteMessegesOnNewLine("Data Read!");
        }
Example #7
0
        public static void CompereContent(string userOutputPath, string expectedOutputPath)
        {
            try
            {
                OutputWriter.WriteMessegesOnNewLine("Reading files...");

                string mismatchPath = GetMismatchPath(expectedOutputPath);

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

                bool hasMismatch;

                string[] mismatches = GetLinesWithPossibleMismatches(actualOutPutLines, expectedOutputLines, out hasMismatch);

                PrintOutput(mismatches, hasMismatch, mismatchPath);
                OutputWriter.WriteMessegesOnNewLine("Files read!");
            }
            catch (FileNotFoundException)
            {
                OutputWriter.DisplayException(ExceptionMessages.InvalidPath);
            }
        }
Example #8
0
        private static string[] GetLinesWithPossibleMismatches(string[] actualOutPutLines, string[] expectedOutputLines, out bool hasMismatch)
        {
            hasMismatch = false;
            string output = string.Empty;

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

            int minOutputLines = actualOutPutLines.Length;

            if (actualOutPutLines.Length != expectedOutputLines.Length)
            {
                hasMismatch    = true;
                minOutputLines = Math.Min(actualOutPutLines.Length, expectedOutputLines.Length);
                OutputWriter.DisplayException(ExceptionMessages.ComparisonOfFilesWithDifferentSizes);
            }
            string[] mismatches = new string[minOutputLines];

            for (int i = 0; i < minOutputLines; i++)
            {
                string actualLine    = actualOutPutLines[i];
                string expectedLines = expectedOutputLines[i];
                if (!actualLine.Equals(expectedLines))
                {
                    output      = string.Format("Mismatch at line {0} -- expected \"{1}\", actual:\"{2}\" ", i, expectedLines, actualLine);
                    output     += Environment.NewLine;
                    hasMismatch = true;
                }
                else
                {
                    output  = actualLine;
                    output += Environment.NewLine;
                }
                mismatches[i] = output;
            }
            return(mismatches);
        }
Example #9
0
 public static void PrintStudent(KeyValuePair <string, List <int> > student)
 {
     OutputWriter.WriteMessegesOnNewLine(string.Format($"{student.Key} - {string.Join(", ", student.Value)}"));
 }