コード例 #1
0
ファイル: OlxPatcher.cs プロジェクト: andgein/uLearn
		public void PatchComponents(EdxCourse course, IEnumerable<Component> components, bool replaceExisting = true)
		{
			var newVerticals = new List<Vertical>();
			foreach (var component in components)
			{
				var filename = string.Format("{0}/{1}/{2}.xml", OlxPath, component.SubfolderName, component.UrlName);
				if (File.Exists(filename))
				{
					if (replaceExisting)
					{
						string displayName;
						try
						{
							var xml = new XmlDocument();
							xml.Load(filename);
							displayName = xml.DocumentElement.Attributes["display_name"].InnerText;
						}
						catch (Exception)
						{
							displayName = component.DisplayName;
						}
						component.DisplayName = displayName;
						component.Save(OlxPath);
					}
				}
				else newVerticals.Add(new Vertical(Utils.NewNormalizedGuid(), component.DisplayName, new[] { component }));
			}
			Add(course, newVerticals.ToArray());
		}
コード例 #2
0
ファイル: OlxPatcher.cs プロジェクト: andgein/uLearn
		public void PatchVerticals(EdxCourse course, IEnumerable<Vertical[]> verticals, bool replaceExisting = true)
		{
			var newVerticals = new List<Vertical>();
			foreach (var subverticals in verticals)
			{
				var existsMap = subverticals.ToDictionary(sv => sv, sv => File.Exists(string.Format("{0}/vertical/{1}.xml", OlxPath, sv.UrlName)));
				if (subverticals.Any(x => existsMap[x]))
				{
					if (replaceExisting)
					{
						foreach (var subvertical in subverticals)
							subvertical.Save(OlxPath);

						if (subverticals.Length > 1)
							SaveSequentialContainingSubverticals(
								course,
								subverticals.Where(x => !existsMap[x]).ToArray(),
								subverticals.First(x => existsMap[x])
							);
					}
				}
				else newVerticals.AddRange(subverticals);
			}
			Add(course, newVerticals.ToArray());
		}
コード例 #3
0
		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);
		}
コード例 #4
0
		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);
			}
		}
コード例 #5
0
        public void PatchVerticals(EdxCourse course, IEnumerable <Vertical[]> verticals, bool replaceExisting = true)
        {
            var newVerticals = new List <Vertical>();

            foreach (var subverticals in verticals)
            {
                var existsMap = subverticals.ToDictionary(sv => sv, sv => File.Exists(string.Format("{0}/vertical/{1}.xml", OlxPath, sv.UrlName)));
                if (subverticals.Any(x => existsMap[x]))
                {
                    if (replaceExisting)
                    {
                        foreach (var subvertical in subverticals)
                        {
                            subvertical.Save(OlxPath);
                        }

                        if (subverticals.Length > 1)
                        {
                            SaveSequentialContainingSubverticals(
                                course,
                                subverticals.Where(x => !existsMap[x]).ToArray(),
                                subverticals.First(x => existsMap[x])
                                );
                        }
                    }
                }
                else
                {
                    newVerticals.AddRange(subverticals);
                }
            }
            Add(course, newVerticals.ToArray());
        }
コード例 #6
0
 public void Add(EdxCourse course, Vertical[] verticals)
 {
     if (verticals.Length != 0)
     {
         course.CreateUnsortedChapter(OlxPath, verticals);
     }
 }
コード例 #7
0
        public void PatchComponents(EdxCourse course, IEnumerable <Component> components, bool replaceExisting = true)
        {
            var newVerticals = new List <Vertical>();

            foreach (var component in components)
            {
                var filename = string.Format("{0}/{1}/{2}.xml", OlxPath, component.SubfolderName, component.UrlName);
                if (File.Exists(filename))
                {
                    if (replaceExisting)
                    {
                        string displayName;
                        try
                        {
                            var xml = new XmlDocument();
                            xml.Load(filename);
                            displayName = xml.DocumentElement.Attributes["display_name"].InnerText;
                        }
                        catch (Exception)
                        {
                            displayName = component.DisplayName;
                        }
                        component.DisplayName = displayName;
                        component.Save(OlxPath);
                    }
                }
                else
                {
                    newVerticals.Add(new Vertical(Utils.NewNormalizedGuid(), component.DisplayName, new[] { component }));
                }
            }
            Add(course, newVerticals.ToArray());
        }
コード例 #8
0
ファイル: OlxPatcher.cs プロジェクト: andgein/uLearn
		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();
		}
コード例 #9
0
ファイル: OlxPatcher.cs プロジェクト: hexandr/uLearn
		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());
		}
コード例 #10
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();
        }
コード例 #11
0
ファイル: VideoPatchOptions.cs プロジェクト: andgein/uLearn
		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
					);
			}
		}
コード例 #12
0
ファイル: OlxPatcher.cs プロジェクト: andgein/uLearn
		public void Add(EdxCourse course, Vertical[] verticals)
		{
			if (verticals.Length != 0)
				course.CreateUnsortedChapter(OlxPath, verticals);
		}
コード例 #13
0
ファイル: PatchOptions.cs プロジェクト: andgein/uLearn
		public abstract void Patch(OlxPatcher patcher, Config config, Profile profile, EdxCourse edxCourse);
コード例 #14
0
ファイル: Options.cs プロジェクト: hexandr/uLearn
		public override void Patch(OlxPatcher patcher, Config config, EdxCourse edxCourse)
		{
			// input
			// patcher.PatchComponents();
			// patcher.PatchVerticals();
		}
コード例 #15
0
ファイル: Options.cs プロジェクト: hexandr/uLearn
		public override void Patch(OlxPatcher patcher, Config config, EdxCourse edxCourse)
		{
			var ulearnCourse = new CourseLoader().LoadCourse(new DirectoryInfo(string.Format("{0}/{1}", Dir, config.ULearnCourseId)));

			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, Utils.GetNormalizedGuid(x.Guid))))
				.ToDictionary(x => x.Item1, x => x.Item2);

			var guids = Guids == null ? null : Guids.Split(',').Select(Utils.GetNormalizedGuid).ToList();

			patcher.PatchVerticals(
				edxCourse, 
				ulearnCourse.Slides
					.Where(x => guids == null || guids.Contains(x.Guid))
					.Select(x => x.ToVerticals(
							ulearnCourse.Id, 
							config.ExerciseUrl, 
							config.SolutionsUrl, 
							videoGuids,
							config.LtiId
						).ToArray()),
				guids != null || ReplaceExisting
			);
		}