Beispiel #1
0
        /// <summary>
        /// 新建实体时使用
        /// </summary>
        public static CustomStyle New()
        {
            CustomStyle customStyle = new CustomStyle()
            {
                BackgroundImage = string.Empty,
                ImageUrl        = string.Empty,
                LastModified    = DateTime.UtcNow
            };

            return(customStyle);
        }
Beispiel #2
0
        /// <summary>
        /// 加载皮肤的css
        /// </summary>
        /// <param name="controllerContext"><see cref="RequestContext"/></param>
        void IThemeResolver.IncludeStyle(RequestContext controllerContext)
        {
            string spaceKey = controllerContext.GetParameterFromRouteDataOrQueryString("SpaceKey");

            if (String.IsNullOrEmpty(spaceKey))
            {
                spaceKey = UserContext.CurrentUser.UserName;
            }
            IUserService userService = DIContainer.Resolve <IUserService>();
            User         user        = userService.GetFullUser(spaceKey);

            if (user == null)
            {
                throw new ExceptionFacade(new ResourceExceptionDescriptor().WithUserNotFound(spaceKey, 0));
            }

            PresentArea presentArea = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace);

            if (presentArea == null)
            {
                return;
            }

            string themeKey      = null;
            string appearanceKey = null;

            IPageResourceManager resourceManager = DIContainer.ResolvePerHttpRequest <IPageResourceManager>();

            if (!presentArea.EnableThemes)
            {
                string themeCssPath      = string.Format("{0}/{1}/theme.css", presentArea.ThemeLocation, presentArea.DefaultThemeKey);
                string appearanceCssPath = string.Format("{0}/{1}/Appearances/{2}/appearance.css", presentArea.ThemeLocation, presentArea.DefaultThemeKey, presentArea.DefaultAppearanceKey);

                resourceManager.IncludeStyle(themeCssPath);
                resourceManager.IncludeStyle(appearanceCssPath);
                return;
            }

            if (user.IsUseCustomStyle)
            {
                var customStyleEntity = new CustomStyleService().Get(presentArea.PresentAreaKey, user.UserId);
                if (customStyleEntity == null)
                {
                    return;
                }
                CustomStyle customStyle = customStyleEntity.CustomStyle;
                if (customStyle == null)
                {
                    return;
                }
                string themeCssPath      = string.Format("{0}/Custom/theme{1}.css", presentArea.ThemeLocation, customStyle.IsDark ? "-deep" : "");
                string appearanceCssPath = SiteUrls.Instance().CustomStyle(presentArea.PresentAreaKey, user.UserId);
                resourceManager.IncludeStyle(themeCssPath);
                resourceManager.IncludeStyle(appearanceCssPath);
                StringBuilder builder = new StringBuilder();
                builder.AppendLine(".tn-page-bg{");
                if (customStyle.IsUseBackgroundImage)
                {
                    builder.AppendLine("background-image:url('" + customStyle.BackgroundImageStyle.Url + @"');");
                    builder.AppendFormat("background-repeat:{0};\n", customStyle.BackgroundImageStyle.IsRepeat ? "repeat" : "no-repeat");
                    builder.AppendFormat("background-attachment:{0};\n", customStyle.BackgroundImageStyle.IsFix ? "fixed" : "scroll");
                    string position = "center";
                    switch (customStyle.BackgroundImageStyle.BackgroundPosition)
                    {
                    case BackgroundPosition.Left:
                        position = "left";
                        break;

                    case BackgroundPosition.Center:
                        position = "center";
                        break;

                    case BackgroundPosition.Right:
                        position = "right";
                        break;

                    default:
                        position = "center";
                        break;
                    }
                    builder.AppendFormat("background-position:{0} top;\n", position);
                }

                builder.AppendLine("}");
                builder.AppendLine("#tn-content{");
                builder.AppendLine("margin-top:" + customStyle.HeaderHeight.ToString() + "px;");
                builder.AppendLine("}");
                resourceManager.RegisterStyleBlock(builder.ToString());
            }
            else
            {
                string[] themeAppearanceArray = user.ThemeAppearance.Split(',');
                var      appearance           = new ThemeService().GetThemeAppearance(PresentAreaKeysOfBuiltIn.UserSpace, user.ThemeAppearance);

                if (appearance != null && themeAppearanceArray.Count() == 2)
                {
                    themeKey      = themeAppearanceArray[0];
                    appearanceKey = themeAppearanceArray[1];
                }
                else
                {
                    themeKey      = presentArea.DefaultThemeKey;
                    appearanceKey = presentArea.DefaultAppearanceKey;
                }

                string themeCssPath      = string.Format("{0}/{1}/theme.css", presentArea.ThemeLocation, themeKey);
                string appearanceCssPath = string.Format("{0}/{1}/Appearances/{2}/appearance.css", presentArea.ThemeLocation, themeKey, appearanceKey);

                resourceManager.IncludeStyle(themeCssPath);
                resourceManager.IncludeStyle(appearanceCssPath);
            }
        }
