Esempio n. 1
0
        public void Failed_On_Set_NonSeriableObject()
        {
            var testObject = new
            {
                id   = 1231,
                name = "asdfa",
                time = DateTime.UtcNow
            };
            var result = _cacheProvider.Add("No_Seriable_Object", testObject, 100);

            Assert.False(result);
        }
Esempio n. 2
0
        public async Task <Event> GetByIdAsync(long id, string appKey)
        {
            var app = ApplicationBusiness.GetByAppKeyAsync(appKey);

            if (app == null)
            {
                throw new ArgumentException("The given application key is invalid.");
            }

            string cacheKey   = Util.GetEventCacheKey(id);
            var    foundEvent = CacheProvider.Get <Event>(cacheKey);

            if (foundEvent == null)
            {
                using (IUnitOfWork uow = DataAccessLayer.GetUnitOfWork())
                {
                    IRepository <Event> repos = DataAccessLayer.GetEventRepository(uow);
                    foundEvent = await repos.GetByIdAsync(id);

                    if (foundEvent.ApplicationId != app.Id)
                    {
                        throw new ArgumentException("The given event ID and application key do not match!");
                    }

                    if (foundEvent != null)
                    {
                        await GetChildrenAsync(foundEvent);

                        CacheProvider.Add(cacheKey, foundEvent, DateTimeOffset.Now.AddHours(Util.GetLogLifespanHours()));
                    }
                }
            }

            return(foundEvent);
        }
Esempio n. 3
0
        /// <summary>
        /// Performs a request to the TVDB API and returns the resultant object.
        /// </summary>
        /// <typeparam name="T">Type of the object to return.</typeparam>
        /// <param name="url">API sub-URL to use for the request.</param>
        /// <param name="cacheKey">Key to use for cache storage of this request.</param>
        /// <param name="ignoreCurrentCache">Ignores existing cache entries for this request.</param>
        /// <param name="ignorePersistentCache">Does not add this request to the persistent cache.</param>
        /// <returns>Object returned for the API request.</returns>
        public T PerformApiRequestAndDeserialize <T>(string url, string cacheKey, bool ignoreCurrentCache = false, bool ignorePersistentCache = false)
        {
            Debug.WriteLine("-> TvdbApiRequest::PerformApiRequestAndDeserialize url=\"" + url + "\" cacheKey=\"" + cacheKey +
                            "\" ignoreCurrentCache=\"" + ignoreCurrentCache + "\" ignorePersistentCache=\"" + ignorePersistentCache + "\" Called");
            try
            {
                // Retreive previous api request from the cache
                if (CacheProvider.ContainsKey(cacheKey))
                {
                    return((T)CacheProvider[cacheKey]);
                }

                // Perform api request and deserialize
                var stream       = PerformApiRequest(url);
                var ser          = new XmlSerializer(typeof(T));
                var deserialized = (T)ser.Deserialize(stream);

                // Add to cache if cache is enabled
                if (CacheProvider.CacheType != TvdbCacheType.None)
                {
                    CacheProvider.Add(cacheKey, deserialized, ignorePersistentCache);
                }

                return(deserialized);
            }
            catch (Exception e)
            {
                Debug.WriteLine("!> TvdbApiRequest::PerformApiRequestAndDeserialize threw an exception: " + e);
                return(default(T)); // request probably failed so return null for safe abort
            }
        }
Esempio n. 4
0
 /// <summary>
 /// 更新缓存
 /// </summary>
 private T UpdateCache <T>(Func <T> addHandler, string lockKey, int time, T result)
 {
     if (Equals(result, null))
     {
         result = addHandler();
         CacheProvider.Add(lockKey, result, GetCacheTime(time) * 2);
         return(result);
     }
     Task.Factory.StartNew(() => CacheProvider.Update(lockKey, addHandler(), GetCacheTime(time) * 2));
     return(result);
 }
Esempio n. 5
0
 public IQueryable Execute(bool?flush = null)
 {
     if (IsCacheable && (!flush.HasValue || !flush.Value))
     {
         if (!CacheProvider.Current.Contains(CacheKey))
         {
             CacheProvider.Add(CacheKey, GetAppliedQuery(), CacheDuration);
         }
         return(CacheProvider.Current.Get(CacheKey) as IQueryable);
     }
     return(GetAppliedQuery());
 }
