Exemple #1
0
        /// <summary>
        /// 通过缓存获取系统编号清单
        /// </summary>
        /// <returns>系统编号清单</returns>
        public static List <BaseDictionaryItemEntity> GetSystemCodesByCache()
        {
            var cacheKey  = "Base.SystemCodes";
            var cacheTime = TimeSpan.FromMilliseconds(86400000);

            return(CacheUtil.Cache <List <BaseDictionaryItemEntity> >(cacheKey, () => GetSystemCodes(), true, false, cacheTime));
        }
Exemple #2
0
        /// <summary>
        /// 获取模块菜单表,从缓存读取
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="refreshCache">是否刷新缓存</param>
        /// <returns>角色列表</returns>
        public static List <BaseRoleEntity> GetEntitiesByCache(string systemCode = "Base", bool refreshCache = false)
        {
            var result = new List <BaseRoleEntity>();

            var tableName = systemCode + "Role";

            //2017.12.20增加默认的HttpRuntime.Cache缓存
            var cacheKey = "List." + systemCode + ".Role";
            //var cacheTime = default(TimeSpan);
            var cacheTime = TimeSpan.FromMilliseconds(86400000);

            result = CacheUtil.Cache <List <BaseRoleEntity> >(cacheKey, () =>
            {
                var roleManager = new BaseRoleManager(tableName);
                // 读取目标表中的数据
                var parametersWhere = new List <KeyValuePair <string, object> >
                {
                    // 有效的菜单
                    new KeyValuePair <string, object>(BaseRoleEntity.FieldEnabled, 1),
                    // 没被删除的菜单
                    new KeyValuePair <string, object>(BaseRoleEntity.FieldDeleted, 0)
                };

                // parameters.Add(new KeyValuePair<string, object>(BaseRoleEntity.FieldIsVisible, 1));
                return(roleManager.GetList <BaseRoleEntity>(parametersWhere, BaseRoleEntity.FieldSortCode));
            }, true, refreshCache, cacheTime);

            return(result);
        }
        /// <summary>
        /// 获取菜单模块树型列表
        /// </summary>
        /// <param name="systemCode">子系统</param>
        /// <param name="isMenu">是否菜单(0/1)</param>
        public DataTable GetModuleTree(string systemCode, string isMenu = null)
        {
            if (string.IsNullOrEmpty(systemCode))
            {
                systemCode = "Base";
            }
            //读取选定子系统的菜单模块
            var manager = new BaseModuleManager(UserInfo, systemCode + "Module");
            // 获取所有数据
            var parameters = new List <KeyValuePair <string, object> >();

            if (ValidateUtil.IsInt(isMenu))
            {
                parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldIsMenu, isMenu));
            }
            parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldEnabled, 1));
            parameters.Add(new KeyValuePair <string, object>(BaseModuleEntity.FieldDeleted, 0));
            //2017.12.20增加默认的HttpRuntime.Cache缓存
            var cacheKey = "DataTable." + systemCode + ".ModuleTree." + isMenu;
            //var cacheTime = default(TimeSpan);
            var cacheTime = TimeSpan.FromMilliseconds(86400000);

            return(CacheUtil.Cache <DataTable>(cacheKey, () => manager.GetModuleTree(manager.GetDataTable(parameters, BaseModuleEntity.FieldSortCode)), true, false, cacheTime));
            //直接读取数据库
            //return manager.GetModuleTree(manager.GetModuleTree(manager.GetDataTable(parameters, BaseModuleEntity.FieldSortCode)));
        }
        /// <summary>
        /// 根据字典编码、主键获取实体
        /// </summary>
        /// <param name="dictionaryCode">字典编码</param>
        /// <param name="itemKey">字典项主键</param>
        /// <param name="itemValue">字典项值</param>
        /// <returns></returns>
        public BaseDictionaryItemEntity GetEntity(string dictionaryCode, string itemKey, string itemValue = null)
        {
            BaseDictionaryItemEntity entity = null;

            if (!string.IsNullOrEmpty(dictionaryCode) && !string.IsNullOrEmpty(itemKey))
            {
                var entityBaseDictionary = new BaseDictionaryManager(UserInfo).GetEntityByCode(dictionaryCode);
                if (entityBaseDictionary != null)
                {
                    var parameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldDictionaryId, entityBaseDictionary.Id),
                        new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldItemKey, itemKey),
                        new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldDeleted, 0),
                        new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldEnabled, 1)
                    };
                    if (!string.IsNullOrEmpty(itemValue))
                    {
                        parameters.Add(new KeyValuePair <string, object>(BaseDictionaryItemEntity.FieldItemValue, itemValue));
                    }
                    var cacheKey  = CurrentTableName + ".Entity." + dictionaryCode + "." + itemKey;
                    var cacheTime = TimeSpan.FromMilliseconds(86400000);
                    entity = CacheUtil.Cache <BaseDictionaryItemEntity>(cacheKey, () => BaseEntity.Create <BaseDictionaryItemEntity>(GetDataTable(parameters)), true, false, cacheTime);
                }
            }
            return(entity);
        }
