Exemple #1
0
        public Unit Load(FileInfo unitFile, CourseLoadingContext context)
        {
            var unitDirectory = unitFile.Directory;

            if (unitDirectory == null)
            {
                throw new CourseLoadingException($"Не могу загрузить модуль из {unitFile.GetRelativePath(context.CourseDirectory)}: не могу определить, из какой папки читать файлы со слайдами.");
            }

            UnitSettings unitSettings;

            if (unitFile.Exists)
            {
                unitSettings = UnitSettings.Load(unitFile, context.CourseSettings);
            }
            else
            {
                try
                {
                    unitSettings = UnitSettings.CreateByTitle(GetUnitTitleFromFile(unitDirectory), context.CourseSettings);
                }
                catch (Exception e)
                {
                    throw new CourseLoadingException(
                              $"Не удалось прочитать настройки курса. Скорее всего, отсутствует или неправильно заполнен файл модуля {unitFile.Name} ({unitFile.GetRelativePath(context.CourseDirectory)})."
                              );
                }
            }

            var unit = new Unit(unitSettings, unitDirectory);

            var slideFiles = unitSettings
                             .SlidesPaths
                             .SelectMany(path => unitDirectory.GetFiles(path, SearchOption.TopDirectoryOnly).OrderBy(f => f.FullName, StringComparer.InvariantCultureIgnoreCase))
                             .Distinct()
                             /* Don't load slide from unit file! Even accidentally */
                             .Where(f => f != unitFile);

            unit.SetSlides(slideFiles
                           .Select(f => LoadSlide(f, unit, context))
                           .ToList());

            var flashcardSlides = unit.GetSlides(true).OfType <FlashcardSlide>();

            foreach (var flashcardSlide in flashcardSlides)
            {
                foreach (var flashcard in flashcardSlide.FlashcardsList)
                {
                    unit.Flashcards.Add(flashcard);
                }
            }

            unit.LoadInstructorNote(context);

            return(unit);
        }
Exemple #2
0
        public static UnitSettings CreateByTitle(string title, CourseSettings courseSettings)
        {
            /* We should register encoding provider for Encoding.GetEncoding(1251) works */
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            var unitSettings = new UnitSettings
            {
                /* We use Win1251 only for back compatibility.
                 * In future all units will have Unit.xml with Id specified, so we will be able to switch to Encoding.UTF8 here or remove this function. */
                Id          = title.ToDeterministicGuid(Encoding.GetEncoding(1251)),
                Url         = title.ToLatin(),
                Title       = title,
                SlidesPaths = new[] { "S*.xml" }                 /* For backward compatibility with old automatic slide's xml detection */
            };

            unitSettings.Scoring.CopySettingsFrom(courseSettings.Scoring);
            return(unitSettings);
        }
Exemple #3
0
 public Unit(UnitSettings settings, DirectoryInfo directory)
 {
     Settings  = settings;
     Directory = directory;
 }
Exemple #4
0
 public Unit(UnitSettings settings, DirectoryInfo directory)
 {
     Settings   = settings;
     Directory  = directory;
     Flashcards = new List <Flashcard>();
 }