Ejemplo n.º 1
0
 /// <summary>
 /// 读取规则目录下的文件
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="fileName">文件名</param>
 /// <returns></returns>
 private static T ParseSettings <T>(string fileName)
 {
     try
     {
         string path = SettingsPath + fileName;
         //T obj = (T)js.ReadObject(stream);
         string  cacheKey = "Settings$" + path;
         DoCache _cache   = new DoCache();
         if (_cache.GetCache(cacheKey) != null)
         {
             return((T)_cache.GetCache(cacheKey));
         }
         string json = Utils.LoadFile(path, "utf-8");
         byte[] bt   = Encoding.UTF8.GetBytes(json.Trim());
         DataContractJsonSerializer js = new DataContractJsonSerializer(typeof(T));
         MemoryStream stream           = new MemoryStream(bt);
         T            obj = (T)js.ReadObject(stream);
         _cache.SetCache(cacheKey, obj, 3600);
         return(obj);
     }
     catch (Exception e)
     {
         Logger.Error(e.ToString());
         //Console.WriteLine(SettingsPath);
         //throw(e);
     }
     return(default(T));
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据关键词,更新使用频率
        /// </summary>
        /// <param name="words">关键词列表</param>
        /// <param name="userKey">ip + 设备号</param>
        public static void ModifyWordUseFreq(List <string> words, string userKey)
        {
            if (words.Count < 1)
            {
                return;//没有关键词
            }
            string            _cacheKey = "ModifyWordUseFreq$" + userKey + "$";
            List <ModifyWord> list      = new List <ModifyWord>();

            foreach (string s in words)
            {
                if (string.IsNullOrEmpty(s))
                {
                    continue;
                }
                list.Add(new ModifyWord(s));
                _cacheKey += s;
            }
            DoCache _cache = new DoCache();
            var     data   = _cache.GetCache(_cacheKey);

            if (data != null)
            {
                return;//缓存存在的情况,不更新
            }
            RequestModifyWordBody body = new RequestModifyWordBody()
            {
                word_list = list
            };
            var response = DBHelper <ResponseWord> .GetResponse("ModifyWordUseFreq", JsonHelper.ObjectToJson(body), "", false);

            if (DBHelper <ResponseWord> .IsOK(response))
            {
                _cache.SetCache(_cacheKey, 1, 600);//缓存10分钟
            }
        }
Ejemplo n.º 3
0
        public ActionResult UserList()
        {
            UserResBody currResBody = new UserResBody();

            foreach (UserResBody item in base._userResBody)
            {
                if (item.res_path.Equals("0,1,107,118,121,"))
                {
                    currResBody = item;
                    break;
                }
            }

            HasPermission(currResBody.res_id);

            ViewData["currResBody"] = currResBody;//当前菜单
            string position = "";

            ViewData["pageTitle"] = base.FormatPageTile(currResBody, ref position);
            ViewData["position"]  = position;//页面位置

            int                  pagesize  = DoRequest.GetQueryInt("size", 60);
            int                  pageindex = DoRequest.GetQueryInt("page", 1);
            string               q         = DoRequest.GetQueryString("q");
            int                  state     = DoRequest.GetQueryInt("state", -1);
            int                  usertype  = DoRequest.GetQueryInt("usertype", -1);
            DateTime             date      = DateTime.Now.AddYears(-3);
            DateTime             sDate     = DoRequest.GetQueryDate("sDate", date);
            DateTime             eDate     = DoRequest.GetQueryDate("eDate", DateTime.Now);
            int                  dataCount = 0;
            int                  pageCount = 0;
            List <ShortUserInfo> infoList  = new List <ShortUserInfo>();
            DoCache              cache     = new DoCache();
            string               cachekey  = "user-QueryUserListindex=" + pageindex + "state=" + state + "type=" + usertype + "sdate=" + sDate.ToString("yyyy-MM-dd") + "edate=" + eDate.ToString("yyyy-MM-dd") + "q=" + q;

            if (cache.GetCache(cachekey) == null)
            {
                var resp = QueryUserList.Do(pagesize, pageindex, state, usertype, sDate.ToString("yyyy-MM-dd 00:00:00"), eDate.ToString("yyyy-MM-dd 23:59:59"), q, ref dataCount, ref pageCount);
                if (resp != null && resp.Body != null && resp.Body.user_list != null)
                {
                    infoList = resp.Body.user_list;
                    cache.SetCache(cachekey, infoList, 300);
                    cache.SetCache("userdatacount", dataCount, 300);
                    if (infoList.Count == 0)
                    {
                        cache.RemoveCache(cachekey);
                    }
                }
            }
            else
            {
                infoList  = (List <ShortUserInfo>)cache.GetCache(cachekey);
                dataCount = (int)cache.GetCache("userdatacount");
            }

            ViewData["infoList"] = infoList;                                         //数据列表

            System.Text.StringBuilder currPageUrl = new System.Text.StringBuilder(); //拼接当前页面URL
            currPageUrl.Append("/musers/userlist?");
            currPageUrl.Append("&size=" + pagesize);
            currPageUrl.Append("&page=" + pageindex);
            currPageUrl.Append("&q=" + DoRequest.UrlEncode(q));
            currPageUrl.Append("&state=" + state);
            currPageUrl.Append("&usertype=" + usertype);
            currPageUrl.Append("&sdate=" + sDate.ToString("yyyy-MM-dd"));
            currPageUrl.Append("&edate=" + eDate.ToString("yyyy-MM-dd"));
            ViewData["currPageUrl"] = currPageUrl;//当前页面的URL
            ViewData["pagesize"]    = pagesize;
            ViewData["pageindex"]   = pageindex;
            ViewData["dataCount"]   = dataCount;

            ViewData["pageIndexLink"]  = this.FormatPageIndex(dataCount, pagesize, pageindex, currPageUrl.ToString());
            ViewData["pageIndexLink2"] = this.FormatPageIndex(dataCount, pagesize, pageindex, currPageUrl.ToString());

            return(View());
        }