Beispiel #1
0
        public async Task DisableThemeFeaturesAsync(string themeName)
        {
            var themes = new Queue <string>();

            while (themeName != null)
            {
                if (themes.Contains(themeName))
                {
                    throw new InvalidOperationException(H["The theme \"{0}\" is already in the stack of themes that need features disabled.", themeName].ToString());
                }
                var theme = _extensionManager.GetExtension(themeName);
                if (theme == null)
                {
                    break;
                }
                themes.Enqueue(themeName);

                themeName = !string.IsNullOrWhiteSpace(theme.Manifest.Name)
                    ? theme.Manifest.Name
                    : null;
            }

            var currentTheme = await _siteThemeService.GetCurrentThemeNameAsync();

            while (themes.Count > 0)
            {
                var themeId = themes.Dequeue();

                // Not disabling base theme if it's the current theme.
                if (themeId != currentTheme)
                {
                    await DisableFeaturesAsync(new[] { themeId }, true);
                }
            }
        }
Beispiel #2
0
        public async Task <ActionResult> Index()
        {
            var model = new SelectThemesViewModel
            {
                SiteThemeName  = await _siteThemeService.GetCurrentThemeNameAsync(),
                AdminThemeName = await _adminThemeService.GetAdminThemeNameAsync()
            };

            return(View(model));
        }
Beispiel #3
0
        public async Task <ThemeSelectorResult> GetThemeAsync()
        {
            string currentThemeName = await _siteThemeService.GetCurrentThemeNameAsync();

            if (String.IsNullOrEmpty(currentThemeName))
            {
                return(null);
            }

            return(new ThemeSelectorResult
            {
                Priority = 0,
                ThemeName = currentThemeName
            });
        }
        public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result)
        {
            var themesState = step as ThemesDeploymentStep;

            if (themesState == null)
            {
                return;
            }

            result.Steps.Add(new JObject(
                                 new JProperty("name", "Themes"),
                                 new JProperty(nameof(ThemeStepModel.Site), await _siteThemeService.GetCurrentThemeNameAsync()),
                                 new JProperty(nameof(ThemeStepModel.Admin), await _adminThemeService.GetAdminThemeNameAsync())
                                 ));
        }
        public async Task <ThemeSelectorResult> GetThemeAsync()
        {
            var context = _httpContextAccessor.HttpContext;

            if (!context.User.IsInRole(RequiredRole))
            {
                return(null);
            }

            var currentThemeName = await _siteThemeService.GetCurrentThemeNameAsync();

            if (string.IsNullOrEmpty(currentThemeName))
            {
                return(null);
            }

            // Try cookies.
            context.Request.Cookies.TryGetValue(CookieName, out var themeName);

            // Try query string. Query string takes precedence.
            context.Request.Query.TryGetValue(QueryStringKey, out var values);
            if (!StringValues.IsNullOrEmpty(values))
            {
                themeName = values.First();
            }

            if (string.IsNullOrWhiteSpace(themeName))
            {
                return(null);
            }

            // Non-persistent cookie. Available only during session.
            context.Response.Cookies.Append(CookieName, themeName);

            // Priority should override current theme priority, but not admin theme priority.
            // Admin Theme Priority = 100
            // Current Theme Priority = 0
            return(new ThemeSelectorResult {
                Priority = Priority,
                ThemeName = themeName
            });
        }