public void BuildBundleData(ContentFragmentPageControl contentFragmentPage, CQ parsedContent) { if (Configuration.OptomizeGlobalCss) { //Get the themes CSS files CQ elements = parsedContent.Select(BuildSelector); foreach (IDomObject element in elements) { string mediaType = element.GetAttribute("media") ?? "screen"; if (mediaType.IndexOf("screen", StringComparison.OrdinalIgnoreCase) > -1) { string src = element.GetAttribute("href"); if (!string.IsNullOrEmpty(src) && mediaType.IndexOf("dynamic-style.aspx", StringComparison.OrdinalIgnoreCase) < 0 && src.EndsWith(".css")) { IBundledFile file = _bundledFileFactory.GetBundleFile("css", src, contentFragmentPage, ""); if (file != null) { HandleLayoutCssPath(file); Include(file); } } } } } }
public IBundledFile GetBundleFile(string type, string url, ContentFragmentPageControl contentFragmentPage, string additionalId) { try { IBundledFile result; if (CentralizedFileStorage.IsCentralizedFileUrl(url)) { result = new BundleCfsFile(type, url, contentFragmentPage, additionalId); } else { string localPath = url; int queryStart = localPath.IndexOf('?'); if (queryStart != -1) { localPath = localPath.Substring(0, queryStart); } if (localPath.StartsWith("http://") || localPath.StartsWith("https://")) { localPath = localPath.Replace(PublicApi.Url.Absolute("~"), "~"); } localPath = HttpContext.Current.Server.MapPath(localPath); if (File.Exists(localPath)) { result = new BundleLocalFile(type, url); } else { result = new BundleRemoteFile(type, url, contentFragmentPage, additionalId); } } if (result.IsValid) { return(result); } } catch (Exception ex) { new CSException(CSExceptionType.UnknownHttpError, string.Format("Unable to bundle file type:{0} url:{1} page:{2}", type, url, contentFragmentPage.ContentFragmentContainer.ContainerName), ex).Log(); } return(null); }
public IBundledFile GetBundleFile(string type, string url, ContentFragmentPageControl contentFragmentPage , string additionalId) { try { IBundledFile result; if (CentralizedFileStorage.IsCentralizedFileUrl(url)) { result = new BundleCfsFile(type, url, contentFragmentPage, additionalId); } else { string localPath = url; int queryStart = localPath.IndexOf('?'); if (queryStart != -1) { localPath = localPath.Substring(0, queryStart); } if (localPath.StartsWith("http://") || localPath.StartsWith("https://")) { localPath = localPath.Replace(PublicApi.Url.Absolute("~"), "~"); } localPath = HttpContext.Current.Server.MapPath(localPath); if (File.Exists(localPath)) { result = new BundleLocalFile(type, url); } else { result = new BundleRemoteFile(type, url, contentFragmentPage, additionalId); } } if (result.IsValid) return result; } catch(Exception ex) { new CSException(CSExceptionType.UnknownHttpError, string.Format("Unable to bundle file type:{0} url:{1} page:{2}", type, url, contentFragmentPage.ContentFragmentContainer.ContainerName), ex).Log(); } return null; }
public void Process(CQ parsedContent) { ContentFragmentPageControl contentFragmentPage = ContentFragmentPageControl.GetCurrentContentFragmentPage(); if (contentFragmentPage != null) { PageContext currentContext = PublicApi.Url.CurrentContext; if (currentContext != null && !string.IsNullOrWhiteSpace(currentContext.UrlName)) { string key = CreateKey(contentFragmentPage.ThemeTypeId, contentFragmentPage.ThemeName, currentContext.UrlName); EnsureBundleIntegrity(key); //Find the right bundle if (BundleDictionary.ContainsKey(key)) { PageBundle bundle = BundleDictionary[key]; if (!bundle.BundleRegistered) { if (_initialization.WaitOne(1)) { try { bundle.BuildBundleData(contentFragmentPage, parsedContent); } finally { _initialization.Release(); } } else { return; } } bundle.ProcessDisplayElement(parsedContent); } } } }
public BundleRemoteFile(string type, string uri, ContentFragmentPageControl contentFragmentPage, string additionalId) { IsValid = false; try { WebRequest request = WebRequest.Create(Globals.FullPath(uri)); string localFsPath = LocalPerformanceCachePath(); LocalPath = Path.Combine(localFsPath, string.Format("{0}-{1}-{2}-{3}", contentFragmentPage.ThemeName, contentFragmentPage.ThemeContextId, additionalId, "axd.js")); using (WebResponse wr = request.GetResponse()) { if (string.Compare(wr.ContentType, "text/javascript", true) == 0) { using (Stream s = wr.GetResponseStream()) { using (StreamReader sr = new StreamReader(s)) { using (FileStream localFile = File.Open(LocalPath, FileMode.Create, FileAccess.Write)) { using (StreamWriter sw = new StreamWriter(localFile)) { sw.Write(sr.ReadToEnd()); Type = type; OrignalUri = uri; RelativeUri = ResolveVirtual(LocalPath); IsValid = true; } } } } } } } catch (Exception ex) { new CSException(CSExceptionType.UnknownError, "Failed to build remote file lookup", ex).Log(); } }
private void HandleInlineScripts(CQ parsedContent, ContentFragmentPageControl contentFragmentPage) { if (Configuration.OptomizeGlobalJs) { //Get the themes CSS files CQ elements = parsedContent.Select(BuildSelector); foreach (IDomObject element in elements) { string src = element.GetAttribute("src"); if (!string.IsNullOrEmpty(src)) { IBundledFile file = _bundledFileFactory.GetBundleFile("js", src, contentFragmentPage, ""); if (file != null) { Include(file); } } } //Get the themes axd files elements = parsedContent.Select(BuildAxdSelector); int i = 0; foreach (IDomObject element in elements) { string src = element.GetAttribute("src"); if (!string.IsNullOrEmpty(src)) { IBundledFile file = _bundledFileFactory.GetBundleFile("js", src, contentFragmentPage, i.ToString()); if (file != null) { Include(file); } i++; } } } }
public BundleCfsFile(string type, string uri, ContentFragmentPageControl contentFragmentPage, string additionalId) { try { ICentralizedFile file = CentralizedFileStorage.GetCentralizedFileByUrl(uri.Replace("cfs-filesystemfile.ashx", "cfs-file.ashx")); if (file != null) { LocalPath = EnsureLocalCopyExists(file, string.Format("{0}-{1}-{2}-{3}", contentFragmentPage.ThemeName, contentFragmentPage.ThemeContextId, additionalId, file.FileName)); Type = type; OrignalUri = uri; RelativeUri = ResolveVirtual(LocalPath); IsValid = true; } } catch (Exception ex) { new CSException(CSExceptionType.UnknownError, "Failed to build remote file lookup", ex).Log(); } }
public void BuildBundleData(ContentFragmentPageControl contentFragmentPage, CQ parsedContent) { HandleInlineScripts(parsedContent, contentFragmentPage); }
public void BuildBundleData(ContentFragmentPageControl contentFragmentPage, CQ parsedContent) { _dynamicBundles.ForEach(b => b.BuildBundleData(contentFragmentPage, parsedContent)); RegisterBundles(); }
public void BuildBundleData(ContentFragmentPageControl contentFragmentPage, CQ parsedContent) { HandleInlineScripts(parsedContent , contentFragmentPage); }
private void HandleInlineScripts(CQ parsedContent, ContentFragmentPageControl contentFragmentPage) { if (Configuration.OptomizeGlobalJs) { //Get the themes CSS files CQ elements = parsedContent.Select(BuildSelector); foreach (IDomObject element in elements) { string src = element.GetAttribute("src"); if (!string.IsNullOrEmpty(src)) { IBundledFile file = _bundledFileFactory.GetBundleFile("js", src, contentFragmentPage, ""); if (file != null) Include(file); } } //Get the themes axd files elements = parsedContent.Select(BuildAxdSelector); int i = 0; foreach (IDomObject element in elements) { string src = element.GetAttribute("src"); if (!string.IsNullOrEmpty(src)) { IBundledFile file = _bundledFileFactory.GetBundleFile("js", src, contentFragmentPage, i.ToString()); if (file != null) Include(file); i++; } } } }