public ActionResult GetSubnetDeviceStatus(int sId) { var result = new JsonResult(); try { string key = string.Format("subnet_device_status_{0}", sId); var nodeStatus = MemoryCacheHelper.GetCacheItem<List<TopoNodeStatus>>(key, () => { IEnumerable<Device> devices = null; using (var ctx = new GlsunViewEntities()) { devices = ctx.Device.Where(d => d.SID == sId).ToList(); } List<TopoNodeStatus> status = new List<TopoNodeStatus>(); foreach (var d in devices) { status.Add(DeviceStatusGetter.GetDeviceStatus(d)); } return status; }, null, DateTime.Now.AddSeconds(5)); result.Data = new { Code = "", Data = nodeStatus }; } catch (Exception ex) { result.Data = new { Code = "Exception", Data = ex.Message }; } return result; }
public string CheckUpdate(string currentVersion) { try { string[] verStrs = MemoryCacheHelper.GetCacheItem <string[]>("upcache", () => { string updatePath = ConfigHelper.GetConfigString("ClientUpdateDir", "", true); if (string.IsNullOrWhiteSpace(updatePath)) { return(null); } string[] ups = Directory.GetDirectories(updatePath, "*", SearchOption.TopDirectoryOnly); string newdir = ups.Max(); //DateTime UpTime = DateTime.ParseExact(Path.GetFileNameWithoutExtension(newdir), "yyyyMMddHHmmss", System.Globalization.CultureInfo.InvariantCulture); string[] lines = File.ReadAllLines(newdir + "\\Version.txt"); string newVersion = lines[0]; //string upStr = null; string nvText = StringPlus.GetArrayStr(lines, Environment.NewLine); //string[] apps = Directory.GetFiles(newdir, "*.exe", SearchOption.TopDirectoryOnly); //string newApp = apps.Max(); //string[] otas = Directory.GetFiles(newdir + "\\ota", "*", SearchOption.AllDirectories); //string otastr = StringPlus.GetArrayStr(otas, ";"); //List<string> list = new List<string>(); //list.Add("Update"); //list.Add(DateTimeHelper.TimeToStamp(UpTime).ToString()); //list.Add(newVersion); //list.Add(nvText); //list.Add(newApp); //list.Add(otastr); //upStr = StringPlus.GetArrayStr(list); return(new[] { newVersion, nvText }); }, DateTime.Now.AddMinutes(15)); if (verStrs != null) { string newVersion = verStrs[0]; if (String.CompareOrdinal(currentVersion, newVersion) >= 0) { return(null); } else { return(verStrs[1]); } } else { return(null); } } catch (Exception e) { LogHelper.Log.Error("获取客户端更新信息失败", e); return(null); } }
/// <summary> /// 获取子网状态 /// </summary> /// <returns></returns> public ActionResult GetSubnetStatus() { var result = new JsonResult(); try { var nodeStatus = MemoryCacheHelper.GetCacheItem<List<TopoNodeStatus>>("subnet_status", () => { IEnumerable<Subnet> nets = null; using (var ctx = new GlsunViewEntities()) { nets = ctx.Subnet.ToList(); } List<TopoNodeStatus> status = new List<TopoNodeStatus>(); foreach (var n in nets) { status.Add(DeviceStatusGetter.GetSubnetStatus(n)); } return status; }, null, DateTime.Now.AddSeconds(10)); result.Data = new { Code = "", Data = nodeStatus }; } catch (Exception ex) { result.Data = new { Code = "Exception", Data = ex.Message }; } return result; }
public static List <string> GetMoguProxyListFromCache() { var fullName = MemoryCacheHelper.GetCacheItem <List <string> >("moguproxyList", delegate() { var res = HttpClientHolder.GetRequest("http://piping.mogumiao.com/proxy/api/get_ip_bs?appKey=e7178154a26948f38f155af1e4f7a440&count=5&expiryDate=0&format=1&newLine=2"); while (res.IndexOf("提取频繁请按照规定频率提取") >= 0) { System.Threading.Thread.Sleep(10000); res = HttpClientHolder.GetRequest("http://piping.mogumiao.com/proxy/api/get_ip_bs?appKey=e7178154a26948f38f155af1e4f7a440&count=5&expiryDate=0&format=1&newLine=2"); } List <string> listProxy = new List <string>(); var jarray = JObject.Parse(res)["msg"] as JArray; foreach (var jitem in jarray) { listProxy.Add($"{jitem["ip"].NullToString()}:{jitem["port"].NullToString()}"); } return(listProxy); }, new TimeSpan(0, 0, 30));//30分钟过期 return(fullName); }
protected override void OnLoad(EventArgs e) { #region GridControl中特殊字段绑定 DataTable dicDpt = Tmo_FakeEntityClient.Instance.GetData("tmo_department", new[] { "dpt_id", "dpt_name", "dpt_parent" }, "dpt_id in (" + TmoComm.login_docInfo.children_department + "," + TmoComm.login_docInfo.doc_department + ")"); DataRow dr1 = dicDpt.NewRow(); dr1["dpt_id"] = -1; dr1["dpt_name"] = "无部门"; dicDpt.Rows.Add(dr1); TSCommon.BindRepositoryImageComboBox(rp_doc_department, dicDpt, "dpt_name", "dpt_id"); DataTable dicGroup = MemoryCacheHelper.GetCacheItem <DataTable>("tmo_docgroup", () => Tmo_FakeEntityClient.Instance.GetData("tmo_docgroup", new[] { "group_id", "group_name" }, "group_level>=" + TmoComm.login_docInfo.doc_group_level), DateTime.Now.AddMinutes(5)); DataTable dicGroupCp = dicGroup.Copy(); DataRow dr2 = dicGroupCp.NewRow(); dr2["group_id"] = -1; dr2["group_name"] = "无群组"; dicGroupCp.Rows.Add(dr2); TSCommon.BindRepositoryImageComboBox(rp_doc_group, dicGroupCp, "group_name", "group_id"); #endregion #region 查询条件绑定 UCTreeListSelector selCheck = new UCTreeListSelector(false); DataRow[] drs = dicDpt.Select("dpt_id=" + TmoComm.login_docInfo.doc_department); for (int i = 0; i < drs.Length; i++) { dicDpt.Rows.Remove(drs[i]); } selCheck.InitData(doc_department, dicDpt, "dpt_id", "dpt_parent", "dpt_name", true); TSCommon.BindImageComboBox(doc_group, dicGroup, "", "group_name", "group_id", true); #endregion base.OnLoad(e); }
public ActionResult GetRealTimeAlarmCount() { JsonResult json = new JsonResult(); json.JsonRequestBehavior = JsonRequestBehavior.AllowGet; /*int criticalCount = 0; * int majorCount = 0; * int minorCount = 0; * int warnCount = 0; * int normalCount = 0; * //统计未确认告警 * using(var ctx = new GlsunViewEntities()) * { * criticalCount = ctx.AlarmInformation.Where(a => a.AIConfirm == false && a.AILevel == "CRITICAL").Count(); * majorCount = ctx.AlarmInformation.Where(a => a.AIConfirm == false && a.AILevel == "MAJOR").Count(); * minorCount = ctx.AlarmInformation.Where(a => a.AIConfirm == false && a.AILevel == "MINOR").Count(); * warnCount = ctx.AlarmInformation.Where(a => a.AIConfirm == false && a.AILevel == "WARN").Count(); * normalCount = ctx.AlarmInformation.Where(a => a.AIConfirm == false && a.AILevel == "NORMAL").Count(); * } * json.Data = new * { * critical = criticalCount, * major = majorCount, * minor = minorCount, * warn = warnCount, * normal = normalCount * };*/ var data = MemoryCacheHelper.GetCacheItem <object>("alarm_statistics", () => { int criticalCount = 0; int majorCount = 0; int minorCount = 0; int warnCount = 0; int normalCount = 0; //统计未确认告警 using (var ctx = new GlsunViewEntities()) { criticalCount = ctx.AlarmInformation.Where(a => a.AIConfirm == false && a.AILevel == "CRITICAL").Count(); majorCount = ctx.AlarmInformation.Where(a => a.AIConfirm == false && a.AILevel == "MAJOR").Count(); minorCount = ctx.AlarmInformation.Where(a => a.AIConfirm == false && a.AILevel == "MINOR").Count(); warnCount = ctx.AlarmInformation.Where(a => a.AIConfirm == false && a.AILevel == "WARN").Count(); normalCount = ctx.AlarmInformation.Where(a => a.AIConfirm == false && a.AILevel == "NORMAL").Count(); } return(new { critical = criticalCount, major = majorCount, minor = minorCount, warn = warnCount, normal = normalCount }); }, null, DateTime.Now.AddSeconds(5)); json.Data = data; return(json); }
void UCUserEditor_Load(object sender, EventArgs e) { //读取民族数据 DataTable dicNation = MemoryCacheHelper.GetCacheItem <DataTable>("nationality", () => { return(Tmo_FakeEntityClient.Instance.GetData("tmo_nationality", new[] { "code", "name" })); }, DateTime.Now.AddHours(24)); //由于民族数据基本不变 24小时过期 TSCommon.BindImageComboBox(nation, dicNation, null, "name", "code", true); birthday.EditValue = DateTime.Now.Date; //绑定婚姻状况 DataTable dicMarital = MemoryCacheHelper.GetCacheItem <DataTable>("marital", () => { return(Tmo_FakeEntityClient.Instance.GetData("tmo_marital")); }, DateTime.Now.AddHours(24)); TSCommon.BindImageComboBox(marital, dicMarital, null, "name", "code", true); //绑定省数据 DataTable dicProvincecode = MemoryCacheHelper.GetCacheItem <DataTable>("provincecode", () => Tmo_FakeEntityClient.Instance.GetData("tmo_provincecode"), DateTime.Now.AddHours(24)); province_id.SelectedValueChanged += (object sender0, EventArgs e0) => {//绑定市数据 city_id.Enabled = province_id.EditValue != null; DataTable dicCitycode = MemoryCacheHelper.GetCacheItem <DataTable>("citycode", () => Tmo_FakeEntityClient.Instance.GetData("tmo_citycode"), DateTime.Now.AddHours(24)); TSCommon.BindImageComboBox(city_id, dicCitycode, "province_id='" + province_id.EditValue + "'", "city_name", "city_id", true); }; city_id.SelectedValueChanged += (object sender0, EventArgs e0) => {//绑定区数据 eare_id.Enabled = city_id.EditValue != null; DataTable dicAreacode = MemoryCacheHelper.GetCacheItem <DataTable>("areacode", () => Tmo_FakeEntityClient.Instance.GetData("tmo_areacode"), DateTime.Now.AddHours(24)); TSCommon.BindImageComboBox(eare_id, dicAreacode, "city_id='" + city_id.EditValue + "'", "area_name", "area_id", true); }; TSCommon.BindImageComboBox(province_id, dicProvincecode, null, "province_name", "province_id", true); //绑定职业类型 DataTable dicOccupation = MemoryCacheHelper.GetCacheItem <DataTable>("occupation", () => { return(Tmo_FakeEntityClient.Instance.GetData("tmo_occupation")); }, DateTime.Now.AddHours(24)); TSCommon.BindImageComboBox(occupation, dicOccupation, null, "name", "code", true); //绑定文化程度 DataTable dicEducation = MemoryCacheHelper.GetCacheItem <DataTable>("education", () => { return(Tmo_FakeEntityClient.Instance.GetData("tmo_education")); }, DateTime.Now.AddHours(24)); TSCommon.BindImageComboBox(education, dicEducation, null, "name", "code", true); InitValidationRules(); DataTable dicDpt = Tmo_FakeEntityClient.Instance.GetData("tmo_department", new[] { "dpt_id", "dpt_name", "dpt_parent" }, "dpt_id in (" + TmoComm.login_docInfo.children_department + ")"); selCheck.InitData(dpt_id, dicDpt, "dpt_id", "dpt_parent", "dpt_name"); }
private void btnMemory_Click(object sender, EventArgs e) { string key = "MemoryTest1"; string fullName = MemoryCacheHelper.GetCacheItem <string>(key, delegate() { return("这里可以写Factory方法去查询并缓存到内存中时间为30分钟"); }, new TimeSpan(0, 30, 0));//30分钟过期 MessageDxUtil.ShowTips(fullName); }
/// <summary> /// 获取用户全部简单对象信息,并放到缓存里面 /// </summary> /// <returns></returns> public static List <SimpleUserInfo> GetSimpleUsers() { System.Reflection.MethodBase method = System.Reflection.MethodBase.GetCurrentMethod(); string key = string.Format("{0}-{1}", method.DeclaringType.FullName, method.Name); return(MemoryCacheHelper.GetCacheItem <List <SimpleUserInfo> >(key, delegate() { return BLLFactory <User> .Instance.GetSimpleUsers(); }, new TimeSpan(0, 10, 0)));//10分钟过期 }
/// <summary> /// 使用分布式缓存实现菜单数据的缓存处理 /// </summary> /// <returns></returns> public string GetMenuStringCache() { string itemValue = MemoryCacheHelper.GetCacheItem <string>("GetMenuStringCache_" + CurrentUser.ID, delegate() { return(GetMenuString()); }, null, DateTime.Now.AddMinutes(5) //5分钟以后过期,重新获取 ); return(itemValue); }
/// <summary> /// 根据ID获取供应商名称 /// </summary> /// <param name="id">对象ID</param> /// <param name="trans">事务对象</param> /// <returns></returns> public string GetNameById(string id, DbTransaction trans = null) { System.Reflection.MethodBase method = System.Reflection.MethodBase.GetCurrentMethod(); string key = string.Format("{0}-{1}-{2}", method.DeclaringType.FullName, method.Name, id); string name = MemoryCacheHelper.GetCacheItem <string>(key, delegate() { return(GetFieldValue(id, "Name", trans)); }, new TimeSpan(0, 30, 0)); return(name); }
/// <summary> /// 获取每次操作微信API的Token访问令牌 /// </summary> /// <param name="appid">应用ID</param> /// <param name="secret">开发者凭据</param> /// <returns></returns> public static string GetAccessToken(string appId, string appSecret) { //正常情况下access_token有效期为7200秒,这里使用缓存设置短于这个时间即可 string access_token = MemoryCacheHelper.GetCacheItem <string>("access_token", delegate() { var credential = ClientCredential.GetCredential(appId, appSecret); return(credential.access_token); }, new TimeSpan(0, 0, 600)//300秒过期 , DateTime.Now.AddSeconds(600) ); return(access_token); }
/// <summary> /// 根据城市ID获取对应的行政区划类别 /// </summary> /// <param name="cityName">城市名称</param> /// <returns></returns> public ActionResult GetDistrictByCityDictJson(string cityId) { #region 常规处理 //List<CListItem> treeList = new List<CListItem>(); //CListItem pNode = new CListItem("选择记录", ""); //treeList.Add(pNode); //if (!string.IsNullOrEmpty(cityId)) //{ // List<DistrictInfo> districtList = BLLFactory<District>.Instance.GetDistrictByCity(cityId); // foreach (DistrictInfo info in districtList) // { // CListItem item = new CListItem(info.DistrictName, info.ID.ToString()); // treeList.Add(item); // } //} //return ToJsonContent(treeList); #endregion #region 使用MemoryCache缓存提高速度 System.Reflection.MethodBase method = System.Reflection.MethodBase.GetCurrentMethod(); string key = string.Format("{0}-{1}-{2}", method.DeclaringType.FullName, method.Name, cityId); var result = MemoryCacheHelper.GetCacheItem <ActionResult>(key, delegate() { List <CListItem> treeList = new List <CListItem>(); CListItem pNode = new CListItem("选择记录", ""); treeList.Add(pNode); if (!string.IsNullOrEmpty(cityId)) { List <DistrictInfo> districtList = BLLFactory <District> .Instance.GetDistrictByCity(cityId); foreach (DistrictInfo info in districtList) { CListItem item = new CListItem(info.DistrictName, info.ID.ToString()); treeList.Add(item); } } return(ToJsonContent(treeList)); }, new TimeSpan(0, 30, 0));//30分钟过期 return(result); #endregion }
private static string GetToken(string sToken, string appid, string secret) { var ourUrl = ConfigurationManager.AppSettings["WeChatTokenRequestURL"]; return(MemoryCacheHelper.GetCacheItem <string>("access_token" + sToken, delegate() { var token = String.Empty; string grant_type = "client_credential"; var url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type={0}&appid={1}&secret={2}", grant_type, appid, secret); var result = HttpUtil.GetHtml(ourUrl); string ourRegex = "\"success\"\\s*?:\\s*?(?<success>.*?),.*?\"data\"\\s*?:\\s*?\"(?<token>.*?)\""; var success = Regex.Match(result, ourRegex).Groups["success"].Value; var isSucc = false; Boolean.TryParse(success, out isSucc); if (isSucc) { token = Regex.Match(result, ourRegex).Groups["token"].Value; } else { var myEx1 = MyException.GetMyExceptionWrapper(String.Format("获取access_token失败:【{0}】", result)); MyException.WriteLog(myEx1); result = HttpUtil.GetHtml(url); /*//如果返回内容不成功则一直获取,直到取得access_token * if (!result.Contains("access_token")) * { * //移除重新获取 * MemoryCacheHelper.RemoveCacheItem("access_token"); * LogHelper.Info("access_token获取失败:"+result); * result = HttpHelper.GetHtml(url); * }*/ if (!result.Contains("access_token")) { var myEx = MyException.GetMyExceptionWrapper(String.Format("获取access_token失败:【{0}】", result)); MyException.WriteLog(myEx); } string regex = "\"access_token\":\"(?<token>.*?)\""; token = Regex.Match(result, regex).Groups["token"].Value; } return token; }, null, DateTime.Now.AddSeconds(6000) )); }
/// <summary> /// 公众号用于调用微信JS接口的临时票据 /// </summary> /// <param name="appid">应用ID</param> /// <param name="secret">开发者凭据</param> /// <returns></returns> public static string GetJsapiTicket(string appId, string appSecret) { //正常情况下jsapi_ticket有效期为7200秒,这里使用缓存设置短于这个时间即可 string jsapi_ticket = MemoryCacheHelper.GetCacheItem <string>("jsapi_ticket", delegate() { string access_token = WeiXin.GetAccessToken(appId, appSecret); string data = Util.HttpGet2("https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=" + access_token + "&type=jsapi"); JsApiTicket ticket = Util.JsonTo <JsApiTicket>(data); return(ticket.ticket); }, new TimeSpan(0, 0, 600)//300秒过期 , DateTime.Now.AddSeconds(600) ); return(jsapi_ticket); }
/// <summary> /// 根据机构的ID,获取机构名,并放到缓存里面 /// </summary> /// <param name="deptId">机构ID</param> /// <returns></returns> public ActionResult GetDeptNameByID(string deptId) { string result = ""; if (!string.IsNullOrEmpty(deptId)) { System.Reflection.MethodBase method = System.Reflection.MethodBase.GetCurrentMethod(); string key = string.Format("{0}-{1}-{2}", method.DeclaringType.FullName, method.Name, deptId); //string key = string.Format("GetDeptNameByID-{0}", deptId); result = MemoryCacheHelper.GetCacheItem <string>(key, delegate() { return(BLLFactory <OU> .Instance.GetFieldValue(deptId, "Name")); }, new TimeSpan(0, 30, 0));//30分钟过期 } return(ToJsonContent(result));; }
protected override void OnLoad(EventArgs e) { #region 绑定数据 DataTable dicDpt = Tmo_FakeEntityClient.Instance.GetData("tmo_department", new[] { "dpt_id", "dpt_name", "dpt_parent" }, "dpt_id in (" + TmoComm.login_docInfo.children_department + ")"); selCheck.InitData(doc_department, dicDpt, "dpt_id", "dpt_parent", "dpt_name"); DataTable dicGroup = MemoryCacheHelper.GetCacheItem <DataTable>("tmo_docgroup", () => { return(Tmo_FakeEntityClient.Instance.GetData("tmo_docgroup", new[] { "group_id", "group_name" }, "group_level>=" + TmoComm.login_docInfo.doc_group_level)); }, DateTime.Now.AddMinutes(5)); TSCommon.BindImageComboBox(doc_group, dicGroup, "", "group_name", "group_id", true); #endregion InitValidationRules(); //doc_loginid.ReadOnly = doc_pwd.ReadOnly = DbOperaType == DBOperateType.Update; //登录账号和密码禁止编辑 doc_department.ReadOnly = PrimaryKeyValue == TmoComm.login_docInfo.doc_id.ToString(); base.OnLoad(e); }
public static List <string> GetMayiProxyListFromCache() { var fullName = MemoryCacheHelper.GetCacheItem <List <string> >("moguproxyList", delegate() { var res = HttpClientHolder.GetRequest("https://proxy.horocn.com/api/proxies?order_id=BIGK1617348040416038&num=10&format=text&line_separator=win"); while (res.IndexOf("频率") >= 0) { System.Threading.Thread.Sleep(10000); res = HttpClientHolder.GetRequest("https://proxy.horocn.com/api/proxies?order_id=BIGK1617348040416038&num=10&format=text&line_separator=win"); } var listProxy = res.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); return(listProxy); }, new TimeSpan(0, 0, 20));//30分钟过期 return(fullName); }
public ActionResult RealTimeAlarm(string level, string exceptIds) { JsonResult json = new JsonResult(); IEnumerable <v_AlarmInfo> alarmInfo = null; alarmInfo = MemoryCacheHelper.GetCacheItem <IEnumerable <v_AlarmInfo> >("curr_alarm", () => { IEnumerable <v_AlarmInfo> infos = null; //数据库取数据 using (var ctx = new GlsunViewEntities()) { infos = ctx.v_AlarmInfo.Where(a => a.AIConfirm == false).ToList(); } return(infos); }, null, DateTime.Now.AddSeconds(2)); List <int> ids = new List <int>(); if (alarmInfo != null) { ids = alarmInfo.Select(a => a.ID).ToList(); //排除已显示的项 if (!string.IsNullOrWhiteSpace(exceptIds)) { var arrIds = exceptIds.Split(','); if (arrIds.Length > 0) { var Ids = (from id in arrIds select int.Parse(id)).ToList(); alarmInfo = alarmInfo.Where(a => !Ids.Contains(a.ID)).OrderBy(a => a.AITime); } } } else { //throw new NullReferenceException("从缓存取当前告警为NULL"); } json.Data = new { Alarm = alarmInfo, IDSet = ids }; return(json); //return JsonHelper.ObjectToJson(alarmInfo); }
/// <summary> /// 根据字典类型获取对应的字典数据,方便UI控件的绑定 /// </summary> /// <param name="dictTypeName">字典类型名称</param> /// <returns></returns> public ActionResult GetDictJson(string dictTypeName) { #region 常规处理 //List<CListItem> treeList = new List<CListItem>(); //CListItem pNode = new CListItem("", ""); //treeList.Insert(0, pNode); //Dictionary<string, string> dict = BLLFactory<DictData>.Instance.GetDictByDictType(dictTypeName); //foreach (string dictKey in dict.Keys) //{ // treeList.Add(new CListItem(key, dict[dictKey])); //} //return ToJsonContent(treeList); #endregion #region 使用MemoryCache缓存提高速度 System.Reflection.MethodBase method = System.Reflection.MethodBase.GetCurrentMethod(); string key = string.Format("{0}-{1}-{2}", method.DeclaringType.FullName, method.Name, dictTypeName); var result = MemoryCacheHelper.GetCacheItem <ActionResult>(key, delegate() { List <CListItem> treeList = new List <CListItem>(); CListItem pNode = new CListItem("", ""); treeList.Insert(0, pNode); Dictionary <string, string> dict = BLLFactory <DictData> .Instance.GetDictByDictType(dictTypeName); foreach (string dictKey in dict.Keys) { treeList.Add(new CListItem(dictKey, dict[dictKey])); } return(ToJsonContent(treeList)); }, new TimeSpan(0, 30, 0));//30分钟过期 return(result); #endregion }
public string GetAccessToken(string appid, string secret) { //正常情况下access_token有效期为7200秒,这里使用缓存设置短于这个时间即可 string access_token = MemoryCacheHelper.GetCacheItem <string>("access_token", delegate() { string grant_type = "client_credential"; var url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type={0}&appid={1}&secret={2}", grant_type, appid, secret); string result = RequestUtility.HttpGet(url); string token = string.Empty; if (result.Contains("access_token")) { AccessTokenInfo at = JsonHelper <AccessTokenInfo> .ConvertObjJson(result); token = at.access_token; } return(token); }, new TimeSpan(0, 0, 7000)//7000秒过期 ); return(access_token); }