コード例 #1
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);
		}
コード例 #2
0
ファイル: Converter.cs プロジェクト: fakefeik/uLearn
		private static Sequential[] UnitToSequentials(Course course, Config config, List<string> units, int unitIndex, string exerciseUrl, string solutionsUrl, Dictionary<string, string> videoGuids)
		{
			var result = new List<Sequential>
			{
				new Sequential(string.Format("{0}-{1}-{2}", course.Id, unitIndex, 0), units[unitIndex],
					course.Slides
						.Where(s => !config.IgnoredUlearnSlides.Contains(s.Id))
						.Where(y => y.Info.UnitName == units[unitIndex])
						.SelectMany(y => y.ToVerticals(course.Id, exerciseUrl, solutionsUrl, videoGuids, config.LtiId))
						.ToArray())
			};
			var note = course.FindInstructorNote(units[unitIndex]);
			var displayName = "Заметки преподавателю";
			var sequentialId = string.Format("{0}-{1}-{2}", course.Id, unitIndex, "note-seq");
			var verticalId = string.Format("{0}-{1}-{2}", course.Id, unitIndex, "note-vert");
			var mdBlockId = string.Format("{0}-{1}-{2}", course.Id, unitIndex, "note-md");
			if (note != null)
				result.Add(new Sequential(sequentialId, displayName,
					new[]
					{
						new Vertical(verticalId, displayName, new[] { new MdBlock(course.FindInstructorNote(units[unitIndex]).Markdown).ToEdxComponent(mdBlockId, displayName, course.GetDirectoryByUnitName(units[unitIndex])) })
					}) { VisibleToStaffOnly = "true" }
				);
			return result.ToArray();
		}
コード例 #3
0
ファイル: Converter.cs プロジェクト: fakefeik/uLearn
		private static Chapter[] CourseToChapters(Course course, Config config, string exerciseUrl, string solutionsUrl, Dictionary<string, string> videoGuids)
		{
			var units = course.GetUnits().ToList();
			return Enumerable
				.Range(0, units.Count)
				.Select(x => new Chapter(string.Format("{0}-{1}", course.Id, x), units[x], UnitToSequentials(course, config, units, x, exerciseUrl, solutionsUrl, videoGuids)))
				.ToArray();
		}
コード例 #4
0
ファイル: Converter_should.cs プロジェクト: fakefeik/uLearn
		private EdxCourse ConvertForTestsCourseToEdx(Dictionary<string, string> youtubeId2UlearnVideoIds = null)
		{
			var config = new Config
			{
				Organization = "org",
				LtiId = ""
			};
			return Converter.ToEdxCourse(course, config, exerciseUrl, solutionsUrl,
				youtubeId2UlearnVideoIds ?? new Dictionary<string, string>());
		}
コード例 #5
0
ファイル: DownloadManager.cs プロジェクト: fakefeik/uLearn
		public static void Download(string baseDir, Config config, string edxStudioUrl, Credentials credentials)
		{
			Console.WriteLine("Downloading {0}.tar.gz", config.CourseRun);
			Download(edxStudioUrl, credentials.Email, credentials.GetPassword(), config.Organization, config.CourseNumber, config.CourseRun, baseDir + "/" + config.CourseRun + ".tar.gz");

			ArchiveManager.ExtractTar(baseDir + "/" + config.CourseRun + ".tar.gz", baseDir);
			Utils.DeleteFileIfExists(baseDir + "/" + config.CourseRun + ".tar.gz");
			Utils.DeleteDirectoryIfExists(baseDir + "/olx");
			Directory.Move(baseDir + "/" + config.CourseRun, baseDir + "/olx");
		}
コード例 #6
0
ファイル: Converter.cs プロジェクト: andgein/uLearn
		public static EdxCourse ToEdxCourse(Course course, Config config, string exerciseUrl, string solutionsUrl,
			Dictionary<string, string> youtubeId2UlearnVideoIds)
		{
			return new EdxCourse(
				course.Id, 
				config.Organization, 
				course.Title, 
				new[] { "lti" }, 
				null, 
				CourseToChapters(course, config, exerciseUrl, solutionsUrl, youtubeId2UlearnVideoIds));
		}
コード例 #7
0
ファイル: Config.cs プロジェクト: fakefeik/uLearn
		public static Profile GetProfile(Config config, string profile)
		{
			try
			{
				return config.Profiles.Single(x => x.Name == profile);
			}
			catch (Exception)
			{
				Console.WriteLine("Profiles were set up incorrectly");
				throw new OperationFailedGracefully();
			}
		}
