Пример #1
0
        public override BundleResponse GenerateBundleResponse(BundleContext context)
        {
            var response = _bundle.GenerateBundleResponse(context);

            response.Content = _localizer.LocalizeText(response.Content, _culture);
            return(response);
        }
Пример #2
0
 private static BundleResponse GetBundleResponse(Bundle bundle, BundleContext context)
 {
     BundleResponse response = bundle.CacheLookup(context);
     if (response == null || context.EnableInstrumentation)
     {
         response = bundle.GenerateBundleResponse(context);
         bundle.UpdateCache(context, response);
     }
     return response;
 }
Пример #3
0
        public void BundlePublicArgumentNullChecks()
        {
            Bundle bundle = new Bundle("~/whatever");

            ExceptionHelper.ExpectArgumentNullException(() => bundle.EnumerateFiles(null), "context");
            ExceptionHelper.ExpectArgumentNullException(() => bundle.CacheLookup(null), "context");
            ExceptionHelper.ExpectArgumentNullException(() => bundle.UpdateCache(null, null), "context");
            ExceptionHelper.ExpectArgumentNullException(() => bundle.UpdateCache(new BundleContext(), null), "response");
            ExceptionHelper.ExpectArgumentNullException(() => bundle.GenerateBundleResponse(null), "context");
            ExceptionHelper.ExpectArgumentNullException(() => bundle.GetCacheKey(null), "context");
            ExceptionHelper.ExpectArgumentNullException(() => bundle.ApplyTransforms(null, "", null), "context");
        }
Пример #4
0
        private static BundleResponse GetBundleResponse(Bundle bundle, BundleContext context)
        {
            BundleResponse response = bundle.CacheLookup(context);

            if (response == null || context.EnableInstrumentation)
            {
                response = bundle.GenerateBundleResponse(context);
                bundle.UpdateCache(context, response);
            }

            return(response);
        }
Пример #5
0
        public void OtherTransformsCanRunAfterLessTransformInBundlingPipeline()
        {
            string inputFilename = "~/content/multiple-transform.less";
            var pathProvider = new InMemoryVirtualPathProvider(inputFilename, ".button { background: blue; }");
            SetUpPathProvider(pathProvider);

            var bundle = new Bundle("~/output/multiple-transform.css", new LessTranform(), new CssMinify())
                .Include(inputFilename);
            var bundleResponse = bundle.GenerateBundleResponse(CreateBundleContext(bundle));

            Assert.That(bundleResponse.Content, Is.EqualTo(".button{background:blue}"));
        }
Пример #6
0
        /// <summary>
        /// Gets the bundle file contents.
        /// </summary>
        /// <param name="virtualPath">The virtual path.</param>
        /// <returns></returns>
        public IEnumerable <BundleFile> GetBundleFileContents(string virtualPath)
        {
            if (ExceptionUtil.ValidateVirtualPath(virtualPath, "virtualPath") != null)
            {
                return((IEnumerable <BundleFile>)null);
            }
            Bundle bundleFor = this.Bundles.GetBundleFor(virtualPath);

            if (bundleFor == null)
            {
                return((IEnumerable <BundleFile>)null);
            }
            List <string>  list           = new List <string>();
            BundleContext  context        = new BundleContext(this.Context, this.Bundles, virtualPath);
            BundleResponse bundleResponse = bundleFor.GenerateBundleResponse(context);

            return(bundleResponse.Files);
        }
Пример #7
0
        /// <summary>
        /// https://stackoverflow.com/questions/35543576/mvc-5-bundling-and-azure-cdn-query-string?rq=1
        ///
        /// Produces hash by calling the System.Web.Optimization Hash() method by reflection
        /// </summary>
        /// <param name="bundles"></param>
        /// <param name="bundlePath"></param>
        /// <returns></returns>
        private static string GetBundleHash(BundleCollection bundles, string bundlePath)
        {
            //Need the context to generate response
            var bundleContext = new BundleContext(new HttpContextWrapper(HttpContext.Current), BundleTable.Bundles, bundlePath);

            //Bundle class has the method we need to get a BundleResponse
            Bundle bundle         = BundleTable.Bundles.GetBundleFor(bundlePath);
            var    bundleResponse = bundle.GenerateBundleResponse(bundleContext);

            //BundleResponse has the method we need to call, but its marked as
            //internal and therefor is not available for public consumption.
            //To bypass this, reflect on it and manually invoke the method
            var bundleReflection = bundleResponse.GetType();

            var method = bundleReflection.GetMethod("GetContentHashCode", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            //contentHash is whats appended to your url (url?###-###...)
            var contentHash = method.Invoke(bundleResponse, null);

            return(contentHash.ToString());
        }