예제 #1
0
 public Course(string id, List <Unit> units, CourseSettings settings, DirectoryInfo courseXmlDirectory)
 {
     Id                 = id;
     Units              = units;
     Settings           = settings;
     CourseXmlDirectory = courseXmlDirectory;
 }
예제 #2
0
 public CourseLoadingContext(string courseId, CourseSettings courseSettings, DirectoryInfo courseDirectory, FileInfo courseXml)
 {
     CourseId        = courseId;
     CourseSettings  = courseSettings;
     CourseDirectory = courseDirectory;
     CourseXml       = courseXml;
 }
예제 #3
0
 public CourseSettings(CourseSettings other)
     : this()
 {
     Title           = other.Title;
     DefaultLanguage = other.DefaultLanguage;
     Preludes        = (PreludeFile[])other.Preludes.Clone();
     DictionaryFile  = other.DictionaryFile;
 }
예제 #4
0
파일: Course.cs 프로젝트: samstikhin/Ulearn
 public Course(string id, List <Unit> units, [NotNull] CourseSettings settings, DirectoryInfo courseDirectory, DirectoryInfo courseXmlDirectory)
 {
     Id                 = id;
     this.units         = units;
     Settings           = settings;
     CourseXmlDirectory = courseXmlDirectory;
     CourseDirectory    = courseDirectory;
 }
예제 #5
0
 private static void CalculateScoringGroupScores(IEnumerable <Unit> units, CourseSettings settings)
 {
     foreach (var unit in units)
     {
         foreach (var slide in unit.Slides.Where(s => s.ShouldBeSolved))
         {
             unit.Scoring.Groups[slide.ScoringGroup].MaxNotAdditionalScore     += slide.MaxScore;
             settings.Scoring.Groups[slide.ScoringGroup].MaxNotAdditionalScore += slide.MaxScore;
         }
     }
 }
예제 #6
0
        private Course UnsafeLoad(DirectoryInfo dir)
        {
            var courseId = dir.Name;

            var loadFromDirectory = dir;
            var courseXmls        = dir.GetFiles("course.xml", SearchOption.AllDirectories).ToList();

            if (courseXmls.Count == 1)
            {
                loadFromDirectory = courseXmls[0].Directory;
            }
            else
            {
                loadFromDirectory = loadFromDirectory.HasSubdirectory("Slides") ? loadFromDirectory.GetSubdirectory("Slides") : loadFromDirectory;
            }

            CourseSettings settings;

            try
            {
                settings = CourseSettings.Load(loadFromDirectory);
            }
            catch (Exception e)
            {
                throw new CourseLoadingException($"Не удалось прочитать настройки курса из файла course.xml. {e.Message}", e.InnerException);
            }

            if (string.IsNullOrEmpty(settings.Title))
            {
                try
                {
                    settings.Title = GetCourseTitleFromFile(loadFromDirectory);
                }
                catch (Exception e)
                {
                    throw new CourseLoadingException(
                              "Не удалось прочитать настройки курса. Скорее всего, отсутствует или неправильно заполнен файл course.xml."
                              );
                }
            }

            var context = new CourseLoadingContext(courseId, settings, dir, loadFromDirectory.GetFile("course.xml"));

            var units  = LoadUnits(context).ToList();
            var slides = units.SelectMany(u => u.Slides).ToList();

            CheckDuplicateSlideIds(slides);
            AddDefaultScoringGroupIfNeeded(units, slides, settings);
            CalculateScoringGroupScores(units, settings);

            return(new Course(courseId, units, settings, dir));
        }
예제 #7
0
        private static void AddDefaultScoringGroupIfNeeded(IEnumerable <Unit> units, IEnumerable <Slide> slides, CourseSettings settings)
        {
            if (slides.Any(s => s.ShouldBeSolved && string.IsNullOrEmpty(s.ScoringGroup)))
            {
                var defaultScoringGroup = new ScoringGroup
                {
                    Id           = "",
                    Abbreviation = "Баллы",
                    Name         = "Упражнения и тесты",
                };
                settings.Scoring.Groups.Add(defaultScoringGroup.Id, defaultScoringGroup);

                /* Add default scoring group to each unit */
                foreach (var unit in units)
                {
                    unit.Scoring.Groups.Add(defaultScoringGroup.Id, defaultScoringGroup);
                }
            }
        }