Esempio n. 1
0
        /// <summary>
        /// Builds a <see cref="BundleResponse"/> object from the declarations found in a bundle manifest file.
        /// </summary>
        /// <param name="bundlePath">The path to the bundle being requested</param>
        /// <param name="settings">An <see cref="OptimizationSettings"/> object containing configuation settings for optimization.</param>
        /// <returns>The bundle response for specified <paramref name="bundlePath"/>.</returns>
        /// <remarks>
        /// The associated <see cref="BundleCollection"/> object is populated from <see cref="OptimizationSettings.BundleManifestPath"/>
        /// and <see cref="OptimizationSettings.BundleSetupMethod"/> properties of the <paramref name="settings"/> parameter.
        /// <see cref="OptimizationSettings.ApplicationPath"/>, also a property of <paramref name="settings"/>, must reference the physical
        /// application file in order to resolve '~' in the virtual paths
        /// </remarks>
        public static BundleResponse BuildBundle(string bundlePath, OptimizationSettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (String.IsNullOrEmpty(settings.ApplicationPath))
            {
                throw ExceptionUtil.ParameterNullOrEmpty("settings.ApplicationPath");
            }
            if (String.IsNullOrEmpty(bundlePath))
            {
                throw ExceptionUtil.ParameterNullOrEmpty("bundlePath");
            }

            BundleCollection        bundleTable = InitializeBundleCollection(settings);
            FileVirtualPathProvider vpp         = new FileVirtualPathProvider(settings.ApplicationPath);
            BundleContext           context     = new BundleContext();

            context.VirtualPathProvider = vpp;
            context.BundleCollection    = bundleTable;
            context.BundleVirtualPath   = bundlePath;

            Bundle bundle = bundleTable.GetBundleFor(bundlePath);

            if (bundle != null)
            {
                return(bundle.GetBundleResponse(context));
            }

            return(null);
        }
        /// <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);
        }