protected string RenderDebug(string name = null) { string content = null; if (!bundleCache.TryGetValue(name, out content)) { DependentFiles.Clear(); var modifiedGroupBundles = BeforeRenderDebug(); var sb = new StringBuilder(); foreach (var groupBundleKVP in modifiedGroupBundles) { var groupBundle = groupBundleKVP.Value; var attributes = GetAdditionalAttributes(groupBundle); var assets = groupBundle.Assets; DependentFiles.AddRange(GetFiles(assets)); foreach (var asset in assets) { string processedFile = ExpandAppRelativePath(asset.LocalPath); sb.Append(FillTemplate(groupBundle, processedFile)); } } content = sb.ToString(); bundleCache.Add(name, content, DependentFiles); } return(content); }
private string RenderRelease(string key, string renderTo, IRenderer renderer) { string content; if (!bundleCache.TryGetValue(key, out content)) { renderMutex.WaitOne(); try { if (!bundleCache.TryGetValue(key, out content)) { var files = new List <string>(); foreach (var groupBundleKVP in GroupBundles) { var group = groupBundleKVP.Key; var groupBundle = groupBundleKVP.Value; string minifiedContent = null; string hash = null; bool hashInFileName = false; DependentFiles.Clear(); if (renderTo == null) { renderTo = renderPathCache[CachePrefix + "." + group + "." + key]; } else { renderPathCache[CachePrefix + "." + group + "." + key] = renderTo; } string outputFile = FileSystem.ResolveAppRelativePathToFileSystem(renderTo); var renderToPath = ExpandAppRelativePath(renderTo); if (!String.IsNullOrEmpty(BaseOutputHref)) { renderToPath = String.Concat(BaseOutputHref.TrimEnd('/'), "/", renderToPath.TrimStart('/')); } var remoteAssetPaths = new List <string>(); foreach (var asset in groupBundle.Assets) { if (asset.IsRemote) { remoteAssetPaths.Add(asset.RemotePath); } } files.AddRange(GetFiles(groupBundle.Assets.Where(asset => asset.IsEmbeddedResource || asset.IsLocal || asset.IsRemoteDownload).ToList())); DependentFiles.AddRange(files); if (renderTo.Contains("#")) { hashInFileName = true; minifiedContent = Minifier.Minify(BeforeMinify(outputFile, files, arbitrary)); hash = hasher.GetHash(minifiedContent); renderToPath = renderToPath.Replace("#", hash); outputFile = outputFile.Replace("#", hash); } if (ShouldRenderOnlyIfOutputFileIsMissing && FileExists(outputFile)) { minifiedContent = ReadFile(outputFile); } else { minifiedContent = minifiedContent ?? Minifier.Minify(BeforeMinify(outputFile, files, arbitrary)); renderer.Render(minifiedContent, outputFile); } if (hash == null && !string.IsNullOrEmpty(HashKeyName)) { hash = hasher.GetHash(minifiedContent); } string renderedTag; if (hashInFileName) { renderedTag = FillTemplate(groupBundle, renderToPath); } else { if (string.IsNullOrEmpty(HashKeyName)) { renderedTag = FillTemplate(groupBundle, renderToPath); } else if (renderToPath.Contains("?")) { renderedTag = FillTemplate(groupBundle, renderToPath + "&" + HashKeyName + "=" + hash); } else { renderedTag = FillTemplate(groupBundle, renderToPath + "?" + HashKeyName + "=" + hash); } } content += String.Concat(GetFilesForRemote(remoteAssetPaths, groupBundle), renderedTag); } } } finally { renderMutex.ReleaseMutex(); } bundleCache.Add(key, content, DependentFiles); } return(content); }