コード例 #1
0
        /// <summary>
        /// 保存用户自定义风格
        /// </summary>
        /// <param name="presentAreaKey">呈现区域标识</param>
        /// <param name="ownerId">OwnerId</param>
        /// <param name="customStyle">自定义风格实体</param>
        public void Save(string presentAreaKey, long ownerId, CustomStyle customStyle)
        {
            PetaPocoDatabase database = CreateDAO();

            database.OpenSharedConnection();
            CustomStyleEntity entity         = Get(presentAreaKey, ownerId);
            string            customStyleXml = Serialize(customStyle);

            if (entity != null)
            {
                customStyle.LastModified     = DateTime.UtcNow;
                entity.CustomStyle           = customStyle;
                entity.SerializedCustomStyle = customStyleXml;
                entity.LastModified          = DateTime.UtcNow;
                database.Update(entity);
            }
            else
            {
                entity                       = CustomStyleEntity.New();
                entity.CustomStyle           = customStyle;
                entity.PresentAreaKey        = presentAreaKey;
                entity.OwnerId               = ownerId;
                entity.SerializedCustomStyle = customStyleXml;
                database.Insert(entity);
            }

            database.CloseSharedConnection();
            cacheService.Set(GetCacheKey_CustomStyleEntity(presentAreaKey, ownerId), entity, CachingExpirationType.UsualSingleObject);
        }
コード例 #2
0
        /// <summary>
        /// 获取用户自定义风格
        /// </summary>
        /// <param name="presentAreaKey">呈现区域标识</param>
        /// <param name="ownerId">OwnerId</param>
        /// <returns>无相应数据返回null</returns>
        public CustomStyleEntity Get(string presentAreaKey, long ownerId)
        {
            string cacheKey = GetCacheKey_CustomStyleEntity(presentAreaKey, ownerId);

            CustomStyleEntity result = cacheService.GetFromFirstLevel <CustomStyleEntity>(cacheKey);

            if (result == null)
            {
                PetaPocoDatabase database = CreateDAO();
                var sql = PetaPoco.Sql.Builder;
                sql.Select("*").From("spb_CustomStyles").Where("PresentAreaKey=@0", presentAreaKey).Where("OwnerId=@0", ownerId);
                result = database.FirstOrDefault <CustomStyleEntity>(sql);
                if (result != null)
                {
                    result.CustomStyle = Deserialize(result.SerializedCustomStyle);
                }

                cacheService.Add(cacheKey, result, CachingExpirationType.UsualSingleObject);
            }
            return(result);
        }