예제 #1
0
        /// <summary>
        /// Clones the given theme.
        /// </summary>
        /// <param name="sourceId">An Id of the theme to clone.</param>
        /// <param name="name">The name for a new theme.</param>
        /// <param name="overrides">Theme overrides.</param>
        /// <returns>New theme.</returns>
        public UserTheme CloneTheme(string sourceId, string name, ThemeMetadata overrides)
        {
            UserTheme ret              = null;
            int       userId           = GetUserId();
            string    cssText          = string.Empty;
            string    fullPhysicalPath = string.Empty;
            string    newId            = ThemeSource.MakeId(name);

            ThemeMetadata.ExCSSStylesheet stylesheet = null;
            string fullPhysicalPathDirectoryName     = string.Empty;
            string fullPath = string.Format("~/App_Data/Themes/{0}/{1}.css", userId, name);

            if (userId > 0)
            {
                stylesheet = new ThemeMetadata.ExCSSStylesheet(sourceId, ThemeMetadata.ResolveThemeContents(sourceId));

                if (overrides != null)
                {
                    stylesheet.FontFamily      = overrides.FontFamily;
                    stylesheet.FontColor       = overrides.FontColor;
                    stylesheet.AccentColor1    = overrides.AccentColor1;
                    stylesheet.AccentColor2    = overrides.AccentColor2;
                    stylesheet.AccentColor3    = overrides.AccentColor3;
                    stylesheet.AccentColor4    = overrides.AccentColor4;
                    stylesheet.BackgroundColor = overrides.BackgroundColor;
                    stylesheet.BackgroundImage = overrides.BackgroundImage ?? string.Empty;
                    stylesheet.Logo            = overrides.Logo;
                }

                cssText = stylesheet.ToString();
                cssText = Regex.Replace(cssText, string.Concat("\\.theme-", sourceId), string.Concat(".theme-", newId), RegexOptions.IgnoreCase);

                fullPhysicalPath = HttpContext.Current.Server.MapPath(fullPath);
                fullPhysicalPathDirectoryName = System.IO.Path.GetDirectoryName(fullPhysicalPath);

                if (!System.IO.Directory.Exists(fullPhysicalPathDirectoryName))
                {
                    System.IO.Directory.CreateDirectory(fullPhysicalPathDirectoryName);
                }

                System.IO.File.WriteAllText(fullPhysicalPath, cssText, System.Text.Encoding.UTF8);

                ret = ThemeSource.CreateThemeInstance <UserTheme>(fullPhysicalPath, t => t.PhysicalPath = fullPhysicalPath, true);
            }

            return(ret);
        }
예제 #2
0
        /// <summary>
        /// Tries to re-map theme background image for a iven presentation.
        /// </summary>
        /// <param name="p">Presentation.</param>
        /// <returns>Presentation.</returns>
        public static Presentation TryRemapThemeBackgroundImage(Presentation p)
        {
            ThemeMetadata metadata = null;

            if (p != null && string.IsNullOrWhiteSpace(p.BackgroundImage))
            {
                metadata = ThemeMetadata.ParseMetadata(p.Theme);

                // We have a nice rendering for background image on the front-end. We don't want to duplicate this functionality but we'd rather put theme BG image as user-specified one.
                if (metadata != null)
                {
                    p.BackgroundImage = metadata.BackgroundImage;
                }
            }

            return(p);
        }
예제 #3
0
        /// <summary>
        /// Parses metadata from a given CSS text.
        /// </summary>
        /// <param name="id">Theme Id.</param>
        /// <param name="css">Theme CSS.</param>
        /// <returns>Theme parsed metadata.</returns>
        public static ThemeMetadata ParseMetadata(string id, string css)
        {
            ExCSSStylesheet stylesheet = null;
            ThemeMetadata   ret        = new ThemeMetadata();

            if (!string.IsNullOrEmpty(css) && !string.IsNullOrEmpty(id))
            {
                stylesheet = new ExCSSStylesheet(id, css);

                ret.FontFamily      = stylesheet.FontFamily;
                ret.FontColor       = stylesheet.FontColor;
                ret.AccentColor1    = stylesheet.AccentColor1;
                ret.AccentColor2    = stylesheet.AccentColor2;
                ret.AccentColor3    = stylesheet.AccentColor3;
                ret.AccentColor4    = stylesheet.AccentColor4;
                ret.BackgroundColor = stylesheet.BackgroundColor;
                ret.BackgroundImage = stylesheet.BackgroundImage;
                ret.Logo            = stylesheet.Logo;
            }

            return(ret);
        }