Пример #1
0
        public void Handler(DeleteWhisperEvent eventData)
        {
            _cacheClient.Remove(ConstantKey.CACHE_SQUARE_WHISPER);
            IList <Whisper> whispers = _whisperRepository.SelectByPage(1, 12).ToList();

            foreach (var item in whispers)
            {
                _cacheClient.AddListTail(ConstantKey.CACHE_SQUARE_WHISPER, item);
            }
            whispers = whispers.Take(6).ToList();
            Message message = new Message();

            //首页微语
            message.Data = whispers;
            _singalrContent.SendAllClientsMessage(message);
        }
Пример #2
0
        public async Task <IList <WhisperModel> > SelectByPageCache(int pageIndex, int pageSize)
        {
            JsonSerializerSettings jsonSerializerSettings = new JsonContractResolver().SetJsonSerializerSettings();
            IList <Whisper>        whispers = await _cacheClient.ListRange <Whisper>(ConstantKey.CACHE_SQUARE_WHISPER, pageIndex, pageSize, jsonSerializerSettings);

            if (whispers.Count == 0)
            {
                whispers = _whisperRepository.SelectByPage(1, 12).ToList();
                foreach (var item in whispers)
                {
                    await _cacheClient.AddListTail(ConstantKey.CACHE_SQUARE_WHISPER, item);
                }
                whispers = whispers.Take(6).ToList();
            }
            return(ConvertToModel(whispers));
        }
Пример #3
0
        public async Task <IList <WhisperDTO> > SelectPageCache(int pageIndex, int pageSize)
        {
            IList <WhisperDTO> whisperDTOs = await _cacheClient.ListRange <WhisperDTO>(ConstantKey.CACHE_SQUARE_WHISPER, pageIndex, pageSize);

            if (whisperDTOs.Count == 0)
            {
                Expression <Func <Whisper, DateTime> > orderBy = s => s.CreateTime;
                IList <Whisper>             whispers           = _whisperRepoistory.SelectByPage(1, 12, null, s => s.CreateTime).ToList();
                IEnumerable <string>        accounts           = whispers.Select(s => s.Account);
                Dictionary <string, string> accountWithName    = _userRepository.AccountWithName(accounts);
                foreach (var item in whispers)
                {
                    WhisperDTO whisperDTO = new WhisperDTO();
                    whisperDTO.Id          = item.Id.ToString();
                    whisperDTO.Account     = item.Account;
                    whisperDTO.AccountName = accountWithName[item.Account];
                    whisperDTO.Content     = item.Content;
                    whisperDTO.CreateDate  = item.CreateTime.ToString("yyyy-MM-dd HH:mm");
                    whisperDTOs.Add(whisperDTO);
                    await _cacheClient.AddListTail(ConstantKey.CACHE_SQUARE_WHISPER, whisperDTO);
                }
            }
            return(whisperDTOs);
        }