Beispiel #3
0
 /// <summary>
 /// 保存自定义皮肤
 /// </summary>
 /// <param name="presentAreaKey"></param>
 /// <param name="ownerId"></param>
 /// <param name="customStyle"></param>
 /// <returns></returns>
 public ActionResult _SaveCustomSettings(string presentAreaKey, long ownerId, CustomStyle customStyle)
 {
     if (!ThemeService.Validate(presentAreaKey, ownerId))
         return Json(new StatusMessageData(StatusMessageType.Error, "没有设置皮肤的权限"));
     new CustomStyleService().Save(presentAreaKey, ownerId, customStyle);
     ThemeService.ChangeThemeAppearance(presentAreaKey, ownerId, true, string.Empty);
     return Json(new StatusMessageData(StatusMessageType.Success, "保存成功!"));
 }
Beispiel #4
0
        /// <summary>
        /// 获取预置的配色方案
        /// </summary>
        /// <param name="presentAreaKey"></param>
        public IEnumerable<CustomStyle> GetColorSchemes(string presentAreaKey)
        {
            string cacheKey = "ColorSchemes-" + presentAreaKey;
            List<CustomStyle> customStyles = cacheService.Get<List<CustomStyle>>(cacheKey);
            if (customStyles == null)
            {
                customStyles = new List<CustomStyle>();
                XElement colorSchemesElement = XElement.Load(WebUtility.GetPhysicalFilePath(string.Format("~/Themes/{0}/Custom/ColorScheme.config", presentAreaKey)));
                if (colorSchemesElement != null)
                {
                    IEnumerable<XElement> colorSchemeElements = colorSchemesElement.Elements("colorScheme");
                    foreach (XElement colorSchemeElement in colorSchemeElements)
                    {
                        Dictionary<string, string> definedColours = new Dictionary<string, string>();
                        CustomStyle customStyle = new CustomStyle();
                        var isDarkAttr = colorSchemeElement.Attribute("isDark");
                        bool isDark = false;
                        if (isDarkAttr != null)
                            bool.TryParse(isDarkAttr.Value, out isDark);
                        customStyle.IsDark = isDark;
                        var imageUrlAttr = colorSchemeElement.Attribute("imageUrl");
                        if (imageUrlAttr != null)
                            customStyle.ImageUrl = imageUrlAttr.Value;

                        IEnumerable<XElement> colorElements = colorSchemeElement.Elements("color");
                        foreach (XElement colorElement in colorElements)
                        {
                            var labelAttr = colorElement.Attribute("label");
                            if (labelAttr == null)
                                continue;
                            string colorLabel = labelAttr.Value;
                            var valueAttr = colorElement.Attribute("value");
                            if (valueAttr == null)
                                continue;
                            definedColours[colorLabel] = valueAttr.Value;
                        }
                        customStyle.DefinedColours = definedColours;
                        customStyles.Add(customStyle);
                    }
                }
                cacheService.Add(cacheKey, customStyles, CachingExpirationType.RelativelyStable);
            }
            return customStyles;
        }
Beispiel #5
0
 /// <summary>
 /// 把CustomStyleEntity对象转换成xml
 /// </summary>
 /// <param name="customStyle">被转换的对象</param>
 /// <returns>序列化后的xml字符串</returns>
 private string Serialize(CustomStyle customStyle)
 {
     string xml = null;
     if (customStyle != null)
     {
         xml = Json.Encode(customStyle);
     }
     return xml;
 }
Beispiel #6
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)
        {
            Database 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);
        }
 /// <summary>
 /// 保存用户自定义风格
 /// </summary>
 /// <param name="presentAreaKey">呈现区域标识</param>
 /// <param name="ownerId">OwnerId</param>
 /// <param name="customStyle">自定义风格实体</param>
 public void Save(string presentAreaKey, long ownerId, CustomStyle customStyle)
 {
     //如果 presentAreaKey+ownerId 存在则更新,否则创建
     customStyleRepository.Save(presentAreaKey, ownerId, customStyle);
 }
Beispiel #8
0
 /// <summary>
 /// 新建实体时使用
 /// </summary>
 public static CustomStyle New()
 {
     CustomStyle customStyle = new CustomStyle()
     {
         BackgroundImage = string.Empty,
         ImageUrl = string.Empty,
         LastModified = DateTime.UtcNow
     };
     return customStyle;
 }
Beispiel #9
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)
 {
     //如果 presentAreaKey+ownerId 存在则更新,否则创建
     customStyleRepository.Save(presentAreaKey, ownerId, customStyle);
 }