Exemple #5
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="name"></param>
        /// <param name="openId"></param>
        /// <param name="unionId"></param>
        /// <returns></returns>
        public BaseUserOAuthEntity GetEntity(string name, string openId, string unionId)
        {
            BaseUserOAuthEntity result = null;

            if (!string.IsNullOrEmpty(name) && !string.IsNullOrEmpty(openId))
            {
                name = dbHelper.SqlSafe(name);
                //需要显示未被删除的记录
                var sql = "SELECT TOP 1 * FROM " + CurrentTableName + " WHERE " + BaseUserOAuthEntity.FieldName + " = N'" + name + "'";
                if (!string.IsNullOrEmpty(openId))
                {
                    sql += " AND " + BaseUserOAuthEntity.FieldOpenId + " = N'" + openId + "'";
                }

                if (!string.IsNullOrEmpty(unionId))
                {
                    sql += " AND " + BaseUserOAuthEntity.FieldUnionId + " = N'" + unionId + "'";
                }

                //未删除
                sql += " AND " + BaseUserOAuthEntity.FieldDeleted + " = 0 AND " + BaseUserOAuthEntity.FieldEnabled + " = 1 ";
                //排序
                sql += " ORDER BY " + BaseUserOAuthEntity.FieldId + " DESC";
                var dt = DbHelper.Fill(sql);
                if (dt != null && dt.Rows.Count != 0)
                {
                    //result = BaseEntity.Create<AppContentEntity>(dt);
                    var cacheKey  = CurrentTableName + ".Entity." + openId;
                    var cacheTime = TimeSpan.FromMilliseconds(86400000);
                    result = CacheUtil.Cache <BaseUserOAuthEntity>(cacheKey, () => BaseEntity.Create <BaseUserOAuthEntity>(dt), true, false, cacheTime);
                }
            }
            return(result);
        }
Exemple #6
0
        /// <summary>
        /// 获取模块菜单表,从缓存读取
        /// 没有缓存也可以用的。
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="refreshCache">是否刷新缓存</param>
        /// <returns>菜单</returns>
        public List <BaseModuleEntity> GetEntitiesByCache(string systemCode = "Base", bool refreshCache = false)
        {
            List <BaseModuleEntity> result = null;

            var tableName = systemCode + "Module";
            var cacheKey  = "List." + systemCode + ".Module";
            //var cacheTime = default(TimeSpan);
            var cacheTime = TimeSpan.FromMilliseconds(86400000);

            result = CacheUtil.Cache <List <BaseModuleEntity> >(cacheKey, () =>
            {
                var moduleManager = new BaseModuleManager(DbHelper, UserInfo, tableName);
                // 读取目标表中的数据
                var parametersWhere = new List <KeyValuePair <string, object> >
                {
                    //有效的菜单
                    new KeyValuePair <string, object>(BaseModuleEntity.FieldEnabled, 1),
                    //没被删除的菜单
                    new KeyValuePair <string, object>(BaseModuleEntity.FieldDeleted, 0)
                };

                // parameters.Add(new KeyValuePair<string, object>(BaseModuleEntity.FieldIsVisible, 1));
                CurrentTableName = tableName;
                return(moduleManager.GetList <BaseModuleEntity>(parametersWhere, BaseModuleEntity.FieldSortCode));
            }, true, refreshCache, cacheTime);

            return(result);
        }