Esempio n. 6
0
        /// <summary>
        /// 应用授权
        /// </summary>
        /// <param name="AppId"></param>
        /// <param name="AppSecret"></param>
        /// <returns></returns>
        public String Auth(long AppId, String AppSecret)
        {
            string cacheKey = CacheKey.GetApp(AppId);
            T_App  app      = CacheProvider.Get <T_App>(cacheKey);

            if (app == null || app.AppSecret != AppSecret)
            {
                throw new RException("00003", "授权失败!");
            }
            string token = Guid.NewGuid().ToString("N");

            cacheKey = CacheKey.GetTokenKey(token);
            TimeSpan expiry = new TimeSpan(8888, 0, 0);

            CacheProvider.Add <T_App>(cacheKey, app, expiry);
            return(token);
        }
        /// <summary>
        /// 获取缓存对象,当缓存对象不存在,则执行方法并添加到缓存中
        /// </summary>
        /// <typeparam name="T">对象类型</typeparam>
        /// <param name="key">缓存键</param>
        /// <param name="addHandler">添加缓存方法,当缓存对象不存在时,执行该方法获得缓存对象</param>
        /// <param name="time">缓存过期时间,单位:秒</param>
        public T Get <T>(string key, Func <T> addHandler, int time = 0)
        {
            var lockKey = GetKey(key);
            var signKey = GetSignKey(key);
            var result  = CacheProvider.Get <T>(lockKey);
            var sign    = CacheProvider.Get <string>(signKey);

            if (!sign.IsEmpty())
            {
                return(result);
            }
            lock ( signKey ) {
                sign = CacheProvider.Get <string>(signKey);
                if (!sign.IsEmpty())
                {
                    return(result);
                }
                CacheProvider.Add(signKey, CacheSign, GetCacheTime(time));
                return(UpdateCache(addHandler, lockKey, time, result));
            }
        }
Esempio n. 8
0
    private static Dictionary <int, bool> GetSetting()
    {
        object oCache = CacheProvider.Get(KeyCache.KeyPopup);

        if (oCache != null)
        {
            return((Dictionary <int, bool>)oCache);
        }

        Dictionary <int, bool> obj;

        if (!File.Exists(HttpContext.Current.Server.MapPath(FILE_NAME)))
        {
            obj = new Dictionary <int, bool>();
            obj.Add(0, true);//add giá trị mặc định cho người dùng ko đăng nhập
            CacheProvider.Add(KeyCache.KeyPopup, obj);
            return(obj);
        }
        Stream          fileStream      = null;
        BinaryFormatter binaryFormatter = new BinaryFormatter();

        fileStream = File.Open(HttpContext.Current.Server.MapPath(FILE_NAME), FileMode.Open, FileAccess.Read, FileShare.None);
        try
        {
            obj = (Dictionary <int, bool>)binaryFormatter.Deserialize(fileStream);
            CacheProvider.Add(KeyCache.KeyPopup, obj);
            return(obj);
        }
        catch
        {
            return(new Dictionary <int, bool>());
        }
        finally
        {
            if (fileStream != null)
            {
                fileStream.Close();
            }
        }
    }
 public static void ListMenuAdd(object s)
 {
     CacheProvider.Add("lstmenu", s);
 }
        public void TestMethodAdd()
        {
            var result = ObjProvider.Add("key1", "testServer");

            Assert.AreEqual(true, result);
        }
Esempio n. 11
0
        public FlowUser(string companyid, string userid, OracleConnection con, string modelCode)
        {
            string names = "";

            try
            {
                ModelInfo      modelinfo = new ModelInfo();
                FlowUserInfo[] Users     = { };
                #region ModelInfo加入缓存
                object modelinfoObj = CacheProvider.GetCache(modelCode);
                if (modelinfoObj != null)
                {
                    modelinfo = (ModelInfo)modelinfoObj;
                    LogHelper.WriteLog("从缓存中获取 ModelInfo");
                }
                else
                {
                    LogHelper.WriteLog("从数据库获取 通过模块代码查询系统代码 开始 modelCode=" + modelCode);

                    modelinfo = FlowBLL.GetSysCodeByModelCode(con, modelCode);//对数据库操作
                    if (modelinfo != null)
                    {
                        CacheProvider.RemoveCache(modelCode);
                        CacheProvider.Add(modelCode, modelinfo);
                    }
                    else
                    {
                        LogHelper.WriteLog("从数据库获取 通过模块代码查询系统代码 结果为空");
                    }
                    LogHelper.WriteLog("从数据库获取 通过模块代码查询系统代码 结束 modelCode=" + modelCode);
                }
                #endregion
                this.ModelCode = modelCode;
                if (modelinfo != null)
                {
                    this.ModelName = modelinfo.ModelName;
                    this.SysCode   = modelinfo.SysCode;
                }
                #region FlowUserInfo加入缓存
                object FlowUserInfoObj = CacheProvider.GetCache(userid);
                if (FlowUserInfoObj != null)
                {
                    Users = (FlowUserInfo[])FlowUserInfoObj;
                    LogHelper.WriteLog("从缓存中获取 FlowUserInfo");
                }
                else
                {
                    LogHelper.WriteLog("创建服务 PermissionServiceClient 开始");
                    PermissionServiceClient WcfPermissionService = new PermissionServiceClient();
                    LogHelper.WriteLog("从数据库获取 FlowUserInfo 开始 userid=" + userid);
                    Users = WcfPermissionService.GetFlowUserByUserID(userid);//新的接口
                    if (Users != null)
                    {
                        CacheProvider.RemoveCache(userid);
                        CacheProvider.Add(userid, Users);
                    }
                    LogHelper.WriteLog("从数据库获取 FlowUserInfo  结束 userid=" + userid);
                }
                #endregion

                foreach (var user in Users)
                {
                    if (user.CompayID == companyid)
                    {
                        names += "公司ID=" + user.CompayID + "\r\n";
                        names += "部门ID=" + user.DepartmentID + "\r\n";
                        names += "岗位ID=" + user.PostID + "\r\n";
                        names += "用户ID=" + user.UserID + "\r\n";

                        names += "公司名称=" + user.CompayName + "\r\n";
                        names += "部门名称=" + user.DepartmentName + "\r\n";
                        names += "岗位名称=" + user.PostName + "\r\n";
                        names += "用户名称=" + user.EmployeeName + "\r\n";

                        #region 用户基本信息
                        this.CompayID     = user.CompayID;
                        this.DepartmentID = user.DepartmentID;
                        this.PostID       = user.PostID;
                        this.UserID       = user.UserID;

                        this.CompayName     = user.CompayName;
                        this.DepartmentName = user.DepartmentName;
                        this.PostName       = user.PostName;
                        this.UserName       = user.EmployeeName;
                        this.Roles          = new List <T_SYS_ROLE>();
                        foreach (var role in user.Roles)
                        {
                            if (role != null)
                            {
                                names += "角色ID=" + role.ROLEID + "\r\n";
                                names += "角色名称=" + role.ROLENAME + "\r\n\r\n";
                            }

                            this.Roles.Add(role);
                        }
                        #endregion
                    }
                }
                LogHelper.WriteLog("流程单据所属人身份:\r\n" + names);
            }
            catch (Exception e)
            {
                ErrorMsg += "获取当前提交,审核单据时的用户信息出错:names=" + names + "异常信息:\r\n" + e.ToString() + "\r\n";
                LogHelper.WriteLog("获取当前提交,审核单据时的用户信息出错:names=" + names + "异常信息:\r\n" + e.ToString());
            }
        }
Esempio n. 12
0
 public static void ListTopArticleByLanguageIDAndArticleIDAdd(int top, string lang, int acticleId, object s)
 {
     CacheProvider.Add("ListTopArticleByLanguageIDAndArticleID_" + top + "_" + lang + "_" + acticleId, s);
 }
Esempio n. 13
0
 public static void GetListTopArticleByLanguageIDAndPositionAdd(int top, string lang, int position, object s)
 {
     CacheProvider.Add("GetListTopArticleByLanguageIDAndPosition_" + top + lang + position, s);
 }
Esempio n. 14
0
 public static void ListTopArticleByLanguageIDAdd(int top, string lang, object s)
 {
     CacheProvider.Add("ListTopArticleByLanguageID" + top + lang, s);
 }
Esempio n. 15
0
 public static void ListCategoryAdd(object s)
 {
     CacheProvider.Add("lstcategory", s);
 }
Esempio n. 16
0
 public static void ListArticleAdd(int cateId, string lang, object s)
 {
     CacheProvider.Add("ListArticle_" + cateId + lang, s);
 }
Esempio n. 17
0
 public static void DvNoiBat_GetAdd(int cateId, string lang, object s)
 {
     CacheProvider.Add("DvNoiBat_Get_" + cateId + lang, s);
 }
Esempio n. 18
0
 public static void ListByCategoryAndLanguageAdd(int cateId, string lang, object s)
 {
     CacheProvider.Add("ListByCategoryAndLanguage_" + cateId + lang, s);
 }