示例#1
0
		public Sequential(string urlName, string displayName, Vertical[] verticals)
		{
			UrlName = urlName;
			DisplayName = displayName;
			Verticals = verticals;
			VerticalReferences = verticals.Select(x => x.GetReference()).ToArray();
		}
示例#2
0
		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);
			}
		}
示例#3
0
		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);
			}
		}
示例#4
0
 public static Sequential Load(string folderName, string urlName, EdxLoadOptions options)
 {
     return(Load <Sequential>(folderName, "sequential", urlName, options, seq =>
     {
         seq.Verticals = seq.VerticalReferences.Select(x => Vertical.Load(folderName, x.UrlName, options)).ExceptNulls().ToArray();
         seq.VerticalReferences = seq.Verticals.Select(v => v.GetReference()).ToArray();
     }));
 }
示例#5
0
		private void SaveSequentialContainingSubverticals(EdxCourse course, IEnumerable<Vertical> verticalsToAdd, Vertical afterThisVertical)
		{
			var sequential = course.GetSequentialContainingVertical(afterThisVertical.UrlName);
			var filename = string.Format("{0}/sequential/{1}.xml", OlxPath, sequential.UrlName);
			var sequentialXml = XDocument.Load(filename).Root ?? new XElement("sequential");
			var refs = sequentialXml.Elements("vertical").ToList();
			var insertIndex = refs
				.Select((v, i) => new {urlName = v.Attribute("url_name").Value, i})
				.First(v => v.urlName == afterThisVertical.UrlName).i + 1;
			refs.InsertRange(insertIndex, verticalsToAdd.Select(v => new XElement("vertical", new XAttribute("url_name", v.UrlName))));
			sequentialXml.ReplaceNodes(refs);
			sequentialXml.Save(filename);
			new FileInfo(filename).RemoveXmlDeclaration();
		}
示例#6
0
		private void SaveSequentialContainingSubverticals(EdxCourse course, IEnumerable<Vertical> subverticals, Vertical first)
		{
			var sequential = course.GetSequentialContainingVertical(first.UrlName);
			var verticalReferences = sequential.VerticalReferences.ToList();
			var firstReference = verticalReferences.Single(x => x.UrlName == first.UrlName);

			verticalReferences.InsertRange(
				verticalReferences.IndexOf(firstReference) + 1,
				subverticals.Select(x => new VerticalReference { UrlName = x.UrlName })
			);

			sequential.VerticalReferences = verticalReferences.ToArray();
			File.WriteAllText(string.Format("{0}/sequential/{1}.xml", olxPath, sequential.UrlName), sequential.XmlSerialize());
		}
示例#7
0
 public static Sequential Load(string folderName, string urlName)
 {
     try
     {
         var sequential = new FileInfo(string.Format("{0}/sequential/{1}.xml", folderName, urlName)).DeserializeXml <Sequential>();
         sequential.UrlName   = urlName;
         sequential.Verticals = sequential.VerticalReferences.Select(x => Vertical.Load(folderName, x.UrlName)).ToArray();
         return(sequential);
     }
     catch (Exception e)
     {
         throw new Exception(string.Format("Sequential {0} load error", urlName), e);
     }
 }
示例#8
0
		public void Add(EdxCourse course, Vertical[] verticals)
		{
			if (verticals.Length != 0)
				course.CreateUnsortedChapter(OlxPath, verticals);
		}
示例#9
0
        private void SaveSequentialContainingSubverticals(EdxCourse course, IEnumerable <Vertical> verticalsToAdd, Vertical afterThisVertical)
        {
            var sequential    = course.GetSequentialContainingVertical(afterThisVertical.UrlName);
            var filename      = string.Format("{0}/sequential/{1}.xml", OlxPath, sequential.UrlName);
            var sequentialXml = XDocument.Load(filename).Root ?? new XElement("sequential");
            var refs          = sequentialXml.Elements("vertical").ToList();
            var insertIndex   = refs
                                .Select((v, i) => new { urlName = v.Attribute("url_name").Value, i })
                                .First(v => v.urlName == afterThisVertical.UrlName).i + 1;

            refs.InsertRange(insertIndex, verticalsToAdd.Select(v => new XElement("vertical", new XAttribute("url_name", v.UrlName))));
            sequentialXml.ReplaceNodes(refs);
            sequentialXml.Save(filename);
            new FileInfo(filename).RemoveXmlDeclaration();
        }