Exemple #7
0
        /// <summary>
        /// 通过 openId 获取用户信息
        /// </summary>
        /// <param name="openId">唯一键</param>
        /// <returns>用户实体</returns>
        public static BaseUserEntity GetEntityByOpenIdByCache(string openId)
        {
            BaseUserEntity result = null;
            var            userId = string.Empty;

            var key = "OpenId";

            if (!string.IsNullOrWhiteSpace(openId))
            {
                key += openId;

                result = CacheUtil.Cache(key, () =>
                {
                    // 到数据库里查一次
                    userId = new BaseUserLogonManager().GetIdByOpenId(openId);
                    if (!string.IsNullOrWhiteSpace(userId))
                    {
                        return(new BaseUserManager().GetEntity(userId));
                    }
                    else
                    {
                        return(null);
                    }
                }, true);
            }
            return(result);
        }
Exemple #8
0
        /// <summary>
        /// 从缓存中获取角色编号
        /// </summary>
        /// <param name="systemCode">系统编码</param>
        /// <param name="userId"></param>
        /// <param name="companyId"></param>
        /// <returns></returns>
        public static string[] GetRoleIdsByCache(string systemCode, string userId, string companyId = null)
        {
            // 返回值
            string[] result = null;

            if (!string.IsNullOrEmpty(userId))
            {
                //2017.12.20增加默认的HttpRuntime.Cache缓存
                var cacheKey = "Array" + systemCode + userId + companyId + "RoleIds";
                //var cacheTime = default(TimeSpan);
                var cacheTime = TimeSpan.FromMilliseconds(86400000);
                result = CacheUtil.Cache <string[]>(cacheKey, () =>
                {
                    //进行数据库查询
                    var userManager = new BaseUserManager();
                    return(userManager.GetRoleIds(systemCode, userId, companyId));
                }, true, false, cacheTime);

                //// 进行数据库查询
                //BaseUserManager userManager = new BaseUserManager();
                //result = userManager.GetRoleIds(systemCode, userId, companyId);
            }

            return(result);
        }
Exemple #9
0
        private static void PingCompletedCallback(object sender, PingCompletedEventArgs e)
        {
            try
            {
                string ip = (string)e.UserState;
                if (e.Reply != null && e.Reply.Status == IPStatus.Success)
                {
                    string macaddres        = NetworkUtil.GetMacAddress(ip);
                    var    deviceProperties = new ConcurrentDictionary <string, string>();
                    deviceProperties.TryAdd("IP", ip);
                    deviceProperties.TryAdd("MACADDRESS", NetworkUtil.GetMacAddress(ip));
                    CacheUtil.Cache("DEVICES")[macaddres] = deviceProperties;

                    LoadHostName(macaddres);
                    LoadVendor(macaddres);
                }
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                Interlocked.Decrement(ref activePingCompletedEventHandler);
            }
        }
Exemple #10
0
        /// <summary>
        /// 获取所有用户的角色列表
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <returns>角色数据表</returns>
        public DataTable GetUserRole(string systemCode)
        {
            var result = new DataTable(BaseRoleEntity.CurrentTableName);

            var userRoleTableName = BaseUserRoleEntity.CurrentTableName;

            if (!string.IsNullOrWhiteSpace(systemCode))
            {
                userRoleTableName = systemCode + "UserRole";
            }
            var roleTableName = BaseRoleEntity.CurrentTableName;

            if (!string.IsNullOrWhiteSpace(systemCode))
            {
                roleTableName = systemCode + "Role";
            }

            var sb = Pool.StringBuilder.Get();

            sb.AppendLine("SELECT BaseRole.Code, BaseRole.Name, BaseRole.Description, UserRole.Id, UserRole.UserId, UserRole.RoleId, UserRole.Enabled, UserRole.Deleted, UserRole.CreateTime, UserRole.CreateBy, UserRole.UpdateTime, UserRole.UpdateBy");
            sb.AppendLine(" FROM BaseRole INNER JOIN (SELECT Id, UserId, RoleId, Enabled, Deleted, CreateTime, CreateBy, UpdateTime, UpdateBy FROM BaseUserRole WHERE Enabled = 1 AND " + BaseUserRoleEntity.FieldDeleted + " = 0) UserRole ON BaseRole.Id = UserRole.RoleId");
            sb.AppendLine(" WHERE BaseRole.Enabled = 1 AND BaseRole." + BaseRoleEntity.FieldDeleted + " = 0 ORDER BY UserRole.CreateTime DESC");
            //替换表名
            sb = sb.Replace("BaseUserRole", userRoleTableName);
            sb = sb.Replace("BaseRole", roleTableName);

            var cacheKey = "DataTable." + systemCode + ".UserRole";
            //var cacheTime = default(TimeSpan);
            var cacheTime = TimeSpan.FromMilliseconds(86400000);

            result = CacheUtil.Cache <DataTable>(cacheKey, () => Fill(sb.Put()), true, false, cacheTime);
            return(result);
        }
