Beispiel #1
0
        public async Task <Course> GetCourseAsync(CoursesRepo coursesRepo, string courseId)
        {
            Course course;

            try
            {
                course = base.GetCourse(courseId);
            }
            catch (KeyNotFoundException)
            {
                course = null;
            }

            if (IsCourseVersionWasUpdatedRecent(courseId))
            {
                return(course ?? throw new CourseNotFoundException(courseId));
            }

            courseVersionFetchTime[courseId] = DateTime.Now;

            var publishedVersion = await coursesRepo.GetPublishedCourseVersionAsync(courseId).ConfigureAwait(false);

            if (publishedVersion == null)
            {
                return(course ?? throw new CourseNotFoundException(courseId));
            }

            ReloadCourseIfLoadedAndPublishedVersionsAreDifferent(courseId, publishedVersion);
            return(base.GetCourse(courseId));
        }
Beispiel #2
0
        public override Course GetCourse(string courseId)
        {
            var course = base.GetCourse(courseId);

            if (IsCourseVersionWasUpdatedRecent(courseId))
            {
                return(course);
            }

            courseVersionFetchTime[courseId] = DateTime.Now;
            var coursesRepo      = new CoursesRepo();
            var publishedVersion = coursesRepo.GetPublishedCourseVersion(courseId);

            if (publishedVersion == null)
            {
                return(course);
            }

            lock (@lock)
            {
                Guid loadedVersionId;
                if (loadedCourseVersions.TryGetValue(courseId, out loadedVersionId) &&
                    loadedVersionId != publishedVersion.Id)
                {
                    log.Info($"Загруженная версия курса {courseId} отличается от актуальной. Обновляю курс.");
                    course = ReloadCourse(courseId);
                }
                loadedCourseVersions[courseId] = publishedVersion.Id;
            }
            return(course);
        }
Beispiel #3
0
 public CommentsController(ULearnDb db)
 {
     commentsRepo       = new CommentsRepo(db);
     userManager        = new ULearnUserManager(db);
     notificationsRepo  = new NotificationsRepo(db);
     coursesRepo        = new CoursesRepo(db);
     systemAccessesRepo = new SystemAccessesRepo(db);
 }
Beispiel #4
0
        public override Course GetCourse(string courseId)
        {
            Course course;

            try
            {
                LoadCoursesIfNotYet();
                TryReloadTempCourseIfNecessary(courseId);
                course = base.GetCourse(courseId);
            }
            catch (Exception e) when(e is KeyNotFoundException || e is CourseNotFoundException || e is CourseLoadingException)
            {
                course = null;
            }
            catch (AggregateException e)
            {
                var ie = e.InnerException;
                if (ie is KeyNotFoundException || ie is CourseNotFoundException || ie is CourseLoadingException)
                {
                    course = null;
                }
                else
                {
                    throw;
                }
            }

            if (IsCourseVersionWasUpdatedRecent(courseId) || CourseIsBroken(courseId))
            {
                return(course ?? throw new KeyNotFoundException($"Key {courseId} not found"));
            }

            courseVersionFetchTime[courseId] = DateTime.Now;
            var coursesRepo      = new CoursesRepo();
            var publishedVersion = coursesRepo.GetPublishedCourseVersion(courseId);

            if (publishedVersion == null)
            {
                return(course ?? throw new KeyNotFoundException($"Key {courseId} not found"));
            }

            lock (@lock)
            {
                if (loadedCourseVersions.TryGetValue(courseId.ToLower(), out var loadedVersionId) &&
                    loadedVersionId != publishedVersion.Id)
                {
                    log.Info($"Загруженная версия курса {courseId} отличается от актуальной ({loadedVersionId.ToString()} != {publishedVersion.Id}). Обновляю курс.");
                    if (TryReloadCourse(courseId))
                    {
                        course = base.GetCourse(courseId);
                    }
                }

                loadedCourseVersions[courseId.ToLower()] = publishedVersion.Id;
            }

            return(course ?? throw new KeyNotFoundException($"Key {courseId} not found"));
        }
Beispiel #5
0
 public UnitofWork(string connectionString, string migrationAssemblyName)
 {
     _context           = new UniversityContext(connectionString, migrationAssemblyName);
     _departmentsRepo   = new DepartmentsRepo(_context);
     _studentsRepo      = new StudentsRepo(_context);
     _coursesRepo       = new CoursesRepo(_context);
     _instructorRepo    = new InstructorRepo(_context);
     _studentCourseRepo = new StudentCourseRepo(_context);
 }
