/// <summary> /// Determines if the virtual path corresponds to a bundle. /// </summary> /// <param name="virtualPath">The virtual path requested.</param> /// <returns>A boolean value indicating whether the virtual path corresponds to a bundle.</returns> public bool IsBundleVirtualPath(string virtualPath) { if (ExceptionUtil.ValidateVirtualPath(virtualPath, "virtualPath") != null) { return(false); } return(Bundles.GetBundleFor(virtualPath) != null); }
/// <summary> /// Given a list of asset paths, expands bundles into individual assets if optimizations are off /// Returns a deduplicated list of paths to render /// </summary> /// <param name="assets"></param> /// <returns></returns> private IEnumerable <AssetTag> DeterminePathsToRender(IEnumerable <string> assets) { List <AssetTag> paths = new List <AssetTag>(); foreach (string path in assets) { if (Resolver.IsBundleVirtualPath(path)) { if (!OptimizationEnabled) { // Get the contents of the bundle IEnumerable <string> contents = Resolver.GetBundleContents(path); foreach (string filePath in contents) { paths.Add(new AssetTag(filePath)); } } else { // Just render the unresolved bundle url(we render the versioned url later) paths.Add(new AssetTag(path)); // Look for Cdn fallback if requested if (Bundles.UseCdn) { Bundle bundle = Bundles.GetBundleFor(path); if (bundle != null && !String.IsNullOrEmpty(bundle.CdnPath) && !String.IsNullOrEmpty(bundle.CdnFallbackExpression)) { // Note: we know this is a bundle virtual path AssetTag script = new AssetTag(String.Format(CultureInfo.InvariantCulture, OptimizationResources.CdnFallBackScriptString, bundle.CdnFallbackExpression, ResolveVirtualPath(path))); script.IsStaticAsset = true; paths.Add(script); } } } } else { paths.Add(new AssetTag(path)); } } return(EliminateDuplicatesAndResolveUrls(paths)); }
/// <summary> /// Gets a set of file paths that correspond to the contents of a bundle. /// </summary> /// <param name="virtualPath">The virtual path requested.</param> /// <returns>An enumeration of application-relative virtual paths to the contents of a bundle.</returns> public IEnumerable <string> GetBundleContents(string virtualPath) { if (ExceptionUtil.ValidateVirtualPath(virtualPath, "virtualPath") != null) { return(null); } Bundle bundle = Bundles.GetBundleFor(virtualPath); if (bundle == null) { return(null); } List <string> bundleContents = new List <string>(); BundleContext context = new BundleContext(Context, Bundles, virtualPath); BundleResponse response = bundle.GetBundleResponse(context); foreach (BundleFile file in response.Files) { bundleContents.Add(file.IncludedVirtualPath); } return(bundleContents); }