Exemple #11
0
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="name">名称</param>
        /// <returns>权限实体</returns>
        public static BaseRoleEntity GetEntityByCacheByName(string systemCode, string name)
        {
            BaseRoleEntity result = null;

            if (string.IsNullOrWhiteSpace(systemCode))
            {
                systemCode = "Base";
            }

            // 动态读取表中的数据
            var tableName = systemCode + "Role";
            //2017.12.20增加默认的HttpRuntime.Cache缓存
            var cacheKey = "List." + systemCode + ".Role";
            //var cacheTime = default(TimeSpan);
            var cacheTime = TimeSpan.FromMilliseconds(86400000);
            var listRole  = CacheUtil.Cache <List <BaseRoleEntity> >(cacheKey, () =>
            {
                var parametersWhere = new List <KeyValuePair <string, object> >
                {
                    new KeyValuePair <string, object>(BaseRoleEntity.FieldDeleted, 0),
                    new KeyValuePair <string, object>(BaseRoleEntity.FieldEnabled, 1)
                };
                return(new BaseRoleManager(tableName).GetList <BaseRoleEntity>(parametersWhere, BaseRoleEntity.FieldId));
            }, true, false, cacheTime);

            result = listRole.Find(t => t.Name == name);
            //直接读取数据库
            //BaseRoleManager manager = new BaseRoleManager(tableName);
            //result = manager.GetEntityByName(name);

            return(result);
        }
        /// <summary>
        /// 多个角色,都有啥权限?单个角色都有啥权限的循环获取?
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="roleIds">角色主键数组</param>
        /// <returns>权限数组</returns>
        public static string[] GetPermissionIdsByCache(string systemCode, string[] roleIds)
        {
            string[] result = null;

            var key    = string.Empty;
            var roleId = string.Empty;

            string[] permissionIds = null;

            key = "Permission:" + systemCode + ":Role:" + roleId;
            var hs = new HashSet <string>();

            result = CacheUtil.Cache(key, () =>
            {
                for (var i = 0; i < roleIds.Length; i++)
                {
                    permissionIds = new BasePermissionManager().GetPermissionIds(systemCode, roleIds[i], "Role");
                    foreach (var permissionId in permissionIds)
                    {
                        hs.Add(permissionId);
                    }
                }

                return(hs.ToArray());
            }, true);

            return(result);
        }
Exemple #13
0
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="id">主键</param>
        public BaseOrganizationEntity GetEntity(int id)
        {
            //return BaseEntity.Create<BaseOrganizationEntity>(GetDataTable(new KeyValuePair<string, object>(PrimaryKey, id)));
            var cacheKey  = CurrentTableName + ".Entity." + id;
            var cacheTime = TimeSpan.FromMilliseconds(86400000);

            return(CacheUtil.Cache <BaseOrganizationEntity>(cacheKey, () => BaseEntity.Create <BaseOrganizationEntity>(GetDataTable(new KeyValuePair <string, object>(PrimaryKey, id))), true, false, cacheTime));
        }
Exemple #14
0
        /// <summary>
        /// 是否验证
        /// </summary>
        /// <param name="systemCode"></param>
        /// <param name="userId"></param>
        /// <param name="permissionCode">权限编码</param>
        /// <returns></returns>
        public static bool IsAuthorizedByCache(string systemCode, string userId, string permissionCode)
        {
            var result = false;
            var hashId = "User:IsAuthorized:" + userId;
            var key    = systemCode + ":" + permissionCode;

            result = CacheUtil.Cache(key, () => new BasePermissionManager().IsAuthorized(systemCode, userId, permissionCode), true);
            return(result);
        }
