コード例 #1
0
        void InitializeTheme()
        {
            var  themesElement  = this.sessionStateService.GetSessionState("Themes");
            bool activeThemeSet = false;

            InitializeThemeCreator();

            if (themesElement == null)
            {
                // No theme data stored in session state yet. Go get the default (if there is one)
                themesElement = ReadDefaultThemesStream();
            }

            if (themesElement != null)
            {
                var activeTheme = themesElement.Attribute("Active");

                foreach (var themeElement in themesElement.Elements("Theme"))
                {
                    var theme = ThemePersistence.LoadTheme(themeElement);

                    Theme.Instance.Themes.Add(theme);
                    if (activeTheme != null && activeTheme.Value == theme.ThemeName)
                    {
                        Theme.Instance.Theme = theme;
                        activeThemeSet       = true;
                    }
                }
            }

            if (!activeThemeSet)
            {
                if (Theme.Instance.Themes.Count == 0)
                {
                    // Make sure at least one theme exists...
                    var defaultTheme = Theme.Instance.ThemeCreator();

                    defaultTheme.ThemeName = "Default Theme";
                    Theme.Instance.Themes.Add(defaultTheme);
                }

                // If no active one specified, pick the first one arbitrarily.
                Theme.Instance.Theme = Theme.Instance.Themes[0];
            }
        }
コード例 #2
0
 void OnSessionStateSaveRequested(object sender, EventArgs e)
 {
     this.sessionStateService.SetSessionState("Themes", new XElement("Themes",
                                                                     new XAttribute("Active", Theme.Instance.Theme.ThemeName),
                                                                     Theme.Instance.Themes.Select(t => ThemePersistence.SaveTheme(t))));
 }