/// <summary>
        /// 获取用户当前选中的皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、群组Id)</param>
        /// <returns></returns>
        public string GetThemeAppearance(long ownerId)
        {
            var groupService = new GroupService();
            GroupEntity group = groupService.Get(ownerId);
            if (group == null)
                return string.Empty;
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.GroupSpace);
            if (pa != null && !pa.EnableThemes)
            {
                return pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey;
            }

            if (group.IsUseCustomStyle)
            {
                return "Default,Default";
            }
            else if (!string.IsNullOrEmpty(group.ThemeAppearance))
            {
                var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfBuiltIn.GroupSpace, group.ThemeAppearance);
                if (appearance != null)
                    return group.ThemeAppearance;
            }

            if (pa != null)
            {
                return pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey;
            }
            return string.Empty;
        }
        /// <summary>
        /// 获取用户当前选中的皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、群组Id)</param>
        /// <returns></returns>
        public string GetThemeAppearance(long ownerId)
        {
            IUserService userService = DIContainer.Resolve<IUserService>();
            User user = userService.GetFullUser(ownerId);
            if (user == null)
                throw new ExceptionFacade("找不到用户");
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace);
            if (pa != null && !pa.EnableThemes)
            {
                return pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey;
            }

            if (user.IsUseCustomStyle)
            {
                return "Default,Default";
            }
            else if (!string.IsNullOrEmpty(user.ThemeAppearance))
            {
                var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfBuiltIn.UserSpace, user.ThemeAppearance);
                if (appearance != null)
                    return user.ThemeAppearance;
            }

            if (pa != null)
            {
                return pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey;
            }

            return string.Empty;
        }
Esempio n. 3
0
        public void IncludeStyle(RequestContext controllerContext)
        {
            ThemeAppearance themeAppearance = GetRequestTheme(controllerContext);
            if (themeAppearance == null)
                return;

            PresentArea presentArea = new PresentAreaService().Get(themeAppearance.PresentAreaKey);
            if (presentArea == null)
                return;

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

            IPageResourceManager resourceManager = DIContainer.ResolvePerHttpRequest<IPageResourceManager>();
            resourceManager.IncludeStyle(themeCssPath);
            resourceManager.IncludeStyle(appearanceCssPath);
        }
Esempio n. 4
0
 /// <summary>
 /// 修改皮肤文件的使用人数
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="eventArgs"></param>
 private void ChangeThemeAppearanceUserCountModule_After(GroupEntity sender, CommonEventArgs eventArgs)
 {
     var themeService = new ThemeService();
     PresentAreaService presentAreaService = new PresentAreaService();
     if (eventArgs.EventOperationType == EventOperationType.Instance().Create())
     {
         var presentArea = presentAreaService.Get(PresentAreaKeysOfBuiltIn.GroupSpace);
         themeService.ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.GroupSpace, null, presentArea.DefaultThemeKey + "," + presentArea.DefaultAppearanceKey);
     }
     else if (eventArgs.EventOperationType == EventOperationType.Instance().Delete())
     {
         var presentArea = presentAreaService.Get(PresentAreaKeysOfBuiltIn.GroupSpace);
         string defaultThemeAppearance = presentArea.DefaultThemeKey + "," + presentArea.DefaultAppearanceKey;
         if (!sender.IsUseCustomStyle)
             themeService.ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.GroupSpace, !string.IsNullOrEmpty(sender.ThemeAppearance) ? sender.ThemeAppearance : defaultThemeAppearance, null);
     }
 }
Esempio n. 5
0
 public ThemeAppearance GetRequestTheme(RequestContext controllerContext)
 {
     string themeKey = null;
     string appearanceKey = null;
     SiteSettings siteSettings = DIContainer.Resolve<ISettingsManager<SiteSettings>>().Get();
     if (!string.IsNullOrEmpty(siteSettings.SiteTheme) && !string.IsNullOrEmpty(siteSettings.SiteThemeAppearance))
     {
         themeKey = siteSettings.SiteTheme;
         appearanceKey = siteSettings.SiteThemeAppearance;
     }
     else
     {
         PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.Channel);
         if (pa != null)
         {
             themeKey = pa.DefaultThemeKey;
             appearanceKey = pa.DefaultAppearanceKey;
         }
     }
     return new ThemeService().GetThemeAppearance(PresentAreaKeysOfBuiltIn.Channel, themeKey, appearanceKey);
 }
        ThemeAppearance IThemeResolver.GetRequestTheme(RequestContext controllerContext)
        {
            string spaceKey = controllerContext.GetParameterFromRouteDataOrQueryString("SpaceKey");
            TopicEntity topic = new TopicService().Get(spaceKey);
            if (topic == null)
                throw new ExceptionFacade("找不到专题");

            string themeKey = null;
            string appearanceKey = null;
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfExtension.TopicSpace);
            if (pa == null)
                throw new ExceptionFacade("找不到专题呈现区域");

            if (pa.EnableThemes)
            {
                if (topic.IsUseCustomStyle)
                {
                    themeKey = "Default";
                    appearanceKey = "Default";
                }
                else
                {
                    string[] themeAppearanceArray = topic.ThemeAppearance.Split(',');
                    var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, topic.ThemeAppearance);

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

            return new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, themeKey, appearanceKey);
        }
