Ejemplo n.º 1
0
        /// <summary>
        /// Check for achievements that may have been earned
        /// </summary>
        /// <param name="streakId">The streak identifier.</param>
        private static void ProcessAchievements(int streakId)
        {
            var rockContext   = new RockContext();
            var streakService = new StreakService(rockContext);
            var streak        = streakService.Get(streakId);

            if (streak == null)
            {
                ExceptionLogService.LogException($"The streak with id {streakId} was not found (it may have been deleted)");
                return;
            }

            var streakTypeCache = StreakTypeCache.Get(streak.StreakTypeId);

            /*
             * 2019-01-13 BJW
             *
             * Achievements need to be processed in order according to dependencies (prerequisites). Prerequisites should be processed first so that,
             * if the prerequisite becomes completed, the dependent achievement will be processed at this time as well. Furthermore, each achievement
             * needs to be processed and changes saved to the database so that subsequent achievements will see the changes (for example: now met
             * prerequisites).
             */
            var sortedAchievementTypes = StreakTypeAchievementTypeService.SortAccordingToPrerequisites(streakTypeCache.StreakTypeAchievementTypes);

            foreach (var streakTypeAchievementTypeCache in sortedAchievementTypes)
            {
                var loopRockContext = new RockContext();
                var component       = streakTypeAchievementTypeCache.AchievementComponent;
                component.Process(loopRockContext, streakTypeAchievementTypeCache, streak);
                loopRockContext.SaveChanges();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start an async task to calculate steak data and then copy it to the enrollment model
        /// </summary>
        /// <param name="streakId">The streak identifier.</param>
        public static void RefreshStreakDenormalizedProperties(int streakId)
        {
            var rockContext       = new RockContext();
            var streakService     = new StreakService(rockContext);
            var streakTypeService = new StreakTypeService(rockContext);

            // Get the streak data and validate it
            var streakData = streakTypeService.GetStreakData(streakId, out var errorMessage);

            if (!errorMessage.IsNullOrWhiteSpace())
            {
                ExceptionLogService.LogException(errorMessage);
                return;
            }

            if (streakData == null)
            {
                ExceptionLogService.LogException("Streak Data was null, but no error was specified");
                return;
            }

            // Get the streak and apply updated information to it
            var streak = streakService.Get(streakId);

            if (streak == null)
            {
                ExceptionLogService.LogException($"The streak with id {streakId} was not found (it may have been deleted)");
                return;
            }

            CopyStreakDataToStreakModel(streakData, streak);
            rockContext.SaveChanges(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Check for achievements that may have been earned
        /// </summary>
        /// <param name="streakId">The streak identifier.</param>
        private static void ProcessAchievements(int streakId)
        {
            var rockContext   = new RockContext();
            var streakService = new StreakService(rockContext);
            var streak        = streakService.Get(streakId);

            if (streak == null)
            {
                ExceptionLogService.LogException($"The streak with id {streakId} was not found (it may have been deleted)");
                return;
            }

            var streakTypeCache = StreakTypeCache.Get(streak.StreakTypeId);

            foreach (var streakTypeAchievementTypeCache in streakTypeCache.StreakTypeAchievementTypes)
            {
                var component = streakTypeAchievementTypeCache.AchievementComponent;
                component.Process(rockContext, streakTypeAchievementTypeCache, streak);
            }

            rockContext.SaveChanges();
        }