示例#1
0
        public string ReplaceBypassKeysInHtml(string pagePath, string pageString)
        {
            if (!_options.Pages.ContainsKey(pagePath))
            {
                return(pageString);
            }

            var page = _options.Pages[pagePath];

            if (page.JsFiles != null && page.JsFiles.Count > 0)//page has js files
            {
                foreach (var pageJsFileName in page.JsFiles)
                {
                    if (_options.JSFiles.ContainsKey(pageJsFileName))//options contains js file
                    {
                        var jsFile = _options.JSFiles[pageJsFileName];
                        pageString = _stringReplacer.SafeReplace(pageString, jsFile.FileName);//replace file names with unique key so that url blocking cant catch your js file
                        pageString = _stringReplacer.SafeReplace(pageString, jsFile.KeysToReplace);
                    }
                }
            }

            if (page.CssFiles != null && page.JsFiles.Count > 0)
            {
                foreach (var pageCssFileName in page.CssFiles)
                {
                    if (_options.CSSFiles.ContainsKey(pageCssFileName))
                    {
                        var cssFile = _options.CSSFiles[pageCssFileName];
                        pageString = _stringReplacer.SafeReplace(pageString, cssFile.FileName);//replace file names with unique key so that url blocking cant catch your
                        pageString = _stringReplacer.SafeReplace(pageString, cssFile.KeysToReplace);
                    }
                }
            }

            if (page.AnotherKeysToReplace != null && page.AnotherKeysToReplace.Count > 0)
            {
                pageString = _stringReplacer.SafeReplace(pageString, page.AnotherKeysToReplace);
            }
            return(pageString);
        }
示例#2
0
        public string ProvideCssJsFileString(string fileKey)
        {
            var keyInformation = _keyProvider.GetValueFromMatchedGuid(fileKey);//get file name with given key (find which file does user want)

            if (keyInformation == null)
            {
                return(null);                                           //check whether file exist
            }
            string fileString = GetFileStringFromCache(keyInformation); //get from cache

            if (!string.IsNullOrEmpty(fileString))
            {
                return(fileString);
            }

            ABBFile file;
            string  filePath = "";

            if (Path.GetExtension(keyInformation.Value) == ".css" && _options.CSSFiles.ContainsKey(keyInformation.Value))
            {
                file     = _options.CSSFiles[keyInformation.Value];
                filePath = GetCssFilePath(file);
            }
            else if (Path.GetExtension(keyInformation.Value) == ".js" && _options.JSFiles.ContainsKey(keyInformation.Value))
            {
                file     = _options.JSFiles[keyInformation.Value];
                filePath = GetJsFilePath(file);
            }
            else
            {
                file = null;
            }

            if (file != null)
            {
                if (!File.Exists(filePath))
                {
                    throw new FileNotFoundException($"File not found at the given path. {filePath}");
                }

                //read file and replace all keys
                fileString = File.ReadAllText(filePath);
                fileString = _stringReplacer.SafeReplace(fileString, file.KeysToReplace);
                SetFileStringCache(keyInformation, fileString);
            }
            return(fileString);
        }