Пример #1
0
        public override string ProcessHtml(string htmlToProcess)
        {
            // Do not process anything if all three flags are set to false
            if (!_combineJs && !_combineCss && !_versionOnly)
            {
                return(htmlToProcess);
            }

            // Build the doc tree to be manipulated by the filter chain
            var doc = new HtmlDocument {
                OptionWriteEmptyNodes = true
            };

            doc.LoadHtml(htmlToProcess);

            var filterContext = new CombinerFilterContext
            {
                Document               = doc,
                CombineJs              = _combineJs,
                CombineCss             = _combineCss,
                MinifyJs               = _minifyJs,
                MinifyCss              = _minifyCss,
                VersionOnly            = _versionOnly,
                JsVersion              = _jsVersion,
                CssVersion             = _cssVersion,
                SharedVersion          = _sharedVersion,
                IeVersion              = _ieVersion,
                RequestPath            = _requestedUrl,
                CombinerService        = _combinerService,
                CombinedResourcesUrl   = _combinedResourcesUrl,
                PrependCdnHostToImages = _prependCdnHostToImages,
                CdnHostToPrepend       = _cdnHostToPrepend
            };

            try
            {
                // Build the filter chain and pass the doc tree to the individual filters.
                // Execute one filter at a time.
                // (Interceptor Filter implementation taken from: http://www.eggheadcafe.com/articles/20060609.asp)
                PipelineManager <CombinerFilterContext> pp =
                    PipelineFactory.CreateFromConfiguration <CombinerFilterContext>("JACombinerAndOptimizerGroup/combinerAndVersioningFilters");
                pp.ProcessFilter(ref filterContext);

                return(filterContext.ParsedHtml);
            }
            catch (Exception e)
            {
                _logger.Error("Exception executing the js and css combiner filter chain for page: " + _requestedUrl + ". Exception: " + e.Message);
            }

            // Return the unmodified html if there was any problems executing the parsing filters!
            return(htmlToProcess);
        }