Beispiel #6
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);
 }
Beispiel #7
0
        public AccountController()
        {
            userRolesRepo      = new UserRolesRepo(db);
            groupsRepo         = new GroupsRepo(db, courseManager);
            certificatesRepo   = new CertificatesRepo(db);
            visitsRepo         = new VisitsRepo(db);
            notificationsRepo  = new NotificationsRepo(db);
            coursesRepo        = new CoursesRepo(db);
            systemAccessesRepo = new SystemAccessesRepo(db);

            telegramSecret = WebConfigurationManager.AppSettings["ulearn.telegram.webhook.secret"] ?? "";
        }
Beispiel #8
0
 public GroupAccessesRepo(
     UlearnDb db,
     GroupsRepo groupsRepo, SystemAccessesRepo systemAccessesRepo, CoursesRepo coursesRepo,
     WebCourseManager courseManager
     )
 {
     this.db                 = db;
     this.groupsRepo         = groupsRepo;
     this.systemAccessesRepo = systemAccessesRepo;
     this.coursesRepo        = coursesRepo;
     this.courseManager      = courseManager;
 }
Beispiel #9
0
 public AccountController(
     ILogger logger, IOptions <WebApiConfiguration> options, WebCourseManager courseManager, UlearnDb db, UlearnUserManager userManager, SignInManager <ApplicationUser> signInManager,
     UserRolesRepo userRolesRepo, CoursesRepo coursesRepo
     )
     : base(logger, courseManager, db)
 {
     this.userManager   = userManager;
     this.signInManager = signInManager;
     this.userRolesRepo = userRolesRepo;
     this.coursesRepo   = coursesRepo;
     this.configuration = options.Value;
 }
Beispiel #10
0
        private void GetList()
        {
            Courses     courses      = new Courses();
            CoursesRepo Repo         = new CoursesRepo(courses);
            int         universityId = int.Parse(Helper.GetParameterFromRequest("universityId"));

            if (Repo.Query(universityId))
            {
                Helper.Response(courses.Serialize());
            }
            else
            {
                Helper.ResponseError(Repo.ErrorMessage);
            }
        }
Beispiel #11
0
        protected override void LoadCourseZipsToDiskFromExternalStorage(IEnumerable <string> existingOnDiskCourseIds)
        {
            log.Info($"Загружаю курсы из БД");
            var coursesRepo = new CoursesRepo();
            var files       = coursesRepo.GetCourseFiles(existingOnDiskCourseIds);

            foreach (var zipFile in files)
            {
                try
                {
                    var stagingCourseFile = GetStagingCourseFile(zipFile.CourseId);
                    File.WriteAllBytes(stagingCourseFile.FullName, zipFile.File);
                    var versionCourseFile = GetCourseVersionFile(zipFile.CourseVersionId);
                    if (!versionCourseFile.Exists)
                    {
                        File.WriteAllBytes(versionCourseFile.FullName, zipFile.File);
                    }
                }
                catch (Exception ex)
                {
                    log.Error(ex, $"Не смог загрузить {zipFile.CourseId} из базы данных");
                }
            }
        }
Beispiel #12
0
        public static bool HasCourseAccess(this IPrincipal User, string courseId, CourseAccessType accessType)
        {
            var coursesRepo = new CoursesRepo();

            return(coursesRepo.HasCourseAccess(User.Identity.GetUserId(), courseId, accessType));
        }
Beispiel #13
0
        public static bool HasCourseAccess(this ApplicationUser User, string courseId, CourseAccessType accessType)
        {
            var coursesRepo = new CoursesRepo();

            return(coursesRepo.HasCourseAccess(User.Id, courseId, accessType));
        }
Beispiel #14
0
 public WebCourseManager(CoursesRepo coursesRepo)
     : base(GetCoursesDirectory())
 {
     this.coursesRepo = coursesRepo;
 }
 public CourseAccessAuthorizationHandler(CoursesRepo coursesRepo, UserRolesRepo userRolesRepo, ILogger logger)
 {
     this.coursesRepo   = coursesRepo;
     this.userRolesRepo = userRolesRepo;
     this.logger        = logger;
 }
Beispiel #16
0
 public DAL(EDbContext db)
 {
     Users   = new UsersRepo(db);
     Courses = new CoursesRepo(db);
     Files   = new FilesRepo(db);
 }