Esempio n. 1
0
        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);
        }
Esempio n. 2
0
        private async Task <StepikApiBlock> ConvertUlearnNonTextBlockIntoStepikStepBlock(SlideBlock block, StepikApiBlock lastTextBlock, string courseId, Slide slide, int lessonId, CourseExportOptions options, CourseExportResults results)
        {
            switch (block)
            {
            case AbstractExerciseBlock exerciseBlock:
                return(new StepikApiBlock
                {
                    Name = "external-grader",
                    Text = lastTextBlock.Text,
                    Cost = ((ExerciseSlide)slide).Scoring.PassedTestsScore,
                    Source = new StepikApiExternalGraderBlockSource(courseId, slide.Id, options.XQueueName, exerciseBlock.ExerciseInitialCode, stepikCSharpLanguageName)
                });

            case ChoiceBlock choiceBlock:
                return(new StepikApiBlock
                {
                    Name = "choice",
                    Text = lastTextBlock.Text + $"<p><br/><b>{choiceBlock.Text.EscapeHtml()}</b></p>",
                    Cost = choiceBlock.MaxScore,
                    Source = new StepikApiChoiceBlockSource(choiceBlock.Items.Select(ConvertUlearnChoiceItemIntoStepikChoiceOption))
                    {
                        IsMultipleChoice = choiceBlock.Multiple,
                        PreserveOrder = !choiceBlock.Shuffle
                    }
                });

            case YoutubeBlock videoBlock:
            {
                var rawVideoUrl = await youtubeVideoUrlExtractor.GetVideoUrl(videoBlock.GetYoutubeUrl()).ConfigureAwait(false);

                var video = await client.UploadVideo(rawVideoUrl, lessonId).ConfigureAwait(false);

                await Task.Delay(options.PauseAfterVideoUploaded).ConfigureAwait(false);

                return(new StepikApiBlock
                    {
                        Name = "video",
                        Video = video,
                    });
            }

            default:
                results.Error($"Unknown block type for converting into stepik step: {block.GetType().Name}, ignoring it");
                return(null);
            }
        }
Esempio n. 3
0
        private async Task TryUpdateCourse(Course course, CourseUpdateOptions updateOptions, CourseExportResults results)
        {
            results.Info($"Downloading stepik course #{updateOptions.StepikCourseId}");
            var stepikCourse = await client.GetCourse(updateOptions.StepikCourseId).ConfigureAwait(false);

            results.StepikCourseTitle = stepikCourse.Title;

            results.Info($"Downloading stepik sections for it ({string.Join(", ", stepikCourse.SectionsIds)})");
            var stepikSections = new Dictionary <int, StepikApiSection>();

            // TODO (andgein): download multiple sections in one request
            foreach (var sectionId in stepikCourse.SectionsIds)
            {
                stepikSections[sectionId] = await client.GetSection(sectionId).ConfigureAwait(false);
            }

            var stepikUnitsIds = stepikSections.SelectMany(kvp => kvp.Value.UnitsIds).ToList();

            results.Info($"Downloading stepik units ({string.Join(", ", stepikUnitsIds)}) and lessons for them");
            var stepikUnits = new Dictionary <int, StepikApiUnit>();

            foreach (var unitId in stepikUnitsIds)
            {
                stepikUnits[unitId] = await client.GetUnit(unitId).ConfigureAwait(false);
            }

            var stepikLessonsIds = stepikUnits.Select(kvp => kvp.Value.LessonId);
            var stepikLessons    = new Dictionary <int, StepikApiLesson>();

            foreach (var lessonId in stepikLessonsIds)
            {
                stepikLessons[lessonId] = await client.GetLesson(lessonId).ConfigureAwait(false);
            }

            var sectionIndex = stepikCourse.SectionsIds.Count;

            foreach (var slideUpdateOptions in updateOptions.SlidesUpdateOptions)
            {
                var slideId = slideUpdateOptions.SlideId;
                var slide   = course.FindSlideById(slideId);
                if (slide == null)
                {
                    results.Error($"Unable to find slide {slideId}, continue without it");
                    continue;
                }
                results.Info($"Updating slide «{slide.Title}» with id {slide.Id}");
                var             stepId = slideUpdateOptions.InsertAfterStep;
                StepikApiLesson lesson;
                int             position;

                if (stepId != -1 && stepikLessons.Values.Any(l => l.StepsIds.Contains(stepId)))
                {
                    var lessonId = stepikLessons.FirstOrDefault(kvp => kvp.Value.StepsIds.Contains(stepId)).Key;
                    // Re-download lesson because it can be changed for a while
                    lesson = await client.GetLesson(lessonId).ConfigureAwait(false);

                    position = lesson.StepsIds.FindIndex(stepId);

                    results.Info($"Removing old steps created for this slide: {string.Join(", ", slideUpdateOptions.RemoveStepsIds)}");
                    await RemoveStepsFromLesson(lesson, slideUpdateOptions.RemoveStepsIds, results).ConfigureAwait(false);
                }
                else
                {
                    results.Info("Creating new stepik lesson for this slide");
                    lesson = await CreateLessonAndSectionForSlide(slide, stepikCourse, ++sectionIndex).ConfigureAwait(false);

                    position = 0;
                }

                results.Info($"Inserting steps for slide «{slide.Title}» into lesson {lesson.Id} on position {position}");
                await InsertSlideAsStepsInLesson(course, slide, lesson.Id.Value, position + 1, updateOptions, results);
            }
        }