Esempio n. 7
0
 /// <summary>
 /// 更新皮肤
 /// </summary>
 /// <param name="ownerId">拥有者Id(如:用户Id、群组Id)</param>
 /// <param name="isUseCustomStyle">是否使用自定义皮肤</param>
 /// <param name="themeAppearance">themeKey与appearanceKey用逗号关联</param>
 public void ChangeThemeAppearance(long ownerId, bool isUseCustomStyle, string themeAppearance)
 {
     SiteSettings siteSettings = DIContainer.Resolve<ISettingsManager<SiteSettings>>().Get();
     string themeKey = null;
     string appearanceKey = null;
     string[] themeAppearanceArray = themeAppearance.Split(',');
     if (themeAppearanceArray.Count() == 2)
     {
         themeKey = themeAppearanceArray[0];
         appearanceKey = themeAppearanceArray[1];
     }
     else
     {
         PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.Channel);
         if (pa != null)
         {
             themeKey = pa.DefaultThemeKey;
             appearanceKey = pa.DefaultAppearanceKey;
         }
     }
     siteSettings.SiteTheme = themeKey;
     siteSettings.SiteThemeAppearance = appearanceKey;
     DIContainer.Resolve<ISettingsManager<SiteSettings>>().Save(siteSettings);
 }
 /// <summary>
 /// 投放区域下拉框
 /// </summary>
 /// <param name="name">viewData名称</param>
 /// <param name="presentAreaKey">当前投放区域</param>
 private void PresentAreasDropDownList(string name, string presentAreaKey)
 {
     List<SelectListItem> areas = new List<SelectListItem>();
     IEnumerable<PresentArea> presentAreas = new PresentAreaService().GetAll().Where(n => n.PresentAreaKey != "ControlPanel");
     foreach (var presentArea in presentAreas)
     {
         areas.Add(new SelectListItem { Text = ResourceAccessor.GetString(presentArea.PresentAreaKey), Value = presentArea.PresentAreaKey });
     }
     ViewData[name] = new SelectList(areas, "value", "text", presentAreaKey);
 }
Esempio n. 9
0
        /// <summary>
        /// 初始化用户的应用
        /// </summary>
        /// <param name="sender">用户实体</param>
        /// <param name="eventArgs">事件参数</param>
        private void InitAppForUserEventMoudle_After(User sender, CreateUserEventArgs eventArgs)
        {
            if (sender == null)
                return;

            applicationService.InstallApplicationsOfPresentAreaOwner(PresentAreaKeysOfBuiltIn.UserSpace, sender.UserId);

            var presentArea = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace);
            new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.UserSpace, null, presentArea.DefaultThemeKey + "," + presentArea.DefaultAppearanceKey);
        }
Esempio n. 10
0
        /// <summary>
        /// 删除ThemeAppearance
        /// </summary>
        /// <param name="presentAreaKey">呈现区域标识</param>
        /// <param name="themeAndAppearance">themeKey与appearanceKey用逗号关联</param>
        public void DeleteThemeAppearance(string presentAreaKey, string themeAndAppearance)
        {
            ThemeAppearance themeAppearance = GetThemeAppearance(presentAreaKey, themeAndAppearance);
            if (themeAppearance == null)
                return;
            PresentArea presentArea = new PresentAreaService().Get(presentAreaKey);
            if (presentArea == null)
                return;
            //默认皮肤不允许删除
            if (presentArea.DefaultAppearanceID == themeAppearance.Id)
                return;
            EventBus<ThemeAppearance>.Instance().OnBefore(themeAppearance, new CommonEventArgs(EventOperationType.Instance().Delete()));
            appearanceRepository.Delete(themeAppearance);

            EventBus<ThemeAppearance>.Instance().OnAfter(themeAppearance, new CommonEventArgs(EventOperationType.Instance().Delete()));
            var themeAppearances = GetThemeAppearances(presentAreaKey, null);
            //若主题下没有外观皮肤,则删除主题;
            if (themeAppearance.ThemeKey.ToLower() != "default" && themeAppearances.Count(n => n.ThemeKey.Equals(themeAppearance.ThemeKey, StringComparison.InvariantCultureIgnoreCase)) == 0)
            {
                themeRepository.DeleteByEntityId(string.Join(",", presentAreaKey, themeAppearance.ThemeKey));
                string themeLocation = WebUtility.GetPhysicalFilePath(string.Format("~/Themes/{0}/{1}", presentAreaKey, themeAppearance.ThemeKey));
                if (Directory.Exists(themeLocation))
                {
                    try
                    {
                        Directory.Delete(themeLocation, true);
                    }
                    catch { }
                }
            }
            else//仅将外观物理文件删除
            {
                string themeAppearanceLocation = WebUtility.GetPhysicalFilePath(string.Format("~/Themes/{0}/{1}/Appearances/{2}", presentAreaKey, themeAppearance.ThemeKey, themeAppearance.AppearanceKey));
                if (Directory.Exists(themeAppearanceLocation))
                {
                    try
                    {
                        Directory.Delete(themeAppearanceLocation, true);
                    }
                    catch { }
                }
            }
        }
        void IThemeResolver.IncludeStyle(RequestContext controllerContext)
        {
            string spaceKey = controllerContext.GetParameterFromRouteDataOrQueryString("SpaceKey");
            TopicEntity topic = new TopicService().Get(spaceKey);
            if (topic == null)
                return;
            PresentArea presentArea = new PresentAreaService().Get(PresentAreaKeysOfExtension.TopicSpace);
            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 (topic.IsUseCustomStyle)
            {
                var customStyleEntity = new CustomStyleService().Get(presentArea.PresentAreaKey, topic.TopicId);
                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, topic.TopicId);
                resourceManager.IncludeStyle(themeCssPath);
                resourceManager.IncludeStyle(appearanceCssPath);
                StringBuilder builder = new StringBuilder();
                builder.AppendLine(".tn-page-bg{");
                if (customStyle.IsUseBackgroundImage && !string.IsNullOrEmpty(customStyle.BackgroundImageStyle.Url))
                {
                    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("}");

                resourceManager.RegisterStyleBlock(builder.ToString());
            }
            else
            {
                string[] themeAppearanceArray = topic.ThemeAppearance.Split(',');
                var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, topic.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);
            }


        }
Esempio n. 12
0
        private void DeleteUserEventMoudle_After(IUser sender, DeleteUserEventArgs eventArgs)
        {
            IUserService userService = DIContainer.Resolve<IUserService>();

            #region 数据
            //清除应用数据
            applicationService.DeleteUser(sender.UserId, eventArgs.TakeOverUserName, eventArgs.TakeOverAll);

            //删除用户信息
            new UserProfileService().Delete(sender.UserId);

            //清除用户内容计数数据
            OwnerDataService ownerDataService = new OwnerDataService(TenantTypeIds.Instance().User());
            ownerDataService.ClearOwnerData(sender.UserId);

            //清除用户关于分类的数据
            CategoryService categoryService = new CategoryService();
            categoryService.CleanByUser(sender.UserId);

            //清除用户动态
            ActivityService activityService = new ActivityService();
            activityService.CleanByUser(sender.UserId);

            //清除用户评论
            new CommentService().DeleteUserComments(sender.UserId, false);

            #endregion

            #region 消息

            //清除用户关于私信的数据
            MessageService messageService = new MessageService();
            messageService.ClearSessionsFromUser(sender.UserId);

            //清除请求的用户数据
            InvitationService invitationService = new InvitationService();
            invitationService.CleanByUser(sender.UserId);

            //清除通知的用户数据
            NoticeService noticeService = new NoticeService();
            noticeService.CleanByUser(sender.UserId);

            InviteFriendService inviteFriendService = new InviteFriendService();
            inviteFriendService.CleanByUser(sender.UserId);

            //清除站外提醒的用户数据
            ReminderService reminderService = new ReminderService();
            reminderService.CleanByUser(sender.UserId);

            #endregion

            #region 关注/访客

            //清除用户关于关注用户的数据
            FollowService followService = new FollowService();
            followService.CleanByUser(sender.UserId);

            //清除访客记录的用户数据
            VisitService visitService = new VisitService(string.Empty);
            visitService.CleanByUser(sender.UserId);

            #endregion

            #region 帐号

            //清除帐号绑定数据
            var accountBindingService = new AccountBindingService();
            var accountBindings = new AccountBindingService().GetAccountBindings(sender.UserId);
            foreach (var accountBinding in accountBindings)
            {
                accountBindingService.DeleteAccountBinding(accountBinding.UserId, accountBinding.AccountTypeKey);
            }

            #endregion

            #region 装扮

            //调整皮肤文件使用次数
            var user = userService.GetFullUser(sender.UserId);
            if (user == null)
                return;
            var presentArea = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace);
            string defaultThemeAppearance = string.Join(",", presentArea.DefaultThemeKey, presentArea.DefaultAppearanceKey);
            if (!user.IsUseCustomStyle)
                new ThemeService().ChangeThemeAppearanceUserCount(PresentAreaKeysOfBuiltIn.UserSpace, null, !string.IsNullOrEmpty(user.ThemeAppearance) ? user.ThemeAppearance : defaultThemeAppearance);

            #endregion
        }
        /// <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);
            }
        }
        /// <summary>
        /// 验证当前用户是否修改皮肤的权限
        /// </summary>
        /// <param name="ownerId"></param>
        /// <returns></returns>
        public bool Validate(long ownerId)
        {
            IUser currentUser = UserContext.CurrentUser;
            if (currentUser == null)
                return false;
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfExtension.TopicSpace);
            if (!pa.EnableThemes)
                return false;

            if (DIContainer.Resolve<Authorizer>().Topic_Manage(new TopicService().Get(ownerId)))
                return true;
            return false;
        }
        /// <summary>
        /// 获取用户当前选中的皮肤
        /// </summary>
        /// <param name="ownerId">拥有者Id(如:用户Id、专题Id)</param>
        /// <returns></returns>
        public string GetThemeAppearance(long ownerId)
        {
            var topicService = new TopicService();
            TopicEntity topic = topicService.Get(ownerId);
            if (topic == null)
                return string.Empty;
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfExtension.TopicSpace);
            if (pa != null && !pa.EnableThemes)
            {
                return pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey;
            }

            if (topic.IsUseCustomStyle)
            {
                return "Default,Default";
            }
            else if (!string.IsNullOrEmpty(topic.ThemeAppearance))
            {
                var appearance = new ThemeService().GetThemeAppearance(PresentAreaKeysOfExtension.TopicSpace, topic.ThemeAppearance);
                if (appearance != null)
                    return topic.ThemeAppearance;
            }

            if (pa != null)
            {
                return pa.DefaultThemeKey + "," + pa.DefaultAppearanceKey;
            }
            return string.Empty;
        }
 /// <summary>
 /// 验证当前用户是否修改皮肤的权限
 /// </summary>
 /// <param name="ownerId"></param>
 /// <returns></returns>
 public bool Validate(long ownerId)
 {
     IUser currentUser = UserContext.CurrentUser;
     if (currentUser == null)
         return false;
     PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace);
     if (!pa.EnableThemes)
         return false;
     if (currentUser.UserId == ownerId || currentUser.IsSuperAdministrator() || currentUser.IsContentAdministrator())
         return true;
     return false;
 }
        /// <summary>
        /// 获取请求页面使用的皮肤
        /// </summary>
        /// <param name="controllerContext"><see cref="RequestContext"/></param>
        ThemeAppearance IThemeResolver.GetRequestTheme(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));

            string themeKey = null;
            string appearanceKey = null;
            PresentArea pa = new PresentAreaService().Get(PresentAreaKeysOfBuiltIn.UserSpace);
            if (pa == null)
                throw new ExceptionFacade("找不到用户空间呈现区域");

            if (pa.EnableThemes)
            {
                if (user.IsUseCustomStyle)
                {
                    themeKey = "Default";
                    appearanceKey = "Default";
                }
                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];
                    }
                }
            }

            if (themeKey == null || appearanceKey == null)
            {
                themeKey = pa.DefaultThemeKey;
                appearanceKey = pa.DefaultAppearanceKey;
            }

            return new ThemeService().GetThemeAppearance(PresentAreaKeysOfBuiltIn.UserSpace, themeKey, appearanceKey);
        }