public void CreateUnsortedChapter(string folderName, Vertical[] verticals) { if (CourseWithChapters.Chapters.All(x => x.UrlName != "Unsorted")) { var chapters = new List<Chapter>(CourseWithChapters.Chapters); var newChapter = new Chapter("Unsorted", "Unsorted", new[] { new Sequential(Utils.NewNormalizedGuid(), "Unsorted " + DateTime.Now, verticals) }); chapters.Add(newChapter); CourseWithChapters.Chapters = chapters.ToArray(); CourseWithChapters.ChapterReferences = CourseWithChapters.Chapters.Select(x => new ChapterReference { UrlName = x.UrlName }).ToArray(); File.WriteAllText(string.Format("{0}/course/{1}.xml", folderName, CourseWithChapters.UrlName), CourseWithChapters.XmlSerialize()); newChapter.Save(folderName); } else { var testChapter = CourseWithChapters.Chapters.Single(x => x.UrlName == "Unsorted"); var sequentials = new List<Sequential>(testChapter.Sequentials); var newSequential = new Sequential(Utils.NewNormalizedGuid(), "Unsorted " + DateTime.Now, verticals); sequentials.Add(newSequential); testChapter.Sequentials = sequentials.ToArray(); testChapter.SequentialReferences = testChapter.Sequentials.Select(x => new SequentialReference { UrlName = x.UrlName }).ToArray(); File.WriteAllText(string.Format("{0}/chapter/{1}.xml", folderName, testChapter.UrlName), testChapter.XmlSerialize()); newSequential.Save(folderName); } }
public void CreateUnsortedChapter(string folderName, Vertical[] verticals) { if (CourseWithChapters.Chapters.All(x => x.UrlName != "Unsorted")) { var chapters = new List<Chapter>(CourseWithChapters.Chapters); var newChapter = new Chapter("Unsorted", "Unsorted", DateTime.MaxValue, new[] { new Sequential(Utils.NewNormalizedGuid(), "Unsorted " + DateTime.Now, verticals) { VisibleToStaffOnly = true } }); chapters.Add(newChapter); CourseWithChapters.Chapters = chapters.ToArray(); CourseWithChapters.ChapterReferences = CourseWithChapters.Chapters.Select(x => new ChapterReference { UrlName = x.UrlName }).ToArray(); File.WriteAllText(string.Format("{0}/course/{1}.xml", folderName, CourseWithChapters.UrlName), CourseWithChapters.XmlSerialize()); newChapter.Save(folderName); } else { var unsortedChapter = CourseWithChapters.Chapters.Single(x => x.UrlName == "Unsorted"); var filename = string.Format("{0}/chapter/{1}.xml", folderName, unsortedChapter.UrlName); var chapterXml = XDocument.Load(filename).Root ?? new XElement("chapter"); var newSequential = new Sequential(Utils.NewNormalizedGuid(), "Unsorted " + DateTime.Now, verticals); chapterXml.Add(new XElement("sequential", new XAttribute("url_name", newSequential.UrlName))); chapterXml.Save(filename); new FileInfo(filename).RemoveXmlDeclaration(); newSequential.Save(folderName); } }
public EdxCourse(string courseId, string organization, string courseTitle, string[] advancedModules, string[] ltiPassports, Chapter[] chapters) { CourseName = courseId; UrlName = courseId; Organization = organization; CourseWithChapters = new CourseWithChapters(courseId, courseTitle, advancedModules, ltiPassports, true, chapters); StaticFiles = Directory.GetFiles(string.Format("{0}/static", Utils.GetRootDirectory())); }
public CourseWithChapters(string urlName, string displayName, string[] advancedModules, string[] ltiPassports, bool useLatexCompiler, Chapter[] chapters) { UrlName = urlName; DisplayName = displayName; AdvancedModules = advancedModules == null ? null : JsonConvert.SerializeObject(advancedModules); LtiPassports = ltiPassports == null ? null : JsonConvert.SerializeObject(ltiPassports); UseLatexCompiler = useLatexCompiler; Chapters = chapters; ChapterReferences = chapters.Select(x => x.GetReference()).ToArray(); }