Exemplo n.º 1
0
        public int InitAnswers()
        {
            var dataSource = new KeyIndexedDataSource <Answer>();

            dataSource.Initialize(_answersRepository.Active());
            _cacheManager.Add(CacheConstants.CACHE_KEY_ANSWERS_DATA, dataSource);
            return(dataSource.Size);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get answer description flags data from cache or initialize if empty
        /// </summary>
        /// <returns></returns>
        private KeyIndexedDataSource <AnswerDescriptionFlag> GetUserDescriptionFlagsCachedData()
        {
            object data = _cacheManager.Get(CacheConstants.CACHE_KEY_USER_DESCRIPTION_FLAGS_DATA);

            if (data == null)
            {
                var dataSource = new KeyIndexedDataSource <AnswerDescriptionFlag>();
                dataSource.Initialize(_answerDescriptionFlagRepository.Active());
                _cacheManager.Add(CacheConstants.CACHE_KEY_USER_DESCRIPTION_FLAGS_DATA, dataSource);
                return(dataSource);
            }
            return((KeyIndexedDataSource <AnswerDescriptionFlag>)data);
        }
Exemplo n.º 3
0
        private KeyIndexedDataSource <Answer> GetCachedData()
        {
            object data = _cacheManager.Get(CacheConstants.CACHE_KEY_ANSWERS_DATA);

            if (data == null)
            {
                var dataSource = new KeyIndexedDataSource <Answer>();
                dataSource.Initialize(_repository.Active());
                _cacheManager.Add(CacheConstants.CACHE_KEY_ANSWERS_DATA, dataSource);
                return(dataSource);
            }
            return((KeyIndexedDataSource <Answer>)data);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get data indexed on the right word
        ///
        /// Load from normally cached data if empty.
        /// </summary>
        /// <returns></returns>
        private KeyIndexedDataSource <AnswerRightMask> GetRightCachedData()
        {
            object data = _cacheManager.Get(CacheConstants.CACHE_KEY_RIGHT_ANSWERS_DATA);

            if (data == null)
            {
                // Initialize from answers
                var dataSource      = GetCachedData();
                var allItems        = dataSource.All();
                var rightDataSource = new KeyIndexedDataSource <AnswerRightMask>();
                rightDataSource.Initialize(allItems.Select(x => new AnswerRightMask(x)));
                _cacheManager.Add(CacheConstants.CACHE_KEY_RIGHT_ANSWERS_DATA, rightDataSource);
                return(rightDataSource);
            }
            return((KeyIndexedDataSource <AnswerRightMask>)data);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get data indexed on the user id
        ///
        /// Load from normally cached data if empty.
        /// </summary>
        /// <returns></returns>
        private KeyIndexedDataSource <AnswerUserMask> GetUserCachedData()
        {
            object data = _cacheManager.Get(CacheConstants.CACHE_KEY_USER_ANSWERS_DATA);

            if (data == null)
            {
                // Initialize from answers
                var dataSource     = GetCachedData();
                var allItems       = dataSource.All();
                var userDataSource = new KeyIndexedDataSource <AnswerUserMask>();
                userDataSource.Initialize(allItems
                                          .Where(x => x.UserId != null)
                                          .Select(x => new AnswerUserMask(x)));
                _cacheManager.Add(CacheConstants.CACHE_KEY_USER_ANSWERS_DATA, userDataSource);
                return(userDataSource);
            }
            return((KeyIndexedDataSource <AnswerUserMask>)data);
        }