Esempio n. 1
0
 public CombinerResponseStream(
     Stream responseStream,
     bool combineJs,
     bool combineCss,
     bool minifyJs,
     bool minifyCss,
     bool versionOnly,
     bool prependCdnHostToImages,
     string jsVersion,
     string cssVersion,
     string sharedVersion,
     int ieVersion,
     string requestedUrl,
     ICombinerService combinerService,
     ILoggingService loggingService,
     string combinedResourcesUrl,
     string cdnHostToPrepend)
     : base(responseStream)
 {
     _combineJs              = combineJs;
     _combineCss             = combineCss;
     _minifyJs               = minifyJs;
     _minifyCss              = minifyCss;
     _versionOnly            = versionOnly;
     _jsVersion              = jsVersion;
     _cssVersion             = cssVersion;
     _sharedVersion          = sharedVersion;
     _ieVersion              = ieVersion;
     _requestedUrl           = requestedUrl;
     _combinerService        = combinerService;
     _logger                 = loggingService;
     _combinedResourcesUrl   = combinedResourcesUrl;
     _prependCdnHostToImages = prependCdnHostToImages;
     _cdnHostToPrepend       = cdnHostToPrepend;
 }
        public void ProcessRequest(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            bool isIe = HttpContext.Current.Request.Browser.Browser.Trim()
                        .Equals("IE", StringComparison.InvariantCultureIgnoreCase);
            int ieVersion = isIe ? HttpContext.Current.Request.Browser.MajorVersion : 0;

            ICombinerService myCombiner = CombinerServiceFactory.CreateCombinerService();

            string imagesHostToPrepend = CombinerConstantsAndSettings.WebSettings.ImagesCdnHostToPrepend;

            byte[] combinedContent = null;

            try
            {
                // *** get the combined content to write to the response
                combinedContent = myCombiner.ServeCombinedContent(ieVersion, context.Request.QueryString,
                                                                  HttpContext.Current.Server.MapPath,
                                                                  File.ReadAllText, imagesHostToPrepend);
                // *******
            }
            catch
            {
                combinedContent = Encoding.UTF8.GetBytes("/* no content */");
            }

            // *** write combined content into the response stream
            WriteBytes(context, combinedContent);
            // *******
        }
 public CombinerResponseStream(
     Stream responseStream,
     bool combineJs,
     bool combineCss,
     bool minifyJs,
     bool minifyCss,
     bool versionOnly,
     bool prependCdnHostToImages,
     string jsVersion,
     string cssVersion,
     string sharedVersion,
     int ieVersion,
     string requestedUrl,
     ICombinerService combinerService,
     ILoggingService loggingService,
     string combinedResourcesUrl,
     string cdnHostToPrepend)
     : base(responseStream)
 {
     _combineJs = combineJs;
     _combineCss = combineCss;
     _minifyJs = minifyJs;
     _minifyCss = minifyCss;
     _versionOnly = versionOnly;
     _jsVersion = jsVersion;
     _cssVersion = cssVersion;
     _sharedVersion = sharedVersion;
     _ieVersion = ieVersion;
     _requestedUrl = requestedUrl;
     _combinerService = combinerService;
     _logger = loggingService;
     _combinedResourcesUrl = combinedResourcesUrl;
     _prependCdnHostToImages = prependCdnHostToImages;
     _cdnHostToPrepend = cdnHostToPrepend;
 }
        public override void OnResultExecuting(ResultExecutingContext filterContext)
        {
            bool isIe = HttpContext.Current.Request.Browser.Browser.Trim()
                        .Equals("IE", StringComparison.InvariantCultureIgnoreCase);
            int ieVersion = isIe ? HttpContext.Current.Request.Browser.MajorVersion : 0;

            ICombinerService myCombiner = CombinerServiceFactory.CreateCombinerService();

            var logger = new LoggingService.LoggingService();

            // Set the Response.Filter to our custom Stream class that will do the parsing of the html
            // and the replacement of the script and css tags with the combined resources tags.
            filterContext.HttpContext.Response.Filter =
                new CombinerResponseStream(
                    filterContext.HttpContext.Response.Filter,
                    CombinerLiveSettings.CombineJs && _combineJs,
                    CombinerLiveSettings.CombineCss && _combineCss,
                    CombinerLiveSettings.MinifyJs && _minifyJs,
                    CombinerLiveSettings.MinifyCss && _minifyCss,
                    CombinerLiveSettings.VersionOnly && _versionOnly,
                    CombinerLiveSettings.PrependCdnHostToImages && _prependCdnHostToImages,
                    CombinerLiveSettings.JsVersion,
                    CombinerLiveSettings.CssVersion,
                    CombinerConstantsAndSettings.JsAndCssSharedVersion,
                    ieVersion,
                    HttpContext.Current.Request.Url.AbsolutePath.TrimEnd('/'),
                    myCombiner,
                    logger,
                    CombinerConstantsAndSettings.WebSettings.ComboScriptUrl,
                    CombinerConstantsAndSettings.WebSettings.ImagesCdnHostToPrepend
                    );

            if (_applyOutputCaching)
            {
                // Set cacheability
                filterContext.HttpContext.Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
                filterContext.HttpContext.Response.Cache.SetCacheability(HttpCacheability.Public);
                filterContext.HttpContext.Response.Cache.SetValidUntilExpires(true);
                filterContext.HttpContext.Response.Cache.VaryByParams["*"] = true;

                // Set file dependency for output cache
                // when the live.js is updated we need to invalidate the OutputCache for this page
                string path = CombinerConstantsAndSettings.WebSettings.CombinerLiveSettingsFile;
                string liveSettingsFilePath = filterContext.HttpContext.Server.MapPath(path);

                filterContext.HttpContext.Response.AddFileDependency(liveSettingsFilePath);
            }

            base.OnResultExecuting(filterContext);
        }
