예제 #1
0
 private static void EnsureBundleSetup()
 {
     // This should not cause any issues if there's a race condition here, because duplicate adds will just be effective no-ops
     if (!_readBundleManifest)
     {
         _readBundleManifest = true;
         var bundleManifest = BundleManifest.ReadBundleManifest();
         if (bundleManifest != null)
         {
             bundleManifest.Register(BundleTable.Bundles);
         }
     }
 }
예제 #2
0
        /// <summary>
        /// Creates a bundle manifest object from a bundle manifest.
        /// </summary>
        /// <param name="bundleStream">The <see cref="Stream"/> object reading the manifest file.</param>
        /// <returns>The <see cref="BundleManifest"/> object representing the manifest file.</returns>
        public static BundleManifest ReadBundleManifest(Stream bundleStream)
        {
            var document = GetXmlDocument(bundleStream);
            var manifest = new BundleManifest();

            manifest.StyleBundles = document.SelectNodes(@"bundles/styleBundle")
                                    .Cast <XmlElement>()
                                    .Select(ReadBundle)
                                    .ToList();
            manifest.ScriptBundles = document.SelectNodes(@"bundles/scriptBundle")
                                     .Cast <XmlElement>()
                                     .Select(ReadBundle)
                                     .ToList();
            return(manifest);
        }
예제 #3
0
        internal static BundleManifest ReadBundleManifest(VirtualPathProvider vpp)
        {
            if (vpp == null)
            {
                return(null);
            }

            if (!vpp.FileExists(BundleManifestPath))
            {
                // If the bundle path is not user-specified and no file exists at the root, don't attempt to set up bundles.
                return(null);
            }

            VirtualFile file = vpp.GetFile(BundleManifestPath);

            using (var stream = file.Open()) {
                return(BundleManifest.ReadBundleManifest(stream));
            }
        }
예제 #4
0
        private static BundleCollection InitializeBundleCollection(OptimizationSettings settings)
        {
            BundleCollection bundleTable = settings.BundleTable ?? new BundleCollection();

            // Setup the bundle table first with manifest
            if (!String.IsNullOrEmpty(settings.BundleManifestPath))
            {
                using (var stream = File.OpenRead(settings.BundleManifestPath)) {
                    BundleManifest manifest = BundleManifest.ReadBundleManifest(stream);
                    manifest.Register(bundleTable);
                }
            }
            // Invoke the setup method second so code wins (i.e. BundleConfig.RegisterBundles)
            if (settings.BundleSetupMethod != null)
            {
                settings.BundleSetupMethod(bundleTable);
            }

            return(bundleTable);
        }