private async Task TryInitialExportCourse(Course course, CourseInitialExportOptions exportOptions, CourseExportResults results) { var stepikCourse = await client.GetCourse(exportOptions.StepikCourseId).ConfigureAwait(false); results.StepikCourseTitle = stepikCourse.Title; await ClearCourse(stepikCourse).ConfigureAwait(false); var unitIndex = 0; foreach (var unit in course.Units) { results.Info($"Converting ulearn unit «{unit.Title}» into stepik section"); var section = ConvertUlearnUnitIntoStepikSection(unit); section.CourseId = exportOptions.StepikCourseId; section.Position = ++unitIndex; section = await client.UploadSection(section).ConfigureAwait(false); if (!section.Id.HasValue) { throw new StepikApiException($"Didn't receive `section`'s ID from stepik: {section.JsonSerialize()}"); } var currentStepikLessonId = -1; var blockIndex = 0; var lessonIndex = 0; var isFirstSlideInUnit = true; foreach (var slide in unit.Slides) { results.Info($"Converting ulearn slide «{slide.Title}» with id {slide.Id} into stepik steps"); var needToStartNewLesson = isFirstSlideInUnit || exportOptions.SlideIdsWhereNewLessonsStart.Contains(slide.Id); isFirstSlideInUnit = false; if (needToStartNewLesson) { results.Info("Starting new stepik lesson for this slide"); var lesson = await client.UploadLesson(new StepikApiLesson { Title = slide.Title }).ConfigureAwait(false); if (!lesson.Id.HasValue) { throw new StepikApiException($"Didn't receive `lesson`'s ID from stepik: {lesson.JsonSerialize()}"); } currentStepikLessonId = lesson.Id.Value; await client.UploadUnit(new StepikApiUnit { Position = ++lessonIndex, SectionId = section.Id.Value, LessonId = currentStepikLessonId, }).ConfigureAwait(false); blockIndex = 0; } blockIndex += await InsertSlideAsStepsInLesson(course, slide, currentStepikLessonId, blockIndex, exportOptions, results).ConfigureAwait(false); } } }
public async Task <CourseExportResults> InitialExportCourse(Course course, CourseInitialExportOptions exportOptions) { var results = new CourseExportResults(course.Id, exportOptions.StepikCourseId); try { await TryInitialExportCourse(course, exportOptions, results); } catch (Exception e) { results.Error(e.Message); results.Exception = e; } return(results); }