Esempio n. 5
0
        protected override void OnPreRender(EventArgs e)
        {
            bool isIe = HttpContext.Current.Request.Browser.Browser.Trim()
                        .Equals("IE", StringComparison.InvariantCultureIgnoreCase);
            int ieVersion = isIe ? HttpContext.Current.Request.Browser.MajorVersion : 0;

            ICombinerService myCombiner = CombinerServiceFactory.CreateCombinerService();

            var logger = new LoggingService.LoggingService();

            HttpContext.Current.Response.Filter =
                new CombinerResponseStream(
                    HttpContext.Current.Response.Filter,
                    CombinerLiveSettings.CombineJs && CombineJs.GetValueOrDefault(true),
                    CombinerLiveSettings.CombineCss && CombineCss.GetValueOrDefault(true),
                    CombinerLiveSettings.MinifyJs && MinifyJs.GetValueOrDefault(true),
                    CombinerLiveSettings.MinifyCss && MinifyCss.GetValueOrDefault(true),
                    CombinerLiveSettings.VersionOnly && VersionOnly.GetValueOrDefault(true),
                    CombinerLiveSettings.PrependCdnHostToImages && PrependCdnHostToImages.GetValueOrDefault(true),
                    CombinerLiveSettings.JsVersion,
                    CombinerLiveSettings.CssVersion,
                    CombinerConstantsAndSettings.JsAndCssSharedVersion,
                    ieVersion,
                    HttpContext.Current.Request.Url.AbsolutePath,
                    myCombiner,
                    logger,
                    CombinerConstantsAndSettings.WebSettings.ComboScriptUrl,
                    CombinerConstantsAndSettings.WebSettings.ImagesCdnHostToPrepend
                    );

            if (ApplyOutputCaching.GetValueOrDefault(true))
            {
                // Set cacheability
                HttpContext.Current.Response.Cache.SetExpires(DateTime.Now.AddMonths(1));
                HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
                HttpContext.Current.Response.Cache.SetValidUntilExpires(true);
                HttpContext.Current.Response.Cache.VaryByParams["*"] = true;

                // Set file dependency for output cache
                // when the live.js is updated we need to invalidate the OutputCache for this page
                string path = CombinerConstantsAndSettings.WebSettings.CombinerLiveSettingsFile;
                string liveSettingsFilePath = HttpContext.Current.Server.MapPath(path);

                HttpContext.Current.Response.AddFileDependency(liveSettingsFilePath);
            }
        }