Exemple #15
0
        /// <summary>
        /// 从缓存中获取用户实体
        /// </summary>
        /// <param name="userCode"></param>
        /// <returns></returns>
        public static BaseUserEntity GetEntityByCodeByCache(string userCode)
        {
            BaseUserEntity result = null;

            var key = "User:ByCode:" + userCode;

            result = CacheUtil.Cache(key, () => new BaseUserManager().GetEntityByCode(userCode), true);
            return(result);
        }
Exemple #16
0
        /// <summary>
        /// 绑定下拉筐数据,组织机构树表
        /// </summary>
        /// <param name="dtOrganization">组织机构</param>
        /// <returns>组织机构树表</returns>
        public DataTable GetOrganizationTree(DataTable dtOrganization = null)
        {
            if (dtOrganization != null)
            {
                _dtOrganization = dtOrganization;
            }
            else
            {
                //2017.12.20增加默认的HttpRuntime.Cache缓存
                var cacheKey = "DataTable.BaseOrganization";
                //var cacheTime = default(TimeSpan);
                var cacheTime = TimeSpan.FromMilliseconds(86400000);
                _dtOrganization = CacheUtil.Cache <DataTable>(cacheKey, () =>
                {
                    //获取所有数据
                    var parameters = new List <KeyValuePair <string, object> >
                    {
                        new KeyValuePair <string, object>(BaseOrganizationEntity.FieldIsInnerOrganization, 1),
                        new KeyValuePair <string, object>(BaseOrganizationEntity.FieldEnabled, 1),
                        new KeyValuePair <string, object>(BaseOrganizationEntity.FieldDeleted, 0)
                    };
                    return(GetDataTable(parameters, BaseOrganizationEntity.FieldSortCode));
                }, true, false, cacheTime);

                // 直接读取数据库
                //List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>
                //{
                //    new KeyValuePair<string, object>(BaseOrganizationEntity.FieldIsInnerOrganization, 1),
                //    new KeyValuePair<string, object>(BaseOrganizationEntity.FieldEnabled, 1),
                //    new KeyValuePair<string, object>(BaseOrganizationEntity.FieldDeleted, 0)
                //};
                //_dtOrganization = this.GetDataTable(parameters, BaseOrganizationEntity.FieldSortCode);
            }
            // 初始化部门表
            if (_organizationTable.Columns.Count == 0)
            {
                // 建立表的列,不能重复建立
                _organizationTable.Columns.Add(new DataColumn(BaseOrganizationEntity.FieldId, Type.GetType("System.Int32")));
                _organizationTable.Columns.Add(new DataColumn(BaseOrganizationEntity.FieldName, Type.GetType("System.String")));
            }

            // 查找子部门
            for (var i = 0; i < _dtOrganization.Rows.Count; i++)
            {
                // Null或0
                if (BaseUtil.ConvertToInt(_dtOrganization.Rows[i][BaseOrganizationEntity.FieldParentId]) == 0)
                {
                    var dr = _organizationTable.NewRow();
                    dr[BaseOrganizationEntity.FieldId]   = _dtOrganization.Rows[i][BaseOrganizationEntity.FieldId];
                    dr[BaseOrganizationEntity.FieldName] = _dtOrganization.Rows[i][BaseOrganizationEntity.FieldName];
                    _organizationTable.Rows.Add(dr);
                    GetSubOrganization(BaseUtil.ConvertToInt(_dtOrganization.Rows[i][BaseOrganizationEntity.FieldId]));
                }
            }
            return(_organizationTable);
        }
Exemple #17
0
        public ServiceResponse <Dictionary <string, object> > GetDevicesFromCache()
        {
            var result = (ConcurrentDictionary <string, object>)CacheUtil.Cache("DEVICES");

            if (result.Count > 0)
            {
                return(new ServiceResponse <Dictionary <string, object> >(result.ToDictionary(x => x.Key, x => x.Value), Translate(MessagesConstants.SCC_DATA_DELETED)));
            }
            throw new ServiceException(Translate(MessagesConstants.ERR_DELETE));
        }
