public Bundle GetBundleFor(string bundleVirtualPath) { Exception error = ExceptionUtil.ValidateVirtualPath(bundleVirtualPath, "bundleVirtualPath"); if (error != null) { throw error; } // Search for exact path match first if (StaticBundles.ContainsKey(bundleVirtualPath)) { return(StaticBundles[bundleVirtualPath]); } if (DynamicBundles.Count > 0) { // Otherwise look at virtualPath component for a bundle extension match bundleVirtualPath = bundleVirtualPath.Replace("\\", "/"); int index = bundleVirtualPath.LastIndexOf("/", StringComparison.Ordinal); // Note: virtualPath always starts with ~/ so should be never -1; string last = bundleVirtualPath.Substring(index + 1); if (DynamicBundles.ContainsKey(last)) { return(DynamicBundles[last]); } } return(null); }
/// <summary> /// Adds a bundle to the collection /// </summary> /// <param name="bundle">The bundle to add to the collection</param> public void Add(Bundle bundle) { if (bundle == null) { throw new ArgumentNullException("bundle"); } string bundlePath = bundle.Path; Bundle oldBundle = null; // REVIEW: Should we lock down when bundles can be registered? DynamicFolderBundle db = bundle as DynamicFolderBundle; if (db != null) { // Remember the old bundle so we can invalidate the cache // NOTE: DynamicBundle paths are not virtual paths so we cannot use GetBundleFor if (DynamicBundles.ContainsKey(bundlePath)) { oldBundle = DynamicBundles[bundlePath]; } DynamicBundles[bundlePath] = db; } else { // We need to resolve the url since the old bundle could have been a dynamic bundle oldBundle = GetBundleFor(bundlePath); StaticBundles[bundlePath] = bundle; } // Invalidate any old cache entries if there was a bundle already registered if (oldBundle != null) { oldBundle.InvalidateCacheEntries(); } _bundles[bundlePath] = bundle; }