public static async Task SubmitScore(string courseId, Slide slide, string userId, int score, ILtiRequestsRepo ltiRequestsRepo, ILtiConsumersRepo consumersRepo) { var ltiRequestJson = await ltiRequestsRepo.Find(courseId, userId, slide.Id); if (ltiRequestJson == null) { throw new Exception("LtiRequest for user '" + userId + "' not found"); } var ltiRequest = JsonConvert.DeserializeObject <LtiRequest>(ltiRequestJson); var consumerSecret = (await consumersRepo.Find(ltiRequest.ConsumerKey)).Secret; log.Info($"Надо отправить результаты слайда {slide.Id} пользователя {userId} по LTI. Нашёл LtiRequest: {ltiRequestJson}"); UriBuilder uri; try { uri = new UriBuilder(ltiRequest.LisOutcomeServiceUrl); } catch (Exception e) { log.Error(e, $"Неверный адрес отправки результатов по LTI: {ltiRequest.LisOutcomeServiceUrl}"); throw; } if (uri.Host == "localhost") { uri.Host = "192.168.33.10"; uri.Port = 80; uri.Scheme = "http"; } var maxScore = BaseController.GetMaxScoreForUsersSlide(slide, true, false, false); var outputScore = score / (double)maxScore; log.Info($"Отправляю результаты на {ltiRequest.LisOutcomeServiceUrl}: {score} из {maxScore} ({outputScore})"); /* Sometimes score is bigger then slide's MaxScore, i.e. in case of manual checking */ if (score > maxScore) { outputScore = 1; } var result = OutcomesClient.PostScore(uri.ToString(), ltiRequest.ConsumerKey, consumerSecret, ltiRequest.LisResultSourcedId, outputScore); if (!result.IsValid) { throw new Exception(uri + "\r\n\r\n" + result.Message); } }
public async Task ProcessResult(UserExerciseSubmission submission, RunningResults result) { var ltiRequestJson = await ltiRequestsRepo.Find(submission.CourseId, submission.UserId, submission.SlideId); if (ltiRequestJson != null) { try { var exerciseSlide = (await courseManager.FindCourseAsync(submission.CourseId)).FindSlideById(submission.SlideId, true) as ExerciseSlide; var score = await visitsRepo.GetScore(submission.CourseId, submission.SlideId, submission.UserId); await LtiUtils.SubmitScore(exerciseSlide, submission.UserId, score, ltiRequestJson, ltiConsumersRepo); } catch (Exception e) { log.Error(e, "Мы не смогли отправить баллы на образовательную платформу"); } } }