⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 themeutility.cs

📁 一个ASP.NET下的中文内容管理和社区系统
💻 CS
字号:
namespace ASPNET.StarterKit.Communities {
    using System;
    using System.IO;
    using System.Collections;
    using System.Web;

    public class ThemeUtility {

        public static ArrayList GetThemes() {
            ArrayList colThemes = new ArrayList();
            string[] themeDirectories;
        
            // Load List of Common Themes
            string themeDirPath = HttpContext.Current.Server.MapPath( CommunityGlobals.AppPath + "\\Communities\\" );
            try {
                themeDirectories = Directory.GetDirectories( themeDirPath + "Common\\Themes" );
            } catch (DirectoryNotFoundException) {
                throw new Exception( "Themes directory is missing!" );
            }
            
            foreach (string theme in themeDirectories) {
                if (!Path.GetFileName(theme).StartsWith("_") ) {
                    string themeName = Path.GetFileNameWithoutExtension(theme); 
                    string themePath = theme.Remove(0, themeDirPath.Length);
                    themePath = ConvertUrl(themePath);
                    colThemes.Add( new ThemeInfo(themeName, themePath) );
                } 
            }

            // Load List of Community Specific Themes
            themeDirPath = HttpContext.Current.Server.MapPath( CommunityGlobals.AppPath + "\\Communities\\" );
            string fullThemeDirPath = themeDirPath + CommunityGlobals.CommunityName + "\\Themes";
            if (Directory.Exists(fullThemeDirPath)) {
                themeDirectories = Directory.GetDirectories( fullThemeDirPath );
            
                foreach (string theme in themeDirectories) {
                    if (! Path.GetFileName(theme).StartsWith("_") ) {
                        string themeName = Path.GetFileNameWithoutExtension(theme); 
                        string themePath = theme.Remove(0, themeDirPath.Length);
                        themeName = String.Format("{0} ({1})", themeName, CommunityGlobals.CommunityName);
                        themePath = ConvertUrl(themePath);
                        colThemes.Add( new ThemeInfo(themeName, themePath) );
                    } 
                }
            }

            return colThemes;
        }




        public static ArrayList GetStyles() {
            ArrayList colStyles = new ArrayList();
            string[] themeDirectories;
        
            // Load List of Common Styles
            string themeDirPath = HttpContext.Current.Server.MapPath( CommunityGlobals.AppPath + "\\Communities\\" );
            try {
                themeDirectories = Directory.GetDirectories( themeDirPath + "Common\\Themes" );
            } catch (DirectoryNotFoundException) {
                throw new Exception( "Themes directory is missing!" );
            }
            
            foreach (string theme in themeDirectories) {
                if (! Path.GetFileName(theme).StartsWith("_") ) {
                    // Get Style Files
                    string[] styleFiles = Directory.GetFiles(Path.Combine(theme, "Styles"), "*.css");
                    foreach (string style in styleFiles) {
                        string styleName = Path.GetFileNameWithoutExtension(style);
                        string stylePath = style.Remove(0, themeDirPath.Length);
                        stylePath = ConvertUrl(stylePath);
                        // if not default theme show it
                        if (styleName.ToLower() == "default")
                            styleName = Path.GetFileNameWithoutExtension(theme);
                        else
                            styleName = String.Format("{0} {1}", Path.GetFileNameWithoutExtension(theme), styleName );
                        colStyles.Add( new StyleInfo(styleName, stylePath) );
                    }
                } 
            }
            
            // Load List of Community Specific Styles
            themeDirPath = HttpContext.Current.Server.MapPath( CommunityGlobals.AppPath + "\\Communities\\" );
            string fullThemeDirPath = themeDirPath + CommunityGlobals.CommunityName + "\\Themes";
            if (Directory.Exists(fullThemeDirPath) ) {
                themeDirectories = Directory.GetDirectories(fullThemeDirPath);
                
                foreach (string theme in themeDirectories) {
                    if (! Path.GetFileName(theme).StartsWith("_") ) {
                        // Get Style Files
                        string[] styleFiles = Directory.GetFiles(Path.Combine(theme, "Styles"), "*.css");
                        foreach (string style in styleFiles) {
                            string styleName = Path.GetFileNameWithoutExtension(style);
                            string stylePath = style.Remove(0, themeDirPath.Length);
                            stylePath = ConvertUrl(stylePath);
                            // if not default theme show it
                            if (styleName.ToLower() == "default")
                                styleName = String.Format("{0} ({1})", Path.GetFileNameWithoutExtension(theme), CommunityGlobals.CommunityName);
                            else
                                styleName = String.Format("{0} {1} ({2})", Path.GetFileNameWithoutExtension(theme), styleName, CommunityGlobals.CommunityName );
                            colStyles.Add( new StyleInfo(styleName, stylePath) );
                        }
                    } 
                }
            }    
            
            return colStyles;
        }


        private static string ConvertUrl(string path) {
            return path.Replace("\\", "/");
        }


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -