示例#1
0
        /// <summary>
        /// 缓存预热,强制重新缓存
        /// 2016-02-26 每个角色的权限也进行缓存起来
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <returns>影响行数</returns>
        public static int CachePreheating(string systemCode)
        {
            var result = 0;

            // 把所有的组织机构都缓存起来的代码
            var manager = new BaseRoleManager
            {
                CurrentTableName = systemCode + "Role"
            };
            var dataReader = manager.ExecuteReader();

            if (dataReader != null && !dataReader.IsClosed)
            {
                while (dataReader.Read())
                {
                    var entity = BaseEntity.Create <BaseRoleEntity>(dataReader, false);
                    if (entity != null)
                    {
                        // 设置角色本身的缓存
                        SetCache(systemCode, entity);
                        // 重置权限缓存数据
                        BasePermissionManager.ResetPermissionByCache(systemCode, null, entity.Id.ToString());
                        result++;
                        System.Console.WriteLine(result + " : " + entity.Name);
                    }
                }

                dataReader.Close();
            }

            return(result);
        }
示例#2
0
        /// <summary>
        /// 刷新缓存
        /// </summary>
        /// <param name="systemCode"></param>
        /// <returns></returns>
        public static int RefreshCache(string systemCode)
        {
            var result = 0;

            var list = GetEntitiesByCache(systemCode, true);

            foreach (var entity in list)
            {
                // 2016-02-29 吉日嘎拉 强制刷新缓存
                var roleEntity = GetEntityByCache(systemCode, entity.Id.ToString(), true);
                if (roleEntity != null)
                {
                    BasePermissionManager.ResetPermissionByCache(systemCode, null, entity.Id.ToString());
                }
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// 刷新缓存
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static int RefreshCache(string userId)
        {
            var result = 0;

            // 刷新用户的缓存
            var userEntity = GetEntityByCache(userId, true);

            if (userEntity != null)
            {
                // 刷新用户的登录限制 用户名的限制

                // 刷新用户的登录限制
                ResetIpAddressByCache(userId);
                ResetMacAddressByCache(userId);
                // 刷新组织机构缓存
                BaseOrganizationManager.GetEntityByCache(userEntity.CompanyId.ToString(), true);
                // 2016-02-18 吉日嘎拉 刷新拒绝权限(把用户的权限放在一起方便直接移除、刷新)
                var key = "User:IsAuthorized:" + userId;
                CacheUtil.Remove(key);

                // 2016-05-24 吉日嘎拉 解除登录限制的方法,防止一天都登录不上的问题发生
                //if (!string.IsNullOrEmpty(userEntity.NickName))
                //{
                //    key = "u:" + userEntity.NickName;
                //    PooledRedisHelper.CallLimitRemove(key);
                //}
                //if (!string.IsNullOrEmpty(userEntity.Code))
                //{
                //    key = "u:" + userEntity.Code;
                //    PooledRedisHelper.CallLimitRemove(key);
                //}

                // 每个子系统都可以循环一次
                var systemCodes = BaseSystemManager.GetSystemCodes();
                foreach (var entity in systemCodes)
                {
                    BasePermissionManager.ResetPermissionByCache(entity.ItemKey, userId, null);
                }
            }

            return(result);
        }