public override void Patch(OlxPatcher patcher, Config config, Profile profile, EdxCourse edxCourse) { var ulearnDir = new DirectoryInfo(string.Format("{0}/{1}", Dir, config.ULearnCourseId)); Console.WriteLine("Loading Ulearn course from {0}", ulearnDir.Name); var ulearnCourse = new CourseLoader().LoadCourse(ulearnDir); Console.WriteLine("Patching"); var videoJson = string.Format("{0}/{1}", Dir, config.Video); var video = File.Exists(videoJson) ? JsonConvert.DeserializeObject<Video>(File.ReadAllText(videoJson)) : new Video { Records = new Record[0] }; var videoHistory = VideoHistory.UpdateHistory(Dir, video); var videoGuids = videoHistory.Records .SelectMany(x => x.Data.Select(y => Tuple.Create(y.Id, x.Guid.GetNormalizedGuid()))) .ToDictionary(x => x.Item1, x => x.Item2); var guids = Guids?.Split(',').Select(Utils.GetNormalizedGuid).ToList(); patcher.PatchVerticals( edxCourse, ulearnCourse.Slides .Where(s => !config.IgnoredUlearnSlides.Select(Guid.Parse).Contains(s.Id)) .Where(s => guids == null || guids.Contains(s.NormalizedGuid)) .Select(s => s.ToVerticals( ulearnCourse.Id, profile.UlearnUrl + SlideUrlFormat, profile.UlearnUrl + SolutionsUrlFormat, videoGuids, config.LtiId ).ToArray()), guids != null || !SkipExistingGuids ); if (Config.EmitSequentialsForInstructorNotes) PatchInstructorsNotes(edxCourse, ulearnCourse, patcher.OlxPath); }
public override void DoExecute() { var course = new CourseLoader().Load(new DirectoryInfo(Path.Combine(Dir, Config.ULearnCourseId))); Console.WriteLine($"{course.Slides.Count} slide(s) have been loaded from {Config.ULearnCourseId}"); var resultHtmlFilename = $"{Config.ULearnCourseId}.annotations.html"; using (var writer = new StreamWriter(resultHtmlFilename)) { writer.WriteLine($"<html><head><title>{course.Title}</title><style>.videoId {{ color: #999; font-size: 12px; }}</style></head><body>"); foreach (var slide in course.Slides) { var videoBlocks = slide.Blocks.OfType <YoutubeBlock>(); foreach (var videoBlock in videoBlocks) { writer.WriteLine($"<h1># {slide.Title.EscapeHtml()}</h1>"); writer.WriteLine($"<span class='videoId'>{videoBlock.VideoId.EscapeHtml()}</span>"); } } writer.WriteLine("</body></html>"); } Console.WriteLine($"HTML has been generated and saved to {resultHtmlFilename}."); Console.WriteLine("Open this file in browser and copy its content to freshly created google doc."); Console.WriteLine("After it set this google doc's id (i.e. 1oJy12bkv2uyAMFBXEKRnNDIkR930-Z6X1dqR7CPuRkP) as <videoAnnotationsGoogleDoc>...</videoAnnotationsGoogleDoc>"); }
public override int Execute() { Dir = Dir ?? Directory.GetCurrentDirectory(); Profile = Profile ?? "default"; var configFile = Dir + "/config.xml"; if (Start(Dir, configFile)) return 0; var config = new FileInfo(configFile).DeserializeXml<Config>(); var profile = CourseTool.Profile.GetProfile(config, Profile); var credentials = Credentials.GetCredentials(Dir, Profile); DownloadManager.Download(Dir, config, profile.EdxStudioUrl, credentials); try { var edxCourse = EdxCourse.Load(Dir + "/olx"); if (edxCourse.CourseWithChapters.Chapters.Length != 0) Console.WriteLine("List of chapters to be removed or replaced:"); foreach (var result in edxCourse.CourseWithChapters.Chapters.Select(x => x.DisplayName)) Console.WriteLine("\t" + result); Console.WriteLine("Do you want to proceed?"); Console.WriteLine("y/n"); while (true) { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.Y) break; if (key.Key == ConsoleKey.N) return 0; } } catch (Exception) { } var videoFile = string.Format("{0}/{1}", Dir, config.Video); var video = File.Exists(videoFile) ? JsonConvert.DeserializeObject<Video>(File.ReadAllText(config.Video)) : new Video { Records = new Record[0] }; VideoHistory.UpdateHistory(Dir, video); Console.WriteLine("Loading uLearn course from {0}", config.ULearnCourseId); var course = new CourseLoader().LoadCourse(new DirectoryInfo(string.Format("{0}/{1}", Dir, config.ULearnCourseId))); Console.WriteLine("Converting uLearn course \"{0}\" to Edx course", course.Id); Converter.ToEdxCourse( course, config, profile.UlearnUrl + ExerciseUrlFormat, profile.UlearnUrl + SolutionsUrlFormat, video.Records.ToDictionary(x => x.Data.Id, x => Utils.GetNormalizedGuid(x.Guid)) ).Save(Dir + "/olx"); DownloadManager.Upload(Dir, course.Id, config, profile.EdxStudioUrl, credentials); return 0; }
public override void DoExecute() { var course = new CourseLoader().LoadCourse(new DirectoryInfo(Path.Combine(Dir, Config.ULearnCourseId))); Console.WriteLine($"{course.Slides.Count} slides loaded from {Config.ULearnCourseId}"); var googleDocFileId = course.Settings.VideoAnnotationsGoogleDoc ?? throw new Exception("no video-annotations-google-doc element in course.xml"); var annotations = ParseAnnotations(GetAnnotations(googleDocFileId)).ToList(); Console.WriteLine($"{annotations.Count} annotations loaded from google doc {googleDocFileId}"); var changedFiles = 0; var unchangedFiles = 0; foreach (var annotation in annotations) { var slide = course.GetSlideById(annotation.slideId); var xSlide = XDocument.Load(slide.Info.SlideFile.FullName); PatchSlide(xSlide, slide, annotation.annotation); var oldText = File.ReadAllText(slide.Info.SlideFile.FullName); xSlide.Save(slide.Info.SlideFile.FullName); var newText = File.ReadAllText(slide.Info.SlideFile.FullName); if (oldText != newText) { Console.WriteLine("patched " + slide.Info.SlideFile.Name); changedFiles++; } else { unchangedFiles++; } } Console.WriteLine($"Changed {changedFiles} files of {unchangedFiles} processed"); }
public override void DoExecute() { var ulearnDir = new DirectoryInfo($"{Dir}/{Config.ULearnCourseId}"); Console.Write("Loading Ulearn course from {0} ... ", ulearnDir.Name); var sw = Stopwatch.StartNew(); var course = new CourseLoader().Load(ulearnDir); Console.WriteLine(sw.ElapsedMilliseconds + " ms"); var slides = course.GetSlides(true); if (SlideId != null) { slides = slides.Where(s => s.Id == Guid.Parse(SlideId)).ToList(); Console.WriteLine("Only slide " + SlideId); } var validator = new CourseValidator(slides); validator.InfoMessage += m => Write(ConsoleColor.Gray, m); var errors = new List <string>(); validator.Error += m => { Write(ConsoleColor.Red, m); errors.Add(m); }; validator.Warning += m => { Write(ConsoleColor.DarkYellow, m); errors.Add(m); }; validator.ValidateSpelling(course); validator.ValidateExercises(); validator.ValidateVideos(); validator.ValidateFlashcardSlides(); validator.ValidateSlidesXml(); if (errors.Any()) { Console.WriteLine("Done! There are errors:"); foreach (var error in errors) { Write(ConsoleColor.Red, error, true); } File.WriteAllText(course.Id + "-validation-report.html", GenerateHtmlReport(course, errors)); } else { Console.WriteLine("OK! No errors found"); } Console.WriteLine("Press any key..."); Console.WriteLine("Exit code " + Environment.ExitCode); Console.ReadLine(); Environment.Exit(Environment.ExitCode); }
public override void DoExecute() { var profile = Config.GetProfile(Profile); Console.WriteLine("Please, download course from Edx (tar.gz from Tools - Export menu) and save it in working directory"); var tarGzPath = Dir.GetSingleFile(CourseTarGz ?? "*.tar.gz"); EdxInteraction.ExtractEdxCourseArchive(Dir, tarGzPath); Console.WriteLine("Loading edx course..."); var edxCourse = EdxCourse.Load(Dir + "/olx"); if (edxCourse.CourseWithChapters.Chapters.Length != 0) { Console.WriteLine("List of chapters to be removed or replaced:"); foreach (var chapterName in edxCourse.CourseWithChapters.Chapters.Select(x => x.DisplayName)) { Console.WriteLine("\t" + chapterName); } while (true) { Console.WriteLine("Do you want to proceed? (y/n)"); var key = Console.ReadKey(); if (key.Key == ConsoleKey.Y) { break; } if (key.Key == ConsoleKey.N) { return; } } } var video = LoadVideoInfo(); VideoHistory.UpdateHistory(Dir, video); Console.WriteLine($"Loading ulearn course from {Config.ULearnCourseId}"); var course = new CourseLoader().LoadCourse(new DirectoryInfo(Path.Combine(Dir, Config.ULearnCourseId))); Console.WriteLine($"Converting ulearn course \"{course.Id}\" to edx course"); Converter.ToEdxCourse( course, Config, profile.UlearnUrl + SlideUrlFormat, profile.UlearnUrl + SolutionsUrlFormat, video.Records.ToDictionary(x => x.Data.Id, x => x.Guid.GetNormalizedGuid()) ).Save(Dir + "/olx"); EdxInteraction.CreateEdxCourseArchive(Dir, course.Id); Console.WriteLine($"Now you can upload {course.Id}.tar.gz to edx via Tools - Import menu"); }
public void SetUp() { Directory.SetCurrentDirectory(TestsHelper.TestDirectory); if (!Directory.Exists(testFolderName)) { Directory.CreateDirectory(testFolderName); } var loader = new CourseLoader(new UnitLoader(new XmlSlideLoader())); course = loader.Load(testCourseDirectory); }
public void CovertLessonSlidesToXml() { var coursesDirectory = new DirectoryInfo(@"Your path to course"); var courseDirectories = coursesDirectory.GetDirectories("Slides", SearchOption.AllDirectories); foreach (var courseDirectory in courseDirectories) { var course = new CourseLoader().LoadCourse(courseDirectory); Console.WriteLine($"course {course.Id}"); foreach (var slide in course.Slides) { ConvertSlide(slide); } } }
public void CovertLessonSlidesToXml() { var coursesDirectory = new DirectoryInfo(@"Your path to course"); var courseDirectories = coursesDirectory.GetDirectories("Slides", SearchOption.AllDirectories); foreach (var courseDirectory in courseDirectories) { var course = new CourseLoader().LoadCourse(courseDirectory); Console.WriteLine($"course {course.Id}"); foreach (var slide in course.Slides) { ConvertSlide(slide); } } }
Course ReloadCourse() { var loadedCourse = new CourseLoader().LoadCourse(new DirectoryInfo(courseDir)); var renderer = new SlideRenderer(new DirectoryInfo(htmlDir), loadedCourse); foreach (var slide in loadedCourse.Slides) { renderer.RenderSlideToFile(slide, htmlDir); } foreach (var unit in loadedCourse.Units.Where(u => u.InstructorNote != null)) { renderer.RenderInstructorNotesToFile(unit, htmlDir); } return(loadedCourse); }
public override void DoExecute() { var profile = Config.GetProfile(Profile); var credentials = Credentials.GetCredentials(Dir, Profile); EdxInteraction.Download(Dir, Config, profile.EdxStudioUrl, credentials); var edxCourse = EdxCourse.Load(Dir + "/olx"); if (edxCourse.CourseWithChapters.Chapters.Length != 0) { Console.WriteLine("List of chapters to be removed or replaced:"); foreach (var chapterName in edxCourse.CourseWithChapters.Chapters.Select(x => x.DisplayName)) { Console.WriteLine("\t" + chapterName); } while (true) { Console.WriteLine("Do you want to proceed? (y/n)"); var key = Console.ReadKey(); if (key.Key == ConsoleKey.Y) { break; } if (key.Key == ConsoleKey.N) { return; } } } var video = LoadVideoInfo(); VideoHistory.UpdateHistory(Dir, video); Console.WriteLine("Loading uLearn course from {0}", Config.ULearnCourseId); var course = new CourseLoader().LoadCourse(new DirectoryInfo(Path.Combine(Dir, Config.ULearnCourseId))); Console.WriteLine("Converting uLearn course \"{0}\" to Edx course", course.Id); Converter.ToEdxCourse( course, Config, profile.UlearnUrl + SlideUrlFormat, profile.UlearnUrl + SolutionsUrlFormat, video.Records.ToDictionary(x => x.Data.Id, x => Utils.GetNormalizedGuid(x.Guid)) ).Save(Dir + "/olx"); EdxInteraction.Upload(Dir, course.Id, Config, profile.EdxStudioUrl, credentials); }
public override void DoExecute() { var profile = Config.GetProfile(Profile); Console.WriteLine("Please, download course from Edx (tar.gz from Tools - Export menu) and save it in working directory"); var tarGzPath = Dir.GetSingleFile(CourseTarGz ?? "*.tar.gz"); EdxInteraction.ExtractEdxCourseArchive(Dir, tarGzPath); Console.WriteLine("Loading edx course..."); var edxCourse = EdxCourse.Load(Dir + "/olx"); if (edxCourse.CourseWithChapters.Chapters.Length != 0) { Console.WriteLine("List of chapters to be removed or replaced:"); foreach (var chapterName in edxCourse.CourseWithChapters.Chapters.Select(x => x.DisplayName)) Console.WriteLine("\t" + chapterName); while (true) { Console.WriteLine("Do you want to proceed? (y/n)"); var key = Console.ReadKey(); if (key.Key == ConsoleKey.Y) break; if (key.Key == ConsoleKey.N) return; } } var video = LoadVideoInfo(); VideoHistory.UpdateHistory(Dir, video); Console.WriteLine($"Loading ulearn course from {Config.ULearnCourseId}"); var course = new CourseLoader().LoadCourse(new DirectoryInfo(Path.Combine(Dir, Config.ULearnCourseId))); Console.WriteLine($"Converting ulearn course \"{course.Id}\" to edx course"); Converter.ToEdxCourse( course, Config, profile.UlearnUrl + SlideUrlFormat, profile.UlearnUrl + SolutionsUrlFormat, video.Records.ToDictionary(x => x.Data.Id, x => x.Guid.GetNormalizedGuid()) ).Save(Dir + "/olx"); EdxInteraction.CreateEdxCourseArchive(Dir, course.Id); Console.WriteLine($"Now you can upload {course.Id}.tar.gz to edx via Tools - Import menu"); }
public void ConvertLessonSlidesToXml() { /* See Core/CSharp/BlocksBuilder.cs:200 (EmbedCode) before converting */ var coursesDirectory = new DirectoryInfo(@"C:\tmp\ulearn\10 course conversion"); // Insert your path here! var courseDirectories = coursesDirectory.GetDirectories("Slides", SearchOption.AllDirectories); foreach (var courseDirectory in courseDirectories) { var course = new CourseLoader().LoadCourse(courseDirectory); Console.WriteLine($"Converting course {course.Title}"); foreach (var slide in course.Slides) { ConvertSlide(slide); } } }
static void Reload() { var course = new CourseLoader().LoadCourse(new DirectoryInfo(courseDir)); server.course = course; var renderer = new SlideRenderer(new DirectoryInfo(htmlDir)); foreach (var slide in course.Slides) File.WriteAllText( string.Format("{0}/{1}.html", htmlDir, slide.Index.ToString("000")), renderer.RenderSlide(course, slide) ); foreach (var note in course.GetUnits().Select(course.FindInstructorNote).Where(x => x != null)) File.WriteAllText( string.Format("{0}/{1}.html", htmlDir, note.UnitName), renderer.RenderInstructorsNote(course, note.UnitName) ); server.UpdateAll(); }
public override void DoExecute() { var ulearnDir = new DirectoryInfo($"{Dir}/{Config.ULearnCourseId}"); Console.Write("Loading Ulearn course from {0} ... ", ulearnDir.Name); var sw = Stopwatch.StartNew(); var course = new CourseLoader().LoadCourse(ulearnDir); Console.WriteLine(sw.ElapsedMilliseconds + " ms"); var slides = course.Slides; if (SlideId != null) { slides = course.Slides.Where(s => s.Id == Guid.Parse(SlideId)).ToList(); Console.WriteLine("Only slide " + SlideId); } var validator = new CourseValidator(slides, new SandboxRunnerSettings()); validator.InfoMessage += m => Write(ConsoleColor.Gray, m); var errors = new List <string>(); validator.Error += m => { Write(ConsoleColor.Red, m); errors.Add(m); }; validator.ValidateExercises(); validator.ValidateVideos(); if (errors.Any()) { Console.WriteLine("Done! There are errors:"); foreach (var error in errors) { Write(ConsoleColor.Red, error); } } else { Console.WriteLine("OK! No errors found"); } Console.WriteLine("Press any key..."); Console.ReadLine(); }
public void CovertLessonSlidesToXml() { var coursesDirectory = new DirectoryInfo("../../../courses"); var courseDirectories = coursesDirectory.GetDirectories("Slides", SearchOption.AllDirectories); var serializer = new XmlSerializer(typeof(Lesson)); foreach (var courseDirectory in courseDirectories) { var course = new CourseLoader().LoadCourse(courseDirectory); foreach (var slide in course.Slides) { if (slide.ShouldBeSolved) continue; var lesson = new Lesson(slide.Title, slide.Id, slide.Blocks); var path = Path.ChangeExtension(slide.Info.SlideFile.FullName, "lesson.xml"); var file = new FileInfo(path); using (var stream = file.OpenWrite()) serializer.Serialize(stream, lesson); slide.Info.SlideFile.Delete(); } } }
public void LoadCourseTest() { const string providerCode = "PR1"; const string campusCode = "C"; Provider provider = new Provider { ProviderCode = providerCode }; var providers = new Dictionary <string, Provider> { [providerCode] = provider }; var subjects = new Dictionary <string, Subject>(); var pgdeCourses = new List <PgdeCourse>(); var courseLoader = new CourseLoader(providers, subjects, pgdeCourses, MockClock.Object); var courseRecords = new List <UcasCourse> { new UcasCourse { CrseCode = "CRS1", CampusCode = campusCode, InstCode = providerCode }, new UcasCourse { CrseCode = "CRS2", CampusCode = campusCode, InstCode = providerCode, Modular = "" }, new UcasCourse { CrseCode = "CRS3", CampusCode = campusCode, InstCode = providerCode, Modular = "M" } }; var courseSubjects = new List <UcasCourseSubject>(); var allSites = new List <Site> { new Site { Provider = provider, Code = campusCode } }; var returnedCourses = courseLoader.LoadCourses(provider, courseRecords, courseSubjects, allSites); returnedCourses.Should().HaveCount(3, "3 courses were passed in"); returnedCourses[0].Modular.Should().Be(null, "The first course doesn't specify Modular"); returnedCourses[1].Modular.Should().Be("", "The second course has an empty string Modular"); returnedCourses[2].Modular.Should().Be("M", "The third course has a defined Modular of 'M'"); }
public override void DoExecute() { var profile = Config.GetProfile(Profile); var credentials = Credentials.GetCredentials(Dir, Profile); EdxInteraction.Download(Dir, Config, profile.EdxStudioUrl, credentials); var edxCourse = EdxCourse.Load(Dir + "/olx"); if (edxCourse.CourseWithChapters.Chapters.Length != 0) { Console.WriteLine("List of chapters to be removed or replaced:"); foreach (var chapterName in edxCourse.CourseWithChapters.Chapters.Select(x => x.DisplayName)) Console.WriteLine("\t" + chapterName); while (true) { Console.WriteLine("Do you want to proceed? (y/n)"); var key = Console.ReadKey(); if (key.Key == ConsoleKey.Y) break; if (key.Key == ConsoleKey.N) return; } } var video = LoadVideoInfo(); VideoHistory.UpdateHistory(Dir, video); Console.WriteLine("Loading uLearn course from {0}", Config.ULearnCourseId); var course = new CourseLoader().LoadCourse(new DirectoryInfo(Path.Combine(Dir, Config.ULearnCourseId))); Console.WriteLine("Converting uLearn course \"{0}\" to Edx course", course.Id); Converter.ToEdxCourse( course, Config, profile.UlearnUrl + SlideUrlFormat, profile.UlearnUrl + SolutionsUrlFormat, video.Records.ToDictionary(x => x.Data.Id, x => Utils.GetNormalizedGuid(x.Guid)) ).Save(Dir + "/olx"); EdxInteraction.Upload(Dir, course.Id, Config, profile.EdxStudioUrl, credentials); }
public override void Patch(OlxPatcher patcher, Config config, Profile profile, EdxCourse edxCourse) { var ulearnDir = new DirectoryInfo(string.Format("{0}/{1}", Dir, config.ULearnCourseId)); Console.WriteLine("Loading Ulearn course from {0}", ulearnDir.Name); var ulearnCourse = new CourseLoader().Load(ulearnDir); Console.WriteLine("Patching"); var videoJson = string.Format("{0}/{1}", Dir, config.Video); var video = File.Exists(videoJson) ? JsonConvert.DeserializeObject <Video>(File.ReadAllText(videoJson)) : new Video { Records = new Record[0] }; var videoHistory = VideoHistory.UpdateHistory(Dir, video); var videoGuids = videoHistory.Records .SelectMany(x => x.Data.Select(y => Tuple.Create(y.Id, x.Guid.GetNormalizedGuid()))) .ToDictionary(x => x.Item1, x => x.Item2); var guids = Guids?.Split(',').Select(Utils.GetNormalizedGuid).ToList(); patcher.PatchVerticals( edxCourse, ulearnCourse.Slides .Where(s => !config.IgnoredUlearnSlides.Select(Guid.Parse).Contains(s.Id)) .Where(s => guids == null || guids.Contains(s.NormalizedGuid)) .Select(s => s.ToVerticals( ulearnCourse.Id, profile.UlearnUrl, videoGuids, config.LtiId, CoursePackageRoot ).ToArray()), guids != null || !SkipExistingGuids ); if (Config.EmitSequentialsForInstructorNotes) { PatchInstructorsNotes(edxCourse, ulearnCourse, patcher.OlxPath); } }
public override void DoExecute() { var ulearnDir = new DirectoryInfo(string.Format("{0}/{1}", Dir, Config.ULearnCourseId)); Console.Write("Loading Ulearn course from {0} ... ", ulearnDir.Name); var sw = Stopwatch.StartNew(); var course = new CourseLoader().LoadCourse(ulearnDir); Console.WriteLine(sw.ElapsedMilliseconds + " ms"); var slides = course.Slides; if (SlideId != null) { slides = course.Slides.Where(s => s.Id == Guid.Parse(SlideId)).ToArray(); Console.WriteLine("Only slide " + SlideId); } var validator = new CourseValidator(slides, new SandboxRunnerSettings()); validator.InfoMessage += m => Write(ConsoleColor.Gray, m); var errors = new List<string>(); validator.Error += m => { Write(ConsoleColor.Red, m); errors.Add(m); }; validator.ValidateExercises(); validator.ValidateVideos(); if (errors.Any()) { Console.WriteLine("Done! There are errors:"); foreach (var error in errors) { Write(ConsoleColor.Red, error); } } else Console.WriteLine("OK! No errors found"); Console.WriteLine("Press any key..."); Console.ReadLine(); }
public void CovertLessonSlidesToXml() { var coursesDirectory = new DirectoryInfo("../../../courses"); var courseDirectories = coursesDirectory.GetDirectories("Slides", SearchOption.AllDirectories); var serializer = new XmlSerializer(typeof(Lesson)); foreach (var courseDirectory in courseDirectories) { var course = new CourseLoader().LoadCourse(courseDirectory); foreach (var slide in course.Slides) { if (slide.ShouldBeSolved) { continue; } var lesson = new Lesson(slide.Title, slide.Id, slide.Blocks); var path = Path.ChangeExtension(slide.Info.SlideFile.FullName, "lesson.xml"); var file = new FileInfo(path); using (var stream = file.OpenWrite()) serializer.Serialize(stream, lesson); slide.Info.SlideFile.Delete(); } } }
/// <summary> /// Processes data in the payload object into the database as an upsert/delta /// </summary> public void UpdateUcasData() { var allCampusesGrouped = payload.Campuses.GroupBy(x => x.InstCode).ToDictionary(x => x.Key); var ucasSubjects = payload.Subjects.ToList(); var pgdeCourses = new List <PgdeCourse>(); var ucasCourseGroupings = payload.Courses.GroupBy(x => x.InstCode).ToDictionary(x => x.Key); var ucasCourseSubjectGroupings = payload.CourseSubjects.GroupBy(x => x.InstCode).ToDictionary(x => x.Key); _logger.Warning("Beginning UCAS import"); _logger.Information($"Upserting {payload.Institutions.Count()} institutions"); var allSubjects = new Dictionary <string, Subject>(); MigrateOnce("upsert subjects", () => { foreach (var s in payload.Subjects) { var savedSubject = UpsertSubject(new Subject { SubjectName = s.SubjectDescription, SubjectCode = s.SubjectCode }); allSubjects[savedSubject.SubjectCode] = savedSubject; } }); var providerCache = _context.Providers .Include(x => x.Sites) .Include(x => x.Courses) .ToDictionary(p => p.ProviderCode); MigratePerProvider("upsert providers", providerCache, inst => { var savedProvider = UpsertProvider(ToProvider(inst), providerCache); _context.Save(); // update/add cached copy providerCache[savedProvider.ProviderCode] = savedProvider; }); var courseLoader = new CourseLoader(providerCache, allSubjects, pgdeCourses, _clock); MigratePerProvider("drop-and-create sites and courses", providerCache, ucasInst => { var inst = providerCache[ucasInst.InstCode]; DeleteForProvider(inst.ProviderCode); _context.Save(); var campuses = allCampusesGrouped.ContainsKey(inst.ProviderCode) ? allCampusesGrouped[inst.ProviderCode] : null; IEnumerable <Site> sites = new List <Site>(); if (campuses != null) { inst.Sites = inst.Sites ?? new Collection <Site>(); sites = campuses.Select(x => ToSite(x)).ToList(); foreach (var site in (IEnumerable <Site>)sites) { inst.Sites.Add(site); site.Provider = inst; } _context.Save(); } var allCoursesForThisProvider = courseLoader.LoadCourses( inst, ucasCourseGroupings.GetValueOrDefault(inst.ProviderCode).AsEnumerable() ?? new List <UcasCourse>(), ucasCourseSubjectGroupings.GetValueOrDefault(inst.ProviderCode).AsEnumerable() ?? new List <UcasCourseSubject>(), sites); inst.Courses = new Collection <Course>(allCoursesForThisProvider.ToList()); _context.Save(); }); _logger.Warning("Completed UCAS import"); }
public async Task TestExportCourseFromDirectory(string coursePath) { var courseLoader = new CourseLoader(); var stubCourse = courseLoader.Load(new DirectoryInfo(coursePath)); await courseExporter.InitialExportCourse(stubCourse, new CourseInitialExportOptions(stepikCourseId, stepikXQueueName, new List <Guid>())); }
Course ReloadCourse() { var loadedCourse = new CourseLoader().LoadCourse(new DirectoryInfo(courseDir)); var renderer = new SlideRenderer(new DirectoryInfo(htmlDir), loadedCourse); foreach (var slide in loadedCourse.Slides) renderer.RenderSlideToFile(slide, htmlDir); foreach (var unit in loadedCourse.GetUnits().Where(u => loadedCourse.FindInstructorNote(u) != null)) renderer.RenderInstructorNotesToFile(unit, htmlDir); return loadedCourse; }
public void OneTimeSetUp() { loader = new CourseLoader(new UnitLoader(new XmlSlideLoader())); }