/// <summary> /// 获取临时用户登录Passport /// </summary> /// <returns></returns> protected static JObject GetTempUser() { var tempUser = CachingHelper <HttpRuntimeCaching> .Get <JObject>(KeyModel.Cache.DataCenterTempUser); if (VerifyHelper.IsEmpty(tempUser)) { var tempUserAccount = StringHelper.Get(DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyApiTempUser)).Split('|'); if (VerifyHelper.IsEmpty(tempUserAccount)) { throw new DefaultException("数据中心TempUser配置错误"); } var data = new JObject(); data["AppId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyAppId); data["ClientId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyClientId); data["Version"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyVersion); data["ip"] = BrowserHelper.GetClientIP(); data["Account"] = tempUserAccount.Length > 0 ? tempUserAccount[0] : ""; data["Password"] = tempUserAccount.Length > 1 ? tempUserAccount[1] : ""; var result = Request(DataCenterConfig.GetApiUrl(KeyModel.Config.DataCenter.KeyAccountLogin), JsonHelper.Serialize(data), resultKey: null, errorKey: null); if (result.Code == EnumHelper.GetValue(EnumResultCode.操作成功) && !VerifyHelper.IsEmpty(result.Obj)) { tempUser = result.Obj; } } return(VerifyHelper.IsEmpty(tempUser) ? new JObject() : tempUser); }
public Contract.Customer[] GetCustomers() { Customer[] customers = null; if (ModuleConfiguration.CachingPolicy != CachingPolicy.LocalOnly) { string url = ModuleConfiguration.ServicePoint + ModuleConfiguration.UrlGetCustomers; object result = this.router.Get(url, new Authentication() { Type = AuthenticationType.Custom }, new Dictionary <string, string>() { { HttpRequestHeader.Authorization.ToString(), ModuleConfiguration.AuthorizationHeaderValue } }); if (result != null) { customers = new DataContractSerializer(typeof(Customer[]), "ArrayOfCustomer", "http://schemas.datacontract.org/2004/07/DISConfigurationCloud.MetaManagement").ReadObject(new MemoryStream(System.Text.Encoding.GetEncoding(ModuleConfiguration.EncodingName).GetBytes(result.ToString()))) as Customer[]; //Utility.XmlDeserialize(result.ToString(), typeof(Customer[]), new Type[] { typeof(Customer), typeof(Configuration), typeof(ConfigurationType), typeof(Configuration[]) }, ModuleConfiguration.EncodingName) as Customer[]; } } if (ModuleConfiguration.CachingPolicy != CachingPolicy.RemoteOnly) { CachingHelper cachingHelper = new CachingHelper(); customers = cachingHelper.ProcessCustomerCache(customers); } return(customers); }
/// <summary> /// 多语言资源文件初始 /// </summary> /// <param name="languages"></param> public static void LanguageResourceInit(List <CultureInfo> languages) { Assembly asm = Assembly.Load("App_GlobalResources"); foreach (var item in StringHelper.ToArray(SettingConfig.GetValue(KeyModel.Config.Setting.KeyResourceScript), new string[] { "," })) { #region 脚本资源文件处理 var itemArr = StringHelper.ToArray(item, new string[] { "|" }); if (!(itemArr != null && itemArr.Length == 2)) { continue; } Type resourceType = asm.GetType(itemArr[0]); ResourceManager resourceMgr = new ResourceManager(itemArr[0], asm); if (VerifyHelper.IsEmpty(resourceType) || VerifyHelper.IsEmpty(resourceMgr)) { continue; } foreach (var culture in languages) { string context = ScriptsHelper.GetJSONStringByList(ResourceHelper.GetList(resourceType, resourceMgr, culture), itemArr[1]); if (!VerifyHelper.IsEmpty(context)) { FileHelper.WriterFile(string.Format("{0}/{1}.{2}.js", HttpContext.Current.Server.MapPath(SettingConfig.GetValue(KeyModel.Config.Setting.KeyCulturePath, KeyModel.Config.Setting.GroupWebsite)), itemArr[1], culture), context); } } #endregion } foreach (var name in StringHelper.ToArray(SettingConfig.GetValue(KeyModel.Config.Setting.KeyResourceCache), new string[] { "," })) { #region 缓存资源文件处理 Type resourceType = asm.GetType(name); ResourceManager resourceMgr = new ResourceManager(name, asm); if (VerifyHelper.IsEmpty(resourceType) || VerifyHelper.IsEmpty(resourceMgr)) { continue; } foreach (var culture in languages) { var list = ResourceHelper.GetList(resourceType, resourceMgr, culture); if (!VerifyHelper.IsEmpty(list)) { CachingHelper.Set(string.Format("_RESOURCE_{0}_{1}", resourceType.FullName, culture), list); } } #endregion } }
/// <summary> /// 配置文件初始 /// </summary> /// <param name="sectionName">节点名称</param> /// <param name="cacheKey">缓存Key</param> protected static void Init(string sectionName, string cacheKey) { TEntity section = ConfigHelper.GetSection <TEntity>(sectionName); if (section != null) { CachingHelper.Set(cacheKey, section); } }
public IActionResult Input(int id, CacheDirection?direction, [FromBody] string input) { // By making the enum nullable, the binder will return a 404 when neither of the enum values is passed string decodedJson = DecodingHelper.Decode(input.ToString()); CachingHelper.Add(id, decodedJson, direction.Value); return(Ok()); }
// GET: Report public ActionResult Index(string key = "", int currentPage = 1) { int cacheTime = (24 - DateTime.Now.Hour) * 60; ReportItemModel model = XmlReader.DeserializeXMLFileToObject <ReportItemModel>(Server.MapPath("/Files/Xml/" + key + ".xml")); model.data = CachingHelper.GetObjectFromCache <DataTable>(key.Replace("-", "_") + "_" + SEmployee.EmployeeCode, cacheTime); if (model.data == null) { model.data = CachingHelper.SetObjectFromCache <DataTable>(key.Replace("-", "_") + "_" + SEmployee.EmployeeCode, cacheTime, DataFunction.GetDataReportFromService(ServiceUrl, "", MapFilterParams(model.filter), "RPT1902-00001")); } return(View(model)); }
/// <summary> /// 应用缓存初始 /// </summary> public static void AppCacheInit() { var quests = EngineHelper.Resolve <IQuestService>().GetAll(); var flows = EngineHelper.Resolve <IQuestFlowService>().GetAll(); quests.ForEach(item => { item.Flows = new List <QuestFlowEntity>(); var currents = flows.Where(x => x.QuestId == item.Id).ToList(); item.Flows = currents?.ToList(); }); CachingHelper.Set <List <QuestEntity> >(AppConst.CacheQuestList, quests); }
/// <summary> /// 重写基类的取配置,加入缓存机制 /// </summary> public override T Get <T>(string index = null) { var fileName = this.GetConfigFileName <T>(index); var key = "ConfigFile_" + fileName; var content = CachingHelper.Get(key); if (content != null) { return((T)content); } var value = base.Get <T>(index); CachingHelper.Set(key, value, new CacheDependency(ConfigService.GetFilePath(fileName))); return(value); }
/// <summary> /// 根据Key获取配置项 /// </summary> /// <param name="cacheKey">缓存Key</param> /// <param name="key">Key键</param> /// <param name="groupKey">组key</param> /// <returns>返回Value</returns> protected static ConfigListItem GetGroupItem(string cacheKey, string key, string groupKey = null) { if (string.IsNullOrWhiteSpace(key)) { return(null); } TEntity section = CachingHelper.Get(cacheKey) as TEntity; if (section != null) { var item = ConfigHelper.GetGroupItem <TEntity, ConfigGroupItem, ConfigListItem>(section, groupKey, key); return(item); } return(null); }
public static IContainer GetContainer() { var obj = CachingHelper <HttpRuntimeCaching> .Get(KeyModel.Cache.Container); if (VerifyHelper.IsNull(obj)) { throw new DefaultException(" The IOC Containe Is null"); } IContainer container = obj as IContainer; if (VerifyHelper.IsNull(container)) { throw new DefaultException(" The IOC Containe Is null"); } return(container); }
public IActionResult Get(int id) { // Returns 404 if Id hasn't been inserted in both directions. This prevents an unwanted 500 from raising to the user. if (!CachingHelper.KeyExists(id)) { return(new NotFoundObjectResult("Provided Id does not exist")); } string left = CachingHelper.Get(id, CacheDirection.LEFT); string right = CachingHelper.Get(id, CacheDirection.RIGHT); /* Improvement: If this application did a heavier/more complex Diff, instead of calling the Diff on the GET, there could be an async/background worker * that ran whenever both directions were input, making the GET speed faster */ var diffResult = new CustomDiff(left, right).Diff(); var response = new DiffResultView { Result = diffResult.Result, Extra = diffResult.HasDifferences ? diffResult.Differences.ToString() : "" }; return(new JsonResult(response)); }
/// <summary> /// 获取所有任务配置 /// </summary> public static List <QuestEntity> GetQuests() { return(CachingHelper.Get <List <QuestEntity> >(AppConst.CacheQuestList)); }
private T AddCaching <T>(T obj) { var cachingHelper = new CachingHelper(); return(AopProxy.Create(obj, cachingHelper.HandleMethodCall)); }
public void AddAndGetItemInLRightStore() { CachingHelper.Add(1, "zxcvb", CacheDirection.RIGHT); Assert.Equal("zxcvb", CachingHelper.Get(1, CacheDirection.RIGHT)); }
public void AddAndGetItemInLeftStore() { CachingHelper.Add(1, "asdfg", CacheDirection.LEFT); Assert.Equal("asdfg", CachingHelper.Get(1, CacheDirection.LEFT)); }
public static void SetContainer(IContainer container) { CachingHelper <HttpRuntimeCaching> .Set(KeyModel.Cache.Container, container); }