Beispiel #1
0
 /// <summary>
 /// 将关键词列表写入存储
 /// </summary>
 /// <param name="filterWords"></param>
 public static void SensitiveWordsStorage(this FilterWords filterWords)
 {
     using (MongoDbContext mc = new MongoDbContext(Const.ConfigsMongoDbConn))
     {
         FilterWords orgWords = mc.Collection <FilterWords>().Linq().FirstOrDefault();
         if (null == orgWords)
         {
             mc.Collection <FilterWords>().Insert(filterWords);
         }
         else
         {
             mc.Collection <FilterWords>().Update(filterWords, orgWords);
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// 获取关键词列表
        /// </summary>
        /// <returns></returns>
        public static IEnumerable <string> GetSensitiveWords()
        {
            object cacheVal = Const.CoreCacheName.GetCache(CacheKey);

            if (null != cacheVal && cacheVal is FilterWords)
            {
                return(((FilterWords)cacheVal).Words);
            }

            FilterWords words = GetSensitiveWordsFromStorage();

            if (null == words)
            {
                return(new List <string>(0));
            }

            Const.CoreCacheName.SetCache(CacheKey, words);
            return(words.Words);
        }