/// <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);
        }
        /// <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);
        }
Example #3
0
        /// <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);
        }
Example #4
0
        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);
        }
Example #5
0
        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));
        }
Example #6
0
 /// <summary>
 /// 获取所有任务配置
 /// </summary>
 public static List <QuestEntity> GetQuests()
 {
     return(CachingHelper.Get <List <QuestEntity> >(AppConst.CacheQuestList));
 }
Example #7
0
 public void AddAndGetItemInLRightStore()
 {
     CachingHelper.Add(1, "zxcvb", CacheDirection.RIGHT);
     Assert.Equal("zxcvb", CachingHelper.Get(1, CacheDirection.RIGHT));
 }
Example #8
0
 public void AddAndGetItemInLeftStore()
 {
     CachingHelper.Add(1, "asdfg", CacheDirection.LEFT);
     Assert.Equal("asdfg", CachingHelper.Get(1, CacheDirection.LEFT));
 }