/// <summary> /// Returns the specific instance of a generated question template /// that corresponds to the given seed. /// </summary> public async Task <GeneratedQuestionInstance> GetQuestionInstanceAsync( string classroomName, int id, int seed) { var question = await GetQuestionAsync(classroomName, id); if (question == null) { return(null); } var generatedQuestionTemplate = question as GeneratedQuestionTemplate; if (generatedQuestionTemplate == null) { throw new InvalidOperationException("Seed can only be specified for a generated question."); } var result = await _questionGenerator.GenerateQuestionAsync ( generatedQuestionTemplate, seed ); if (result.SerializedQuestion != null) { var resultingQuestion = _jsonSerializer.Deserialize <Question>(result.SerializedQuestion); resultingQuestion.Name = question.Name; resultingQuestion.QuestionCategoryId = question.QuestionCategoryId; resultingQuestion.QuestionCategory = question.QuestionCategory; return(new GeneratedQuestionInstance(resultingQuestion, seed, error: null)); } else { return(new GeneratedQuestionInstance(null /*question*/, seed, result.Error)); } }
/// <summary> /// Performs code-question-type-specific update operations. /// </summary> protected override async Task UpdateQuestionImplAsync() { DbContext.RemoveUnwantedObjects ( DbContext.ImportedClasses, importedClass => importedClass.Id, importedClass => importedClass.CodeQuestionId == Question.Id, Question.ImportedClasses ); var generateResult = await _questionGenerator.GenerateQuestionAsync(Question, 0); if (generateResult.Error != null) { Errors.AddError("GeneratorContents", generateResult.Error); } else { Question.DateModified = _timeProvider.UtcNow; Question.FullGeneratorFileContents = generateResult.FullGeneratorFileContents; Question.FullGeneratorFileLineOffset = generateResult.FullGeneratorFileLineOffset; } }