Exemple #18
0
        private static void LoadHostName(string macaddres)
        {
            ConcurrentDictionary <string, string> deviceProperties = (ConcurrentDictionary <string, string>)CacheUtil.Cache("DEVICES")[macaddres];

            string hostname = NetworkUtil.GetHostName(deviceProperties["IP"]);

            deviceProperties.TryAdd("HOSTNAME", hostname);
            //update
            CacheUtil.Cache("DEVICES")[macaddres] = deviceProperties;
        }
        /// <summary>
        /// 获取参数
        /// 2015-07-24 吉日嘎拉,获取最新的一条,增加排序字段
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="categoryCode">类别编号</param>
        /// <param name="parameterId">参数主键</param>
        /// <param name="parameterCode">编码</param>
        /// <returns>参数值</returns>
        public string GetParameter(string tableName, string categoryCode, string parameterId, string parameterCode)
        {
            CurrentTableName = tableName;

            //var parameters = new List<KeyValuePair<string, object>>
            //{
            //    new KeyValuePair<string, object>(BaseParameterEntity.FieldCategoryCode, categoryCode),
            //    new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterId, parameterId),
            //    new KeyValuePair<string, object>(BaseParameterEntity.FieldParameterCode, parameterCode),
            //    new KeyValuePair<string, object>(BaseParameterEntity.FieldDeleted, 0)
            //};
            //return GetProperty(parameters, BaseParameterEntity.FieldParameterContent, BaseParameterEntity.FieldCreateTime + " DESC");

            var result = string.Empty;
            var sb     = Pool.StringBuilder.Get().Append(" 1 = 1");

            if (!string.IsNullOrEmpty(categoryCode))
            {
                sb.Append(" AND " + BaseParameterEntity.FieldCategoryCode + " = '" + categoryCode + "'");
            }
            if (!string.IsNullOrEmpty(parameterId))
            {
                sb.Append(" AND " + BaseParameterEntity.FieldParameterId + " = '" + parameterId + "'");
            }
            if (!string.IsNullOrEmpty(parameterCode))
            {
                sb.Append(" AND " + BaseParameterEntity.FieldParameterCode + " = '" + parameterCode + "'");
            }

            var cacheKey = "DataTable." + CurrentTableName;
            //万一系统里开的公司多了,还是不要按公司来分
            //if (UserInfo != null)
            //{
            //    cacheKey += "." + UserInfo.CompanyId;
            //}
            var cacheTime  = TimeSpan.FromMilliseconds(86400000);
            var parameters = new List <KeyValuePair <string, object> >
            {
                //这里只要有效的,没被删除的
                new KeyValuePair <string, object>(BaseParameterEntity.FieldEnabled, 1),
                new KeyValuePair <string, object>(BaseParameterEntity.FieldDeleted, 0)
            };
            var dt = CacheUtil.Cache <DataTable>(cacheKey, () => GetDataTable(parameters), true, false, cacheTime);

            //查找
            sb.Replace(" 1 = 1 AND ", "");
            var drs = dt.Select(sb.Put());

            if (drs.Length > 0)
            {
                result = drs[0][BaseParameterEntity.FieldParameterContent].ToString();
            }

            return(result);
        }
        /// <summary>
        /// 根据工号从缓存获取实体
        /// </summary>
        /// <param name="employeeNumber">工号</param>
        /// <returns></returns>
        public static BaseStaffEntity GetEntityByEmployeeNumberByCache(string employeeNumber)
        {
            BaseStaffEntity result = null;

            if (!string.IsNullOrEmpty(employeeNumber))
            {
                var cacheKey = "StaffByEmployeeNumber" + employeeNumber;
                result = CacheUtil.Cache(cacheKey, () => new BaseStaffManager().GetEntityByEmployeeNumber(employeeNumber), true);
            }
            return(result);
        }
Exemple #21
0
        /// <summary>
        /// 从缓存中获取实体
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BaseUserLogonEntity GetEntityByCache(string id)
        {
            BaseUserLogonEntity result = null;

            if (!string.IsNullOrEmpty(id))
            {
                var key = "UserLogon:" + id;
                result = CacheUtil.Cache(key, () => GetCacheByKey(key), true);
            }

            return(result);
        }
        /// <summary>
        /// 从缓存获取获取实体
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns>实体</returns>
        public static BaseUserContactEntity GetEntityByCache(int id)
        {
            BaseUserContactEntity result = null;

            if (id > 0)
            {
                var key = "UserContact:" + id;
                result = CacheUtil.Cache(key, () => new BaseUserContactManager().GetEntity(id), true);
            }

            return(result);
        }
