public void patch_putsNewVideos_toExistingUnsortedChapter() { var videoGuid = Utils.NewNormalizedGuid(); var videoGuid2 = Utils.NewNormalizedGuid(); var edxCourse = ConvertForTestsCourseToEdx(new Dictionary <string, string> { { youtubeIdFromCourse, videoGuid } }); var olxPath = string.Format("{0}/{1}", testFolderName, course.Id); edxCourse.Save(olxPath); var patcher = new OlxPatcher(olxPath); var videoDict = new Dictionary <string, Tuple <string, string> > { { videoGuid, Tuple.Create("QWFuk3ymXxc", "") }, { videoGuid2, Tuple.Create("w8_GlqSkG-U", "") } }; patcher.PatchComponents(edxCourse, GetVideoComponentFromDictionary(videoDict)); videoDict = new Dictionary <string, Tuple <string, string> > { { videoGuid, Tuple.Create("QWFuk3ymXxc", "") }, { videoGuid2, Tuple.Create("w8_GlqSkG-U", "") }, { Utils.NewNormalizedGuid(), Tuple.Create("qTnKi67AAlg", "") } }; patcher.PatchComponents(edxCourse, GetVideoComponentFromDictionary(videoDict)); var edxCourse2 = EdxCourse.Load(olxPath); Assert.AreEqual("Unsorted", edxCourse2.CourseWithChapters.Chapters[1].DisplayName); Assert.AreEqual(2, edxCourse2.CourseWithChapters.Chapters[1].Sequentials.Length); }
private void PatchInstructorsNotes(EdxCourse edxCourse, Course ulearnCourse, string olxPath) { var ulearnUnits = ulearnCourse.Units; foreach (var chapter in edxCourse.CourseWithChapters.Chapters) { var chapterUnit = ulearnCourse.Units.FirstOrDefault(u => u.Title == chapter.DisplayName); var chapterNote = chapterUnit?.InstructorNote; if (chapterUnit == null || chapterNote == null) { continue; } var unitIndex = ulearnUnits.IndexOf(chapterUnit); var displayName = "Заметки преподавателю"; var sequentialId = $"{ulearnCourse.Id}-{unitIndex}-note-seq"; var verticalId = $"{ulearnCourse.Id}-{unitIndex}-note-vert"; var mdBlockId = $"{ulearnCourse.Id}-{unitIndex}-note-md"; var sequentialNote = new Sequential(sequentialId, displayName, new[] { new Vertical(verticalId, displayName, new[] { new MdBlock(chapterNote.Markdown).ToEdxComponent(mdBlockId, displayName, chapterUnit.Directory.FullName) }) }) { VisibleToStaffOnly = true }; if (!File.Exists($"{olxPath}/sequential/{sequentialNote.UrlName}.xml")) { var sequentials = chapter.Sequentials.ToList(); sequentials.Add(sequentialNote); new Chapter(chapter.UrlName, chapter.DisplayName, chapter.Start, sequentials.ToArray()).Save(olxPath); } sequentialNote.Save(olxPath); } }
public override void DoExecute() { if (!UploadOlx && !DownloadOlx && !PatchOlx && !FullProcessingOlx) { Console.WriteLine("Use the options: --up, --down, --patch, --full. Or --help for help"); return; } Console.WriteLine("Profile {0}", Profile); var profile = Config.GetProfile(Profile); var credentials = Credentials.GetCredentials(Dir, Profile); if (DownloadOlx || FullProcessingOlx) { EdxInteraction.Download(Dir, Config, profile.EdxStudioUrl, credentials); } Console.WriteLine("Loading OLX"); var edxCourse = EdxCourse.Load(Dir + "/olx"); if (PatchOlx || FullProcessingOlx) { Console.WriteLine("Patching OLX..."); Patch(new OlxPatcher(Dir + "/olx"), Config, profile, edxCourse); Console.WriteLine("Patched!"); } if (UploadOlx || FullProcessingOlx) { EdxInteraction.Upload(Dir, edxCourse.CourseName, Config, profile.EdxStudioUrl, credentials); } }
public override void DoExecute() { var prequelChapterIds = PrequelChapterIds.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); Console.WriteLine("Loading OLX"); string olxDir = Dir + "/olx"; var edxCourse = EdxCourse.Load(olxDir); Console.WriteLine("Setting dates OLX..."); var curDate = StartDate; foreach (var chapter in edxCourse.CourseWithChapters.Chapters) { chapter.Start = curDate; chapter.Save(olxDir, withAdditionals: false); Console.WriteLine($"Patched start date of {chapter.UrlName} to " + curDate); if (!prequelChapterIds.Contains(chapter.UrlName, StringComparer.InvariantCultureIgnoreCase)) { curDate += TimeSpan.FromDays(7); // next week } } Console.WriteLine("Done!"); //EdxInteraction.CreateEdxCourseArchive(Dir, Config.ULearnCourseId); }
private void PatchInstructorsNotes(EdxCourse edxCourse, Course ulearnCourse, string olxPath) { var ulearnUnits = ulearnCourse.GetUnits().ToList(); foreach (var chapter in edxCourse.CourseWithChapters.Chapters) { var chapterNote = ulearnCourse.InstructorNotes.FirstOrDefault(x => x.UnitName == chapter.DisplayName); if (chapterNote == null) { continue; } var unitIndex = ulearnUnits.IndexOf(chapterNote.UnitName); var displayName = "Заметки преподавателю"; var sequentialId = string.Format("{0}-{1}-{2}", ulearnCourse.Id, unitIndex, "note-seq"); var verticalId = string.Format("{0}-{1}-{2}", ulearnCourse.Id, unitIndex, "note-vert"); var mdBlockId = string.Format("{0}-{1}-{2}", ulearnCourse.Id, unitIndex, "note-md"); var sequentialNote = new Sequential(sequentialId, displayName, new[] { new Vertical(verticalId, displayName, new[] { new MdBlock(chapterNote.Markdown).ToEdxComponent(mdBlockId, displayName, ulearnCourse.GetDirectoryByUnitName(chapterNote.UnitName)) }) }) { VisibleToStaffOnly = true }; if (!File.Exists(string.Format("{0}/sequential/{1}.xml", olxPath, sequentialNote.UrlName))) { var sequentials = chapter.Sequentials.ToList(); sequentials.Add(sequentialNote); new Chapter(chapter.UrlName, chapter.DisplayName, chapter.Start, sequentials.ToArray()).Save(olxPath); } sequentialNote.Save(olxPath); } }
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 override void DoExecute() { Console.WriteLine("Profile {0}", Profile); var profile = Config.GetProfile(Profile); var credentials = Credentials.GetCredentials(Dir, Profile); Console.WriteLine("Loading OLX"); var edxCourse = EdxCourse.Load(Dir + "/olx"); EdxInteraction.Upload(Dir, edxCourse.CourseName, Config, profile.EdxStudioUrl, credentials); }
public void convert_saveAndLoadEdxCourse() { var edxCourse = ConvertForTestsCourseToEdx(); var f1 = string.Format("{0}/{1}", testFolderName, 1); var f2 = string.Format("{0}/{1}", testFolderName, 2); edxCourse.Save(f1); EdxCourse.Load(f1).Save(f2); CollectionAssert.AreEqual(GetDirectoryFiles(f1), GetDirectoryFiles(f2)); }
public void convert_saveAndLoadEdxCourse() { var edxCourse = ConvertForTestsCourseToEdx(); var f1 = $"{testFolderName}/{1}"; var f2 = $"{testFolderName}/{2}"; edxCourse.Save(f1); EdxCourse.Load(f1).Save(f2); CollectionAssert.AreEqual(GetDirectoryFiles(f1), GetDirectoryFiles(f2)); }
public override void DoExecute() { var loadOptions = new EdxLoadOptions(); loadOptions.FailOnNonExistingItem = false; loadOptions.HandleNonExistentItemTypeName = (type, url) => Console.WriteLine($"Skipped non existent item type:{type} urlName:{url}"); var folderName = Path.Combine(Dir, "olx"); Console.WriteLine("Loading"); var course = EdxCourse.Load(folderName, loadOptions); Console.WriteLine("Saving"); course.Save(folderName); }
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() { Console.WriteLine("Profile {0}", Profile); var profile = Config.GetProfile(Profile); if (!SkipExtractingTarGz) { var tarGzPath = Dir.GetSingleFile(CourseTarGz ?? "*.tar.gz"); EdxInteraction.ExtractEdxCourseArchive(Dir, tarGzPath); } Console.WriteLine("Loading OLX"); var edxCourse = EdxCourse.Load(Dir + "/olx"); Console.WriteLine("Patching OLX..."); Patch(new OlxPatcher(Dir + "/olx"), Config, profile, edxCourse); Console.WriteLine("Patched!"); EdxInteraction.CreateEdxCourseArchive(Dir, Config.ULearnCourseId); }
public void patch_createsUnsortedChapter_withNewSlides() { var edxCourse = ConvertForTestsCourseToEdx(); var olxPath = $"{testFolderName}/{course.Id}"; edxCourse.Save(olxPath); new OlxPatcher(olxPath).PatchVerticals(edxCourse, new[] { aTextSlide } .Select(x => x.ToVerticals( course.Id, ulearnBaseUrl, new Dictionary <string, string>(), ltiId, testCourseDirectory.Parent ).ToArray())); var edxCourse2 = EdxCourse.Load(olxPath); Assert.AreEqual("Unsorted", edxCourse2.CourseWithChapters.Chapters.Last().DisplayName); }
public void patch_doesNotCreateUnsortedChapter_ifNoNewSlides() { var edxCourse = ConvertForTestsCourseToEdx(); var olxPath = string.Format("{0}/{1}", testFolderName, course.Id); edxCourse.Save(olxPath); new OlxPatcher(olxPath).PatchVerticals(edxCourse, course.GetSlides(true) .Select(x => x.ToVerticals( course.Id, ulearnBaseUrl, new Dictionary <string, string>(), ltiId, testCourseDirectory.Parent ).ToArray())); var edxCourse2 = EdxCourse.Load(olxPath); Assert.IsFalse(edxCourse2.CourseWithChapters.Chapters.Any(c => c.DisplayName == "Unsorted")); }
public void patch_createsUnsortedChapter_withNewSlides() { var edxCourse = ConvertForTestsCourseToEdx(); var olxPath = string.Format("{0}/{1}", testFolderName, course.Id); edxCourse.Save(olxPath); new OlxPatcher(olxPath).PatchVerticals(edxCourse, new [] { aTextSlide } .Select(x => x.ToVerticals( course.Id, slideUrl, solutionsUrl, new Dictionary <string, string>(), ltiId ).ToArray())); var edxCourse2 = EdxCourse.Load(olxPath); Assert.AreEqual("Unsorted", edxCourse2.CourseWithChapters.Chapters.Last().DisplayName); }
public void patch_updatesOrdinarySlide_withExerciseSlide() { var edxCourse = ConvertForTestsCourseToEdx(); var olxPath = string.Format("{0}/{1}", testFolderName, course.Id); edxCourse.Save(olxPath); var slidesCount = edxCourse.CourseWithChapters.Chapters[0].Sequentials[0].Verticals.Count(); new OlxPatcher(olxPath).PatchVerticals(edxCourse, new[] { exerciseSlide } .Select(x => x.ToVerticals( course.Id, ulearnBaseUrl, new Dictionary <string, string>(), ltiId, testCourseDirectory.Parent ).ToArray())); var edxCourse2 = EdxCourse.Load(olxPath); var patchedSlidesCount = edxCourse2.CourseWithChapters.Chapters[0].Sequentials[0].Verticals.Count(); Assert.AreEqual(slidesCount + 1, patchedSlidesCount); }
public abstract void Patch(OlxPatcher patcher, Config config, Profile profile, EdxCourse edxCourse);
public override void Patch(OlxPatcher patcher, Config config, Profile profile, EdxCourse edxCourse) { // input // patcher.PatchComponents(...); // patcher.PatchVerticals(...); }
public override void Patch(OlxPatcher patcher, Config config, Profile profile, EdxCourse edxCourse) { 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] }; VideoHistory.UpdateHistory(Dir, video); var guids = Guids == null ? null : Guids.Split(',').Select(Utils.GetNormalizedGuid).ToList(); if (config.Video != null && File.Exists(string.Format("{0}/{1}", Dir, config.Video))) { var videoComponents = video .Records .Where(x => guids == null || guids.Contains(Utils.GetNormalizedGuid(x.Guid))) .Select(x => new VideoComponent(Utils.GetNormalizedGuid(x.Guid), x.Data.Name, x.Data.Id)); patcher.PatchComponents( edxCourse, videoComponents, guids != null || !SkipExistingGuids ); } }
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); } }