Esempio n. 1
0
        /* Convert ulearn's blocks and group some of them into on stepik's text block*/
        private async Task <IEnumerable <StepikApiBlock> > ConvertUlearnBlocksIntoStepikBlocks(string courseId, Slide slide, IEnumerable <SlideBlock> blocks, CourseExportOptions options, int stepikLessonId, CourseExportResults results)
        {
            var stepikBlocks = new List <StepikApiBlock>();

            var previousTextBlock = new StepikApiBlock
            {
                Name = "text",
                Text = "",
            };
            var attachTextBlocksToInteractiveContent = slide is QuizSlide || slide is ExerciseSlide;

            foreach (var block in blocks)
            {
                if (block.Hide)
                {
                    continue;
                }

                var isCurrentBlockText = IsCurrentBlockText(block, options);
                if (isCurrentBlockText)
                {
                    previousTextBlock.Text += GetTextForStepikBlockFromUlearnBlock(courseId, slide, block);
                }
                else
                {
                    if (!string.IsNullOrEmpty(previousTextBlock.Text) && !attachTextBlocksToInteractiveContent)
                    {
                        stepikBlocks.Add(previousTextBlock);
                        previousTextBlock = new StepikApiBlock
                        {
                            Name = "text",
                            Text = "",
                        };
                    }

                    var stepikBlock = await ConvertUlearnNonTextBlockIntoStepikStepBlock(
                        block, previousTextBlock, courseId, slide, stepikLessonId, options, results
                        ).ConfigureAwait(false);

                    if (stepikBlock != null)
                    {
                        stepikBlocks.Add(stepikBlock);
                    }
                }
            }

            if (!string.IsNullOrEmpty(previousTextBlock.Text) && !attachTextBlocksToInteractiveContent)
            {
                stepikBlocks.Add(previousTextBlock);
            }

            return(stepikBlocks);
        }
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);
            }
        }