コード例 #1
0
ファイル: EntityData.cs プロジェクト: lxkbest/SexyColor.Net
        /// <summary>
        /// 获取实时缓存组手
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        private RealTimeCacheHelper ParseCacheTimelinessHelper(Type t)
        {
            RealTimeCacheHelper helper = null;
            TypeInfo            info   = t.GetTypeInfo();

            IEnumerable <Attribute> customAttributes = info.GetCustomAttributes(typeof(CacheSettingAttribute), true);
            IEnumerator <Attribute> attributes       = customAttributes.GetEnumerator();

            if (attributes.MoveNext())
            {
                CacheSettingAttribute attribute = attributes.Current as CacheSettingAttribute;
                if (attribute != null)
                {
                    helper = new RealTimeCacheHelper(attribute.EnableCache, this.TypeHashId);
                    if (attribute.EnableCache)
                    {
                        switch (attribute.ExpirationPolicy)
                        {
                        case CachingExpirationType.Stable:
                            helper.CachingExpirationType = CachingExpirationType.Stable;
                            break;

                        case CachingExpirationType.UsualSingleObject:
                            helper.CachingExpirationType = CachingExpirationType.UsualSingleObject;
                            break;

                        default:
                            helper.CachingExpirationType = CachingExpirationType.SingleObject;
                            break;
                        }
                        List <PropertyInfo> list = new List <PropertyInfo>();
                        if (!string.IsNullOrEmpty(attribute.PropertyNamesOfArea))
                        {
                            foreach (string str in attribute.PropertyNamesOfArea.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                            {
                                PropertyInfo property = t.GetProperty(str);
                                if (property != null)
                                {
                                    list.Add(property);
                                }
                            }
                        }
                        helper.PropertiesOfArea = list;
                    }
                }
            }
            if (helper == null)
            {
                helper = new RealTimeCacheHelper(true, this.TypeHashId);
            }
            return(helper);
        }
コード例 #2
0
ファイル: EntityData.cs プロジェクト: lxkbest/SexyColor.Net
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="t"></param>
        public EntityData(Type t)
        {
            this.Type       = t;
            this.TypeHashId = EncryptionUtility.MD5_16(t.FullName);
            RealTimeCacheHelper helper       = this.ParseCacheTimelinessHelper(t);
            ICacheService       cacheService = DIContainer.Resolve <ICacheService>();

            if (cacheService.EnableDistributedCache)
            {
                cacheService.Set(RealTimeCacheHelper.GetCacheKeyOfTimelinessHelper(this.TypeHashId), helper, CachingExpirationType.Invariable);
            }
            else
            {
                this.realTimeCacheHelper = helper;
            }
        }