Exemple #23
0
        /// <summary>
        /// 获取权限编号
        /// </summary>
        /// <param name="systemCode">系统编码</param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static string[] GetPermissionIdsByCache(string systemCode, string userId)
        {
            string[] result = null;

            var key = string.Empty;

            key = "Permission:" + systemCode + ":User:" + userId;

            result = CacheUtil.Cache(key, () => new BasePermissionManager().GetPermissionIds(systemCode, userId), true);

            return(result);
        }
        /// <summary>
        /// 从缓存获取
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="categoryCode"></param>
        /// <param name="parameterId"></param>
        /// <param name="parameterCode"></param>
        /// <param name="refreshCache"></param>
        /// <returns></returns>
        public static string GetParameterByCache(string tableName, string categoryCode, string parameterId, string parameterCode, bool refreshCache = false)
        {
            var result = string.Empty;

            if (!string.IsNullOrEmpty(tableName) && !string.IsNullOrEmpty(categoryCode) && !string.IsNullOrEmpty(parameterId) && !string.IsNullOrEmpty(parameterCode))
            {
                var key = "Parameter:" + tableName + ":" + categoryCode + ":" + parameterId + ":" + parameterCode;
                result = CacheUtil.Cache(key, () => new BaseParameterManager(tableName).GetParameter(tableName, categoryCode, parameterId, parameterCode), true, refreshCache);
            }

            return(result);
        }
