Пример #1
0
        public static void SubmitScore(Slide slide, string userId)
        {
            var ltiRequestsRepo = new LtiRequestsRepo();
            var consumersRepo   = new ConsumersRepo();
            var visitsRepo      = new VisitsRepo();

            var ltiRequest = ltiRequestsRepo.Find(userId, slide.Id);

            if (ltiRequest == null)
            {
                throw new Exception("LtiRequest for user '" + userId + "' not found");
            }

            var consumerSecret = consumersRepo.Find(ltiRequest.ConsumerKey).Secret;

            var score = visitsRepo.GetScore(slide.Id, userId);

            // TODO: fix outcome address in local edx (no localhost and no https)
            var uri = new UriBuilder(ltiRequest.LisOutcomeServiceUrl);

            if (uri.Host == "localhost")
            {
                uri.Host   = "192.168.33.10";
                uri.Port   = 80;
                uri.Scheme = "http";
            }

            var result = OutcomesClient.PostScore(uri.ToString(), ltiRequest.ConsumerKey, consumerSecret,
                                                  ltiRequest.LisResultSourcedId, score / (double)slide.MaxScore);

            if (!result.IsValid)
            {
                throw new Exception(uri + "\r\n\r\n" + result.Message);
            }
        }
Пример #2
0
        public static void SubmitScore(string courseId, Slide slide, string userId, Visit visit = null)
        {
            var db = new ULearnDb();
            var ltiRequestsRepo = new LtiRequestsRepo(db);
            var consumersRepo   = new ConsumersRepo(db);
            var visitsRepo      = new VisitsRepo(db);

            var ltiRequest = ltiRequestsRepo.Find(courseId, userId, slide.Id);

            if (ltiRequest == null)
            {
                throw new Exception("LtiRequest for user '" + userId + "' not found");
            }

            var consumerSecret = consumersRepo.Find(ltiRequest.ConsumerKey).Secret;

            var score = visit?.Score ?? visitsRepo.GetScore(courseId, slide.Id, userId);

            log.Info($"Надо отправить результаты слайда {slide.Id} пользователя {userId} по LTI. Нашёл LtiRequest: {ltiRequest.JsonSerialize()}");
            UriBuilder uri;

            try
            {
                uri = new UriBuilder(ltiRequest.LisOutcomeServiceUrl);
            }
            catch (Exception e)
            {
                log.Error($"Неверный адрес отправки результатов по LTI: {ltiRequest.LisOutcomeServiceUrl}", e);
                throw;
            }

            if (uri.Host == "localhost")
            {
                uri.Host   = "192.168.33.10";
                uri.Port   = 80;
                uri.Scheme = "http";
            }

            var maxScore    = ControllerUtils.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);
            }
        }
Пример #3
0
 public CourseController()
 {
     slideCheckingsRepo = new SlideCheckingsRepo(db);
     visitsRepo         = new VisitsRepo(db);
     unitsRepo          = new UnitsRepo(db);
     slideRateRepo      = new SlideRateRepo(db);
     solutionsRepo      = new UserSolutionsRepo(db, courseManager);
     ltiRequestsRepo    = new LtiRequestsRepo(db);
     groupsRepo         = new GroupsRepo(db, courseManager);
     userQuizzesRepo    = new UserQuizzesRepo(db);
     coursesRepo        = new CoursesRepo(db);
 }
Пример #4
0
        private static async Task ResendLti(UlearnDb db)
        {
            var ltiRequestsRepo    = new LtiRequestsRepo(db);
            var ltiConsumersRepo   = new LtiConsumersRepo(db);
            var slideCheckingsRepo = new SlideCheckingsRepo(db, null);
            var visitsRepo         = new VisitsRepo(db, slideCheckingsRepo);
            var ltiRequests        = await db.LtiRequests.Where(r => r.RequestId > 284927).OrderByDescending(r => r.RequestId).ToListAsync();

            var courseManager = new CourseManager(CourseManager.GetCoursesDirectory());

            var i = 0;

            foreach (var ltiRequest in ltiRequests)
            {
                var course = courseManager.GetCourse(ltiRequest.CourseId);
                var slide  = course.GetSlideById(ltiRequest.SlideId, true);
                var score  = await visitsRepo.GetScore(ltiRequest.CourseId, ltiRequest.SlideId, ltiRequest.UserId);

                await LtiUtils.SubmitScore(ltiRequest.CourseId, slide, ltiRequest.UserId, score, ltiRequestsRepo, ltiConsumersRepo);

                i++;
                Console.WriteLine($"{i} requestId {ltiRequest.RequestId} score {score}");
            }
        }