예제 #1
0
        private async Task LoadHighlightJSThemesAsync()
        {
            Package package    = AreaRegistration.CurrentPackage;
            string  url        = VersionManager.GetAddOnNamedUrl(package.AreaName, "SkinHighlightJS");
            string  customUrl  = VersionManager.GetCustomUrlFromUrl(url);
            string  path       = Utility.UrlToPhysical(url);
            string  customPath = Utility.UrlToPhysical(customUrl);

            // use custom or default theme list
            string themeFile = HighlightJSThemeFile;
            string filename  = Path.Combine(customPath, themeFile);

            if (!await FileSystem.FileSystemProvider.FileExistsAsync(filename))
            {
                filename = Path.Combine(path, themeFile);
            }

            List <string> lines = await FileSystem.FileSystemProvider.ReadAllLinesAsync(filename);

            List <HighlightJSTheme> HighlightJSList = new List <HighlightJSTheme>();

            foreach (string line in lines)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                string name = line.Trim();
#if DEBUG // only validate files in debug builds
                string f = Path.Combine(path, "themes", name) + ".css";
                if (!await FileSystem.FileSystemProvider.FileExistsAsync(f))
                {
                    throw new InternalError("HighlightJS theme file not found: {0} - {1}", line, f);
                }
#endif
                HighlightJSList.Add(new HighlightJSTheme {
                    Name = name,
                });
            }
            if (HighlightJSList.Count == 0)
            {
                throw new InternalError("No HighlightJS themes found");
            }

            _HighlightJSThemeDefault = HighlightJSList[0];
            _HighlightJSThemeList    = (from theme in HighlightJSList orderby theme.Name select theme).ToList();
        }
예제 #2
0
        public async Task <ActionResult> SkinSyntaxHighlighter()
        {
            ConfigData config = await ConfigDataProvider.GetConfigAsync();

            // find theme specific skin
            Package    package    = AreaRegistration.CurrentPackage;
            SkinAccess skinAccess = new SkinAccess();
            string     theme      = skinAccess.FindSyntaxHighlighterSkin(config.SyntaxHighlighterSkin);
            await Manager.AddOnManager.AddAddOnNamedAsync(package.AreaName, "SkinSyntaxHighlighter", theme);

            // add client-side init
            string url = VersionManager.GetAddOnNamedUrl(package.AreaName, "SkinSyntaxHighlighter");

            Manager.ScriptManager.AddLast("AlexGorbatchevCom_SyntaxHighlighter", "YetaWF_SyntaxHighlighter.AlexGorbatchevCom.init('" + url + "');");

            return(new EmptyResult());
        }
        private async Task LoadSyntaxHighlighterThemesAsync()
        {
            Package package    = AreaRegistration.CurrentPackage;
            string  url        = VersionManager.GetAddOnNamedUrl(package.AreaName, "SkinSyntaxHighlighter");
            string  customUrl  = VersionManager.GetCustomUrlFromUrl(url);
            string  path       = Utility.UrlToPhysical(url);
            string  customPath = Utility.UrlToPhysical(customUrl);

            // use custom or default theme list
            string themeFile;

            if (Utility.AspNetMvc == Utility.AspNetMvcVersion.MVC5)
            {
                themeFile = SyntaxHighlighterThemeFileMVC5;
            }
            else
            {
                themeFile = SyntaxHighlighterThemeFileMVC6;
            }
            string filename = Path.Combine(customPath, themeFile);

            if (!await FileSystem.FileSystemProvider.FileExistsAsync(filename))
            {
                filename = Path.Combine(path, themeFile);
            }

            List <string> lines = await FileSystem.FileSystemProvider.ReadAllLinesAsync(filename);

            List <SyntaxHighlighterTheme> syntaxHighlighterList = new List <SyntaxHighlighterTheme>();

            foreach (string line in lines)
            {
                if (string.IsNullOrWhiteSpace(line))
                {
                    continue;
                }
                string[] s    = line.Split(new char[] { ',' }, 3);
                string   name = s[0].Trim();
                if (string.IsNullOrWhiteSpace(name))
                {
                    throw new InternalError("Invalid/empty SyntaxHighlighter theme name");
                }
                if (s.Length < 2)
                {
                    throw new InternalError("Invalid SyntaxHighlighter theme entry: {0}", line);
                }
                string file = s[1].Trim();
#if DEBUG // only validate files in debug builds
                if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
                {
                    url = url.Replace('/', '\\');
                }
                if (file.StartsWith("\\") || file.StartsWith("/"))
                {
                    string f = Path.Combine(YetaWFManager.RootFolder, file.Substring(1));
                    if (!await FileSystem.FileSystemProvider.FileExistsAsync(f))
                    {
                        throw new InternalError("SyntaxHighlighter theme file not found: {0} - {1}", line, f);
                    }
                }
                else
                {
                    string f = Path.Combine(path, file);
                    if (!await FileSystem.FileSystemProvider.FileExistsAsync(f))
                    {
                        throw new InternalError("SyntaxHighlighter theme file not found: {0} - {1}", line, f);
                    }
                }
#endif
                string description = null;
                if (s.Length > 2)
                {
                    description = s[2].Trim();
                }
                if (string.IsNullOrWhiteSpace(description))
                {
                    description = null;
                }
                syntaxHighlighterList.Add(new SyntaxHighlighterTheme {
                    Name        = name,
                    Description = description,
                    File        = file,
                });
            }
            if (syntaxHighlighterList.Count == 0)
            {
                throw new InternalError("No SyntaxHighlighter themes found");
            }

            _syntaxHighlighterThemeDefault = syntaxHighlighterList[0];
            SyntaxHighlighterThemeList     = (from theme in syntaxHighlighterList orderby theme.Name select theme).ToList();
        }