示例#1
0
        public void InterpredCommand(string input)
        {
            string[] data        = input.Split(' ');
            string   commandName = data[0];

            try
            {
                Command command = this.ParseCommand(input, commandName, data);
                command.Execute();
            }
            catch (DirectoryNotFoundException dnfe)
            {
                OutputWriter.DisplayExpetion(dnfe.Message);
            }
            catch (ArgumentOutOfRangeException aoore)
            {
                OutputWriter.DisplayExpetion(aoore.Message);
            }
            catch (ArgumentException ae)
            {
                OutputWriter.DisplayExpetion(ae.Message);
            }
            catch (Exception e)
            {
                OutputWriter.DisplayExpetion(e.Message);
            }
        }
 private void TryParseParametersForFilterAndTake(string takeCommand, string takeQuantity,
                                                 string courseName, string filter)
 {
     if (takeCommand == "take")
     {
         if (takeQuantity == "all")
         {
             this.Repository.FilterAndTake(courseName, filter);
         }
         else
         {
             int  studentsToTake;
             bool hasParsed = int.TryParse(takeQuantity, out studentsToTake);
             if (hasParsed)
             {
                 this.Repository.FilterAndTake(courseName, filter, studentsToTake);
             }
             else
             {
                 OutputWriter.DisplayExpetion(ExceptionMessages.InvalidTakeQuantityParameter);
             }
         }
     }
     else
     {
         OutputWriter.DisplayExpetion(ExceptionMessages.InvalidTakeCommandParameter);
     }
 }
示例#3
0
        public override void Execute()
        {
            if (this.Data.Length != 2)
            {
                throw new InvalidCommandException(this.Input);
            }
            if (Data.Length == 1)
            {
                int  depth;
                bool hasParser = int.TryParse(Data[0], out depth);
                if (hasParser)
                {
                    this.InputOutputManager.TraverseDirectory(depth);
                }
                else
                {
                    OutputWriter.DisplayExpetion(ExceptionMessages.UnableToParseNumber);
                }
            }
            else if (Data.Length == 2)
            {
                int  depth;
                bool hasParesd = int.TryParse(Data[1], out depth);

                if (hasParesd)
                {
                    this.InputOutputManager.TraverseDirectory(depth);
                }
                else
                {
                    OutputWriter.DisplayExpetion(ExceptionMessages.UnableToParseNumber);
                }
            }
        }
 private bool IsQueryForStudentPossiblе(string courseName, string studentUserName)
 {
     if (this.IsQueryForCoursePossible(courseName) && this.courses[courseName].StudentByName.ContainsKey(studentUserName))
     {
         return(true);
     }
     else
     {
         OutputWriter.DisplayExpetion(ExceptionMessages.InexistingStudentInDataBase);
     }
     return(false);
 }
示例#5
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);
        }
示例#6
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);
                }
            }
        }
        private bool IsQueryForCoursePossible(string courseName)
        {
            if (isDataInitialized)
            {
                return(true);
            }
            else
            {
                OutputWriter.DisplayExpetion(ExceptionMessages.DataNotInitializedExceptionMessage);
            }
            //return false;

            if (this.courses.ContainsKey(courseName))
            {
                return(true);
            }
            else
            {
                OutputWriter.DisplayExpetion(ExceptionMessages.InexistingStudentInDataBase);
            }
            return(false);
        }
示例#8
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!");
        }