Exemple #25
0
        /// <summary>
        /// 获取用户的角色列表
        /// </summary>
        /// <param name="systemCode">系统编号</param>
        /// <param name="userId">用户主键</param>
        /// <returns>角色数据表</returns>
        public DataTable GetUserRoleDataTable(string systemCode, string userId)
        {
            var result = new DataTable(BaseRoleEntity.CurrentTableName);

            var userRoleTableName = BaseUserRoleEntity.CurrentTableName;

            if (!string.IsNullOrWhiteSpace(systemCode))
            {
                userRoleTableName = systemCode + "UserRole";
            }
            var tableRoleName = BaseRoleEntity.CurrentTableName;

            if (!string.IsNullOrWhiteSpace(systemCode))
            {
                tableRoleName = systemCode + "Role";
            }

            var commandText = @"SELECT BaseRole.Id
                                    , BaseRole.Code 
                                    , BaseRole.Name 
                                    , BaseRole.Description
                                    , UserRole.UserId
                                    , UserRole.Enabled
                                    , UserRole.Deleted
                                    , UserRole.CreateTime
                                    , UserRole.CreateBy
                                    , UserRole.UpdateTime
                                    , UserRole.UpdateBy
 FROM BaseRole RIGHT OUTER JOIN
                          (SELECT UserId, RoleId, Enabled, Deleted, CreateTime, CreateBy, UpdateTime, UpdateBy FROM BaseUserRole
                            WHERE UserId = " + DbHelper.GetParameter(BaseUserRoleEntity.FieldUserId)
                              + " AND Enabled = 1 AND " + BaseUserRoleEntity.FieldDeleted + " = 0 " + @") UserRole 
                            ON BaseRole.Id = UserRole.RoleId WHERE BaseRole." + BaseRoleEntity.FieldEnabled + " = 1 AND BaseRole." + BaseRoleEntity.FieldDeleted + @" = 0 
                      ORDER BY UserRole." + BaseRoleEntity.FieldCreateTime + " DESC ";

            //替换表名
            commandText = commandText.Replace("BaseUserRole", userRoleTableName);
            commandText = commandText.Replace("BaseRole", tableRoleName);

            var dbParameters =
                new List <IDbDataParameter> {
                DbHelper.MakeParameter(BaseUserRoleEntity.FieldUserId, userId)
            };

            //2017.12.20增加默认的HttpRuntime.Cache缓存
            var cacheKey = "DataTable." + systemCode + "." + userId + ".UserRole";
            //var cacheTime = default(TimeSpan);
            var cacheTime = TimeSpan.FromMilliseconds(86400000);

            result = CacheUtil.Cache <DataTable>(cacheKey, () => Fill(commandText, dbParameters.ToArray()), true, false, cacheTime);
            return(result);
        }
Exemple #26
0
        /// <summary>
        /// 从缓存获取
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static BaseOrganizationEntity GetEntityByCodeByCache(string code)
        {
            BaseOrganizationEntity result = null;

            if (!string.IsNullOrEmpty(code))
            {
                // string key = "OrganizationByCode:" + code;
                var key = "OBC:" + code;
                result = CacheUtil.Cache(key, () => new BaseOrganizationManager().GetEntityByCode(code), true);
            }

            return(result);
        }
Exemple #27
0
        /// <summary>
        /// 从缓存获取
        /// </summary>
        /// <param name="id"></param>
        /// <param name="refreshCache"></param>
        /// <returns></returns>
        public static BaseOrganizationEntity GetEntityByCache(string id, bool refreshCache = false)
        {
            BaseOrganizationEntity result = null;

            if (!string.IsNullOrEmpty(id))
            {
                var cacheKey = "O:";
                cacheKey += id;
                result    = CacheUtil.Cache(cacheKey, () => new BaseOrganizationManager().GetEntity(id), true, refreshCache);
            }

            return(result);
        }
        /// <summary>
        /// 获取实体
        /// </summary>
        /// <param name="code">编码</param>
        /// <returns></returns>
        public BaseDictionaryEntity GetEntityByCode(string code)
        {
            var parameters = new List <KeyValuePair <string, object> >
            {
                new KeyValuePair <string, object>(BaseDictionaryEntity.FieldCode, code),
                new KeyValuePair <string, object>(BaseDictionaryEntity.FieldDeleted, 0),
                new KeyValuePair <string, object>(BaseDictionaryEntity.FieldEnabled, 1)
            };
            var cacheKey  = CurrentTableName + ".Entity." + code;
            var cacheTime = TimeSpan.FromMilliseconds(86400000);

            return(CacheUtil.Cache <BaseDictionaryEntity>(cacheKey, () => BaseEntity.Create <BaseDictionaryEntity>(GetDataTable(parameters)), true, false, cacheTime));
        }
Exemple #29
0
        /// <summary>
        /// 通过唯一用户名从Reids中获取
        /// </summary>
        /// <param name="nickName"></param>
        /// <returns></returns>
        public static BaseUserEntity GetEntityByNickNameByCache(string nickName)
        {
            // 2016-01-25 黄斌 添加, 从缓存中 通过唯一用户名获取
            BaseUserEntity result = null;

            if (string.IsNullOrEmpty(nickName))
            {
                return(result);
            }
            var key = "User:ByNickName:" + nickName.ToLower();

            result = CacheUtil.Cache(key, () => new BaseUserManager().GetEntityByNickName(nickName), true);
            return(result);
        }
Exemple #30
0
        private void CacheVideosFiles(Uri videoUrl)
        {
            try
            {
                if (Cache == null)
                {
                    Cache = new SimpleCache(MainContext.CacheDir, new NoOpCacheEvictor());
                }

                if (CacheDataSourceFactory == null)
                {
                    CacheDataSourceFactory = new CacheDataSourceFactory(Cache, DefaultDataSourceFac);
                }

                var dataSpec = new DataSpec(videoUrl, 0, 3000 * 1024, null); //0, 1000 * 1024, null
                var counters = new CacheUtil.CachingCounters();

                CacheUtil.GetCached(dataSpec, Cache, counters);

                if (counters.ContentLength == counters.TotalCachedBytes())
                {
                }
                else if (counters.TotalCachedBytes() == 0)
                {
                    // not cached at all
                    Task.Run(() =>
                    {
                        try
                        {
                            var cacheDataSource = new CacheDataSource(Cache, CacheDataSourceFactory.CreateDataSource());
                            CacheUtil.Cache(dataSpec, Cache, cacheDataSource, counters, new AtomicBoolean());
                            double downloadPercentage = counters.TotalCachedBytes() * 100d / counters.ContentLength;
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    });
                }
                else
                {
                    // just few mb cached
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }