コード例 #1
0
 public async Task ChangeUiTheme(ChangeUiThemeInput input)
 {
     await SettingManager.ChangeSettingForUserAsync(
         StudioXSession.ToUserIdentifier(),
         AppSettingNames.UiTheme,
         input.Theme
         );
 }
コード例 #2
0
        public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "")
        {
            if (!GlobalizationHelper.IsValidCultureCode(cultureName))
            {
                throw new StudioXException("Unknown language: " + cultureName + ". It must be a valid culture!");
            }

            var cookieValue = CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(cultureName, cultureName));

            Response.Cookies.Append(
                CookieRequestCultureProvider.DefaultCookieName,
                cookieValue,
                new CookieOptions {
                Expires = Clock.Now.AddYears(2)
            }
                );

            if (StudioXSession.UserId.HasValue)
            {
                SettingManager.ChangeSettingForUser(
                    StudioXSession.ToUserIdentifier(),
                    LocalizationSettingNames.DefaultLanguage,
                    cultureName
                    );
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(new AjaxResponse()));
            }

            if (!string.IsNullOrWhiteSpace(returnUrl) && StudioXUrlHelper.IsLocalUrl(Request, returnUrl))
            {
                return(Redirect(returnUrl));
            }

            return(Redirect("/")); //TODO: Go to app root
        }
コード例 #3
0
        public virtual ActionResult ChangeCulture(string cultureName, string returnUrl = "")
        {
            if (!GlobalizationHelper.IsValidCultureCode(cultureName))
            {
                throw new StudioXException("Unknown language: " + cultureName + ". It must be a valid culture!");
            }

            Response.Cookies.Add(
                new HttpCookie(webLocalizationConfiguration.CookieName, cultureName)
            {
                Expires = Clock.Now.AddYears(2),
                Path    = Request.ApplicationPath
            }
                );

            if (StudioXSession.UserId.HasValue)
            {
                SettingManager.ChangeSettingForUser(
                    StudioXSession.ToUserIdentifier(),
                    LocalizationSettingNames.DefaultLanguage,
                    cultureName
                    );
            }

            if (Request.IsAjaxRequest())
            {
                return(Json(new AjaxResponse(), JsonRequestBehavior.AllowGet));
            }

            if (!string.IsNullOrWhiteSpace(returnUrl) && Request.Url != null && StudioXUrlHelper.IsLocalUrl(Request.Url, returnUrl))
            {
                return(Redirect(returnUrl));
            }

            return(Redirect(Request.ApplicationPath));
        }
コード例 #4
0
ファイル: SettingManager.cs プロジェクト: longhuynh/studiox
        /// <inheritdoc />
        public async Task <IReadOnlyList <ISettingValue> > GetAllSettingValuesAsync(SettingScopes scopes)
        {
            var settingDefinitions = new Dictionary <string, SettingDefinition>();
            var settingValues      = new Dictionary <string, ISettingValue>();

            //Fill all setting with default values.
            foreach (var setting in settingDefinitionManager.GetAllSettingDefinitions())
            {
                settingDefinitions[setting.Name] = setting;
                settingValues[setting.Name]      = new SettingValueObject(setting.Name, setting.DefaultValue);
            }

            //Overwrite application settings
            if (scopes.HasFlag(SettingScopes.Application))
            {
                foreach (var settingValue in await GetAllSettingValuesForApplicationAsync())
                {
                    var setting = settingDefinitions.GetOrDefault(settingValue.Name);

                    //TODO: Conditions get complicated, try to simplify it
                    if (setting == null || !setting.Scopes.HasFlag(SettingScopes.Application))
                    {
                        continue;
                    }

                    if (!setting.IsInherited &&
                        (setting.Scopes.HasFlag(SettingScopes.Tenant) && StudioXSession.TenantId.HasValue ||
                         setting.Scopes.HasFlag(SettingScopes.User) && StudioXSession.UserId.HasValue))
                    {
                        continue;
                    }

                    settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value);
                }
            }

            //Overwrite tenant settings
            if (scopes.HasFlag(SettingScopes.Tenant) && StudioXSession.TenantId.HasValue)
            {
                foreach (var settingValue in await GetAllSettingValuesForTenantAsync(StudioXSession.TenantId.Value))
                {
                    var setting = settingDefinitions.GetOrDefault(settingValue.Name);

                    //TODO: Conditions get complicated, try to simplify it
                    if (setting == null || !setting.Scopes.HasFlag(SettingScopes.Tenant))
                    {
                        continue;
                    }

                    if (!setting.IsInherited && setting.Scopes.HasFlag(SettingScopes.User) &&
                        StudioXSession.UserId.HasValue)
                    {
                        continue;
                    }

                    settingValues[settingValue.Name] = new SettingValueObject(settingValue.Name, settingValue.Value);
                }
            }

            //Overwrite user settings
            if (scopes.HasFlag(SettingScopes.User) && StudioXSession.UserId.HasValue)
            {
                foreach (var settingValue in await GetAllSettingValuesForUserAsync(StudioXSession.ToUserIdentifier()))
                {
                    var setting = settingDefinitions.GetOrDefault(settingValue.Name);
                    if (setting != null && setting.Scopes.HasFlag(SettingScopes.User))
                    {
                        settingValues[settingValue.Name] =
                            new SettingValueObject(settingValue.Name, settingValue.Value);
                    }
                }
            }

            return(settingValues.Values.ToImmutableList());
        }