コード例 #8
0
ファイル: ULearnInteractor.cs プロジェクト: andgein/uLearn
		public static void Upload(string baseDir, Config config, string ulearnUrl, Credentials credentials)
		{
			var fileFullName = Path.Combine(baseDir, config.ULearnCourseId + ".zip");
			var uploadUrl = ulearnUrl + "/Unit/UploadCourse?courseId=" + config.ULearnCourseId;
			var courseDir = Path.Combine(baseDir, config.ULearnCourseId);

			if (File.Exists(fileFullName))
				File.Delete(fileFullName);
			using (var zip = new ZipFile(fileFullName, Encoding.GetEncoding(866)))
			{
				zip.AddDirectory(courseDir);
				zip.Save();
			}

			var client = Login(ulearnUrl, credentials.Email, credentials.GetPassword());
			client.UploadFile(uploadUrl, fileFullName);
		}
コード例 #9
0
ファイル: ULearnInteractor.cs プロジェクト: andgein/uLearn
		public static void Download(string baseDir, bool force, Config config, string ulearnUrl, Credentials credentials)
		{
			var fileName = config.ULearnCourseId + ".zip";
			var fileFullName = Path.Combine(baseDir, fileName);
			var downloadUrl = string.Format("{0}/Unit/DownloadPackage?courseId={1}", ulearnUrl, HttpUtility.UrlEncode(config.ULearnCourseId));

			var client = Login(ulearnUrl, credentials.Email, credentials.GetPassword());
			client.TryDownloadFile(downloadUrl, fileFullName);
			Console.Out.WriteLine("Package downloaded to {0}", fileFullName);

			var dir = new DirectoryInfo(baseDir);
			using (var zip = ZipFile.Read(fileFullName, new ReadOptions { Encoding = Encoding.GetEncoding(866) }))
			{
				var courseDir = dir.CreateSubdirectory(config.ULearnCourseId);
				Directory.Delete(courseDir.FullName, force);
				courseDir.Create();
				zip.ExtractAll(courseDir.FullName, ExtractExistingFileAction.OverwriteSilently);
			}

			new FileInfo(fileFullName).Delete();
		}
コード例 #10
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
					);
			}
		}
コード例 #11
0
ファイル: EdxInteraction.cs プロジェクト: kontur-edu/uLearn
		public static void Download(string baseDir, Config config, string edxStudioUrl, Credentials credentials)
		{
			Console.WriteLine($"Downloading {config.ULearnCourseId}.tar.gz from {edxStudioUrl}");
			Download(edxStudioUrl, credentials.Email, credentials.GetPassword(), config.Organization, config.CourseNumber, config.CourseRun, baseDir + "/" + config.ULearnCourseId + ".tar.gz");
		}
コード例 #12
0
ファイル: EdxInteraction.cs プロジェクト: kontur-edu/uLearn
		public static void Upload(string courseName, Config config, string edxStudioUrl, Credentials credentials)
		{
			Console.WriteLine($"Uploading {courseName}.tar.gz to {edxStudioUrl}");
			Upload(edxStudioUrl, credentials.Email, credentials.GetPassword(), config.Organization, config.CourseNumber, config.CourseRun, courseName + ".tar.gz");
			Utils.DeleteFileIfExists(courseName + ".tar.gz");
		}
コード例 #13
0
ファイル: PatchOptions.cs プロジェクト: andgein/uLearn
		public abstract void Patch(OlxPatcher patcher, Config config, Profile profile, EdxCourse edxCourse);
コード例 #14
0
ファイル: DownloadManager.cs プロジェクト: fakefeik/uLearn
		public static void Upload(string baseDir, string courseName, Config config, string edxStudioUrl, Credentials credentials)
		{
			Environment.CurrentDirectory = baseDir;
			Utils.DeleteDirectoryIfExists("temp");
			if (Directory.Exists(courseName))
				Directory.Move(courseName, "temp");
			Utils.DirectoryCopy("olx", courseName, true);
			Utils.DeleteFileIfExists(courseName + ".tar.gz");

			Console.WriteLine("Creating {0}.tar.gz...", courseName);
			ArchiveManager.CreateTar(courseName + ".tar.gz", courseName);

			Utils.DeleteDirectoryIfExists(courseName);
			if (Directory.Exists("temp"))
				Directory.Move("temp", courseName);

			Console.WriteLine("Uploading {0}.tar.gz...", courseName);
			Upload(edxStudioUrl, credentials.Email, credentials.GetPassword(), config.Organization, config.CourseNumber, config.CourseRun, courseName + ".tar.gz");
			Utils.DeleteFileIfExists(courseName + ".tar.gz");
		}
コード例 #15
0
		public override void Patch(OlxPatcher patcher, Config config, Profile profile, EdxCourse edxCourse)
		{
			// input
			//			 patcher.PatchComponents(...);
			//			 patcher.PatchVerticals(...);
		}