예제 #1
0
        private void TryCheckTempCoursesAndReloadIfNecessary(string courseIdToUpdate = null)
        {
            try
            {
                if (new DateTime(tempCoursesUpdateTime) > DateTime.Now.Subtract(tempCourseUpdateEvery))
                {
                    return;
                }
                if (courseIdToUpdate != null && IsTempCourseUpdatedRecent(courseIdToUpdate))
                {
                    return;
                }
                if (courseIdToUpdate == null)
                {
                    Interlocked.Exchange(ref tempCoursesUpdateTime, DateTime.Now.Ticks);
                }

                var tempCoursesRepo = new TempCoursesRepo();
                var tempCourses     = tempCoursesRepo.GetTempCourses();
                foreach (var tempCourse in tempCourses)
                {
                    var    courseId = tempCourse.CourseId;
                    Course course   = null;
                    try
                    {
                        course = base.GetCourse(courseId);                         // Не используется FindCourse, иначе бесконечная рекурсия
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                    if (course == null || course.GetSlides(true).Count == 0 ||
                        courseId == courseIdToUpdate && tempCourse.LastUpdateTime < tempCourse.LoadingTime)
                    {
                        TryReloadCourse(courseId);
                        tempCoursesRepo.UpdateTempCourseLastUpdateTimeAsync(courseId).Wait();
                        courseVersionFetchTime[courseId] = DateTime.Now;
                    }
                    else if (tempCourse.LastUpdateTime > tempCourse.LoadingTime)
                    {
                        courseVersionFetchTime[courseId] = DateTime.Now;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
예제 #2
0
        private void TryCheckTempCoursesAndReloadIfNecessary()
        {
            try
            {
                if (new DateTime(allTempCoursesUpdateTime) > DateTime.Now.Subtract(allTempCoursesUpdateEvery))
                {
                    return;
                }
                Interlocked.Exchange(ref allTempCoursesUpdateTime, DateTime.Now.Ticks);

                var tempCourses = GetTempCoursesWithCache();
                foreach (var tempCourse in tempCourses)
                {
                    var courseId = tempCourse.CourseId;
                    if (CourseIsBroken(courseId))
                    {
                        continue;
                    }
                    Course course = null;
                    try
                    {
                        course = base.GetCourse(courseId);                         // Не используется FindCourse, иначе бесконечная рекурсия
                    }
                    catch (Exception ex)
                    {
                        log.Error(ex);
                    }
                    if (course == null || course.GetSlides(true).Count == 0)
                    {
                        TryReloadCourse(courseId);
                        var tempCoursesRepo = new TempCoursesRepo();
                        tempCoursesRepo.UpdateTempCourseLastUpdateTime(courseId);
                        courseVersionFetchTime[courseId] = DateTime.Now;
                    }
                    else if (tempCourse.LastUpdateTime > tempCourse.LoadingTime)
                    {
                        courseVersionFetchTime[courseId] = DateTime.Now;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }