Пример #1
0
        public BundlingMiddleware(RequestDelegate next, IHostingEnvironment env, ILoggerFactory loggerFactory, IHttpContextAccessor httpContextAccessor,
            IOptions<BundleGlobalOptions> globalOptions, IBundleManagerFactory bundleManagerFactory, BundleCollection bundles, IOptions<BundlingOptions> options)
        {
            if (next == null)
                throw new ArgumentNullException(nameof(next));

            if (env == null)
                throw new ArgumentNullException(nameof(env));

            if (loggerFactory == null)
                throw new ArgumentNullException(nameof(loggerFactory));

            if (httpContextAccessor == null)
                throw new ArgumentNullException(nameof(httpContextAccessor));

            if (globalOptions == null)
                throw new ArgumentNullException(nameof(globalOptions));

            if (bundleManagerFactory == null)
                throw new ArgumentNullException(nameof(bundleManagerFactory));

            if (bundles == null)
                throw new ArgumentNullException(nameof(bundles));

            if (options == null)
                throw new ArgumentNullException(nameof(options));

            _next = next;

            var optionsUnwrapped = options.Value;

            _bundleManager = optionsUnwrapped.BundleManager ?? bundleManagerFactory.Create(bundles, new BundlingContext
            {
                BundlesPathPrefix = optionsUnwrapped.RequestPath,
                StaticFilesPathPrefix = optionsUnwrapped.StaticFilesRequestPath
            });

            optionsUnwrapped.FileProvider = optionsUnwrapped.FileProvider ?? new BundleFileProvider(_bundleManager, httpContextAccessor);

            var globalOptionsUnwrapped = globalOptions.Value;
            if (globalOptionsUnwrapped.EnableCacheHeader)
            {
                var originalPrepareResponse = optionsUnwrapped.OnPrepareResponse;
                optionsUnwrapped.OnPrepareResponse = ctx =>
                {
                    var headers = ctx.Context.Response.GetTypedHeaders();
                    headers.CacheControl = new CacheControlHeaderValue { MaxAge = globalOptionsUnwrapped.CacheHeaderMaxAge };
                    originalPrepareResponse?.Invoke(ctx);
                };
            }

            _staticFileMiddleware = new StaticFileMiddleware(next, env, options, loggerFactory);
        }
Пример #2
0
 public AbpTagHelperStyleService(
     IBundleManager bundleManager,
     IWebContentFileProvider webContentFileProvider,
     IOptions <AbpBundlingOptions> options,
     IWebHostEnvironment hostingEnvironment
     ) : base(
         bundleManager,
         webContentFileProvider,
         options,
         hostingEnvironment)
 {
 }
 public RocketTagHelperScriptService(
     IBundleManager bundleManager,
     IWebContentFileProvider webContentFileProvider,
     IOptions <RocketBundlingOptions> options,
     IWebHostEnvironment hostingEnvironment
     ) : base(
         bundleManager,
         webContentFileProvider,
         options,
         hostingEnvironment)
 {
 }
Пример #4
0
        protected AbpTagHelperResourceService(
            IBundleManager bundleManager,
            IWebContentFileProvider webContentFileProvider,
            IOptions <AbpBundlingOptions> options,
            IWebHostEnvironment hostingEnvironment)
        {
            BundleManager          = bundleManager;
            WebContentFileProvider = webContentFileProvider;
            HostingEnvironment     = hostingEnvironment;
            Options = options.Value;

            Logger = NullLogger <AbpTagHelperResourceService> .Instance;
        }
Пример #5
0
 public AddCompressionFilter(IRequestHelper requestHelper, IBundleManager bundleManager)
 {
     if (requestHelper == null)
     {
         throw new ArgumentNullException(nameof(requestHelper));
     }
     if (bundleManager == null)
     {
         throw new ArgumentNullException(nameof(bundleManager));
     }
     _requestHelper = requestHelper;
     _bundleManager = bundleManager;
 }
    public SmidgeRuntimeMinifier(
        IBundleManager bundles,
        SmidgeHelperAccessor smidge,
        IHostingEnvironment hostingEnvironment,
        IConfigManipulator configManipulator,
        IOptions <RuntimeMinificationSettings> runtimeMinificationSettings,
        CacheBusterResolver cacheBusterResolver)
    {
        _bundles             = bundles;
        _smidge              = smidge;
        _hostingEnvironment  = hostingEnvironment;
        _configManipulator   = configManipulator;
        _cacheBusterResolver = cacheBusterResolver;
        _jsMinPipeline       = new Lazy <PreProcessPipeline>(() => _bundles.PipelineFactory.Create(typeof(JsMinifier)));
        _cssMinPipeline      = new Lazy <PreProcessPipeline>(() => _bundles.PipelineFactory.Create(typeof(NuglifyCss)));

        // replace the default JsMinifier with NuglifyJs and CssMinifier with NuglifyCss in the default pipelines
        // for use with our bundles only (not modifying global options)
        _jsOptimizedPipeline = new Lazy <PreProcessPipeline>(() =>
                                                             bundles.PipelineFactory.DefaultJs().Replace <JsMinifier, SmidgeNuglifyJs>(_bundles.PipelineFactory));
        _jsNonOptimizedPipeline = new Lazy <PreProcessPipeline>(() =>
        {
            PreProcessPipeline defaultJs = bundles.PipelineFactory.DefaultJs();

            // remove minification from this pipeline
            defaultJs.Processors.RemoveAll(x => x is JsMinifier);
            return(defaultJs);
        });
        _cssOptimizedPipeline = new Lazy <PreProcessPipeline>(() =>
                                                              bundles.PipelineFactory.DefaultCss().Replace <CssMinifier, NuglifyCss>(_bundles.PipelineFactory));
        _cssNonOptimizedPipeline = new Lazy <PreProcessPipeline>(() =>
        {
            PreProcessPipeline defaultCss = bundles.PipelineFactory.DefaultCss();

            // remove minification from this pipeline
            defaultCss.Processors.RemoveAll(x => x is CssMinifier);
            return(defaultCss);
        });

        Type cacheBusterType = runtimeMinificationSettings.Value.CacheBuster switch
        {
            RuntimeMinificationCacheBuster.AppDomain => typeof(AppDomainLifetimeCacheBuster),
            RuntimeMinificationCacheBuster.Version => typeof(UmbracoSmidgeConfigCacheBuster),
            RuntimeMinificationCacheBuster.Timestamp => typeof(TimestampCacheBuster),
            _ => throw new NotImplementedException(),
        };

        _cacheBusterType = cacheBusterType;
    }
Пример #7
0
        private static void FileWatchOptions_FileModified(IBundleManager bundleManager, CacheBusterResolver cacheBusterResolver, string bundleName, Bundle bundle, bool debug, FileWatchEventArgs e)
        {
            var cacheBuster = cacheBusterResolver.GetCacheBuster(bundle.GetBundleOptions(bundleManager, debug).GetCacheBusterType());

            //this file is part of this bundle, so the persisted processed/combined/compressed  will need to be
            // invalidated/deleted/renamed
            foreach (var compressionType in new[] { CompressionType.deflate, CompressionType.gzip, CompressionType.none })
            {
                var compFilePath = e.FileSystemHelper.GetCurrentCompositeFilePath(cacheBuster, compressionType, bundleName);
                if (File.Exists(compFilePath))
                {
                    File.Delete(compFilePath);
                }
            }
        }
Пример #8
0
        private static void WireUpFileWatchEventHandlers(IBundleManager bundleManager, CacheBusterResolver cacheBusterResolver, string bundleName, Bundle bundle)
        {
            if (bundle.BundleOptions == null)
            {
                return;
            }

            if (bundle.BundleOptions.DebugOptions.FileWatchOptions.Enabled)
            {
                bundle.BundleOptions.DebugOptions.FileWatchOptions.FileModified += FileWatchOptions_FileModified(bundleManager, cacheBusterResolver, bundleName, bundle, true);
            }
            if (bundle.BundleOptions.ProductionOptions.FileWatchOptions.Enabled)
            {
                bundle.BundleOptions.ProductionOptions.FileWatchOptions.FileModified += FileWatchOptions_FileModified(bundleManager, cacheBusterResolver, bundleName, bundle, false);
            }
        }
Пример #9
0
 public SmidgeRequire(string bundleName, IBundleManager bundleManager, WebFileType type, IRequestHelper requestHelper)
 {
     if (bundleName == null)
     {
         throw new ArgumentNullException(nameof(bundleName));
     }
     if (bundleManager == null)
     {
         throw new ArgumentNullException(nameof(bundleManager));
     }
     if (requestHelper == null)
     {
         throw new ArgumentNullException(nameof(requestHelper));
     }
     _bundleName    = bundleName;
     _bundleManager = bundleManager;
     _type          = type;
     _requestHelper = requestHelper;
 }
Пример #10
0
        public SmidgeHelperTests()
        {
            //  var config = Mock.Of<ISmidgeConfig>();
            _httpContext         = new Mock <HttpContext>();
            _httpContextAccessor = new Mock <IHttpContextAccessor>();
            _httpContextAccessor.Setup(x => x.HttpContext).Returns(_httpContext.Object);

            _dynamicallyRegisteredWebFiles = new DynamicallyRegisteredWebFiles();
            _fileSystemHelper = new FileSystemHelper(_hostingEnvironment, _config, _fileProvider, _hasher);

            _smidgeOptions = new Mock <IOptions <SmidgeOptions> >();
            _smidgeOptions.Setup(opt => opt.Value).Returns(new SmidgeOptions());

            _requestHelper     = Mock.Of <IRequestHelper>();
            _processorFactory  = new PreProcessPipelineFactory(new Lazy <IEnumerable <IPreProcessor> >(() => _preProcessors));
            _bundleManager     = new BundleManager(_smidgeOptions.Object, Mock.Of <ILogger <BundleManager> >());
            _preProcessManager = new PreProcessManager(
                _fileSystemHelper,
                new CacheBusterResolver(Enumerable.Empty <ICacheBuster>()),
                _bundleManager, Mock.Of <ILogger <PreProcessManager> >());
            _fileSetGenerator = new BundleFileSetGenerator(_fileSystemHelper, _requestHelper,
                                                           new FileProcessingConventions(_smidgeOptions.Object, new List <IFileProcessingConvention>()));
        }
Пример #11
0
 private static EventHandler <FileWatchEventArgs> FileWatchOptions_FileModified(IBundleManager bundleManager, CacheBusterResolver cacheBusterResolver, string bundleName, Bundle bundle, bool debug)
 {
     return((sender, args) =>
     {
         FileWatchOptions_FileModified(bundleManager, cacheBusterResolver, bundleName, bundle, debug, args);
     });
 }
Пример #12
0
 public void Init(IBundleManager bundleManager)
 {
     _bundleManager = bundleManager;
 }
Пример #13
0
 public AbstractResources(IPathInfoParser pathInfoParser, IBundleManager manager, bool useWeakCache)
 {
     this.pathInfoParser = pathInfoParser;
     this.bundleManager  = manager;
     this.useWeakCache   = useWeakCache;
 }
Пример #14
0
        public static IApplicationBuilder UseModulesContent(this IApplicationBuilder appBuilder, IBundleManager bundles)
        {
            var hostingEnv = appBuilder.ApplicationServices.GetRequiredService <IHostingEnvironment>();
            var modules    = GetInstalledModules(appBuilder.ApplicationServices);

            var cssBundleItems = modules.SelectMany(m => m.Styles).ToArray();

            var cssFiles = cssBundleItems.OfType <ManifestBundleFile>().Select(x => new CssFile(x.VirtualPath));

            cssFiles = cssFiles.Concat(cssBundleItems.OfType <ManifestBundleDirectory>().SelectMany(x => new WebFileFolder(hostingEnv, x.VirtualPath)
                                                                                                    .AllWebFiles <CssFile>(x.SearchPattern, x.SearchSubdirectories ?  SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)));

            var scriptBundleItems = modules.SelectMany(m => m.Scripts).ToArray();
            var jsFiles           = scriptBundleItems.OfType <ManifestBundleFile>().Select(x => new JavaScriptFile(x.VirtualPath));

            jsFiles = jsFiles.Concat(scriptBundleItems.OfType <ManifestBundleDirectory>().SelectMany(x => new WebFileFolder(hostingEnv, x.VirtualPath)
                                                                                                     .AllWebFiles <JavaScriptFile>(x.SearchPattern, x.SearchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)));


            //TODO: Test minification and uglification for resulting bundles
            var options = bundles.DefaultBundleOptions;

            options.DebugOptions.FileWatchOptions.Enabled = true;

            bundles.Create("vc-modules-styles", cssFiles.ToArray())
            .WithEnvironmentOptions(options);

            bundles.Create("vc-modules-scripts", jsFiles.ToArray())
            .WithEnvironmentOptions(options);


            return(appBuilder);
        }
Пример #15
0
        public CompositeFileModel(IHasher hasher, IUrlManager urlManager, IActionContextAccessor accessor, IRequestHelper requestHelper, IBundleManager bundleManager, CacheBusterResolver cacheBusterResolver)
            : base("file", urlManager, accessor, requestHelper)
        {
            //Creates a single hash of the full url (which can include many files)
            FileKey = hasher.Hash(string.Join(".", ParsedPath.Names));

            CacheBuster = cacheBusterResolver.GetCacheBuster(bundleManager.GetDefaultBundleOptions(false).GetCacheBusterType());
        }
Пример #16
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="fileSetGenerator"></param>
 /// <param name="dynamicallyRegisteredWebFiles"></param>
 /// <param name="preProcessManager"></param>
 /// <param name="fileSystemHelper"></param>
 /// <param name="hasher"></param>
 /// <param name="bundleManager"></param>
 /// <param name="processorFactory"></param>
 /// <param name="urlManager"></param>
 /// <param name="requestHelper"></param>
 /// <param name="httpContextAccessor"></param>
 /// <param name="cacheBusterResolver"></param>
 public SmidgeHelper(
     IBundleFileSetGenerator fileSetGenerator,
     DynamicallyRegisteredWebFiles dynamicallyRegisteredWebFiles,
     PreProcessManager preProcessManager,
     FileSystemHelper fileSystemHelper,
     IHasher hasher,
     IBundleManager bundleManager,
     PreProcessPipelineFactory processorFactory,
     IUrlManager urlManager,
     IRequestHelper requestHelper,
     IHttpContextAccessor httpContextAccessor,
     CacheBusterResolver cacheBusterResolver)
 {
     if (fileSetGenerator == null)
     {
         throw new ArgumentNullException(nameof(fileSetGenerator));
     }
     if (dynamicallyRegisteredWebFiles == null)
     {
         throw new ArgumentNullException(nameof(dynamicallyRegisteredWebFiles));
     }
     if (preProcessManager == null)
     {
         throw new ArgumentNullException(nameof(preProcessManager));
     }
     if (fileSystemHelper == null)
     {
         throw new ArgumentNullException(nameof(fileSystemHelper));
     }
     if (bundleManager == null)
     {
         throw new ArgumentNullException(nameof(bundleManager));
     }
     if (processorFactory == null)
     {
         throw new ArgumentNullException(nameof(processorFactory));
     }
     if (urlManager == null)
     {
         throw new ArgumentNullException(nameof(urlManager));
     }
     if (requestHelper == null)
     {
         throw new ArgumentNullException(nameof(requestHelper));
     }
     if (httpContextAccessor == null)
     {
         throw new ArgumentNullException(nameof(httpContextAccessor));
     }
     if (cacheBusterResolver == null)
     {
         throw new ArgumentNullException(nameof(cacheBusterResolver));
     }
     _fileSetGenerator              = fileSetGenerator;
     _processorFactory              = processorFactory;
     _urlManager                    = urlManager;
     _requestHelper                 = requestHelper;
     _httpContextAccessor           = httpContextAccessor;
     _cacheBusterResolver           = cacheBusterResolver;
     _bundleManager                 = bundleManager;
     _preProcessManager             = preProcessManager;
     _dynamicallyRegisteredWebFiles = dynamicallyRegisteredWebFiles;
     _fileSystemHelper              = fileSystemHelper;
     _fileBatcher                   = new FileBatcher(_fileSystemHelper, _requestHelper, hasher);
 }
Пример #17
0
 /// <summary>
 /// Create a CSS bundle
 /// </summary>
 /// <param name="bundleManager"></param>
 /// <param name="bundleName"></param>
 /// <param name="pipeline"></param>
 /// <param name="paths"></param>
 /// <returns></returns>
 public static Bundle CreateCss(this IBundleManager bundleManager, string bundleName, PreProcessPipeline pipeline, params string[] paths)
 {
     return(bundleManager.Create(bundleName, pipeline, WebFileType.Css, paths));
 }
Пример #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pathInfoParser">The parser for the asset path.</param>
 /// <param name="manager">The manager of Assetbundles.</param>
 /// <param name="useWeakCache">Whether to use weak cache, if it is true, use weak cache, otherwise close weak cache.
 /// Objects loaded from AssetBundles are unmanaged objects,the weak caches do not accurately track the validity of objects.
 /// If there are some problems after the Resource.UnloadUnusedAssets() is called, please turn off the weak cache.
 /// </param>
 public BundleResources(IPathInfoParser pathInfoParser, IBundleManager manager, bool useWeakCache) : base(pathInfoParser, manager, useWeakCache)
 {
 }
Пример #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="pathInfoParser">The parser for the asset path.</param>
 /// <param name="manager">The manager of Assetbundles.</param>
 public BundleResources(IPathInfoParser pathInfoParser, IBundleManager manager) : this(pathInfoParser, manager, true)
 {
 }
Пример #20
0
 public SimulationResources(IPathInfoParser pathInfoParser, IBundleManager manager) : base(pathInfoParser, manager, false)
 {
 }
Пример #21
0
 public AssetResolver(IBundleManager bundleManager)
 {
     BundleManager    = bundleManager;
     VirtualPathUtils = new VirtualPathHelper(bundleManager.VirtualPathProvider);
 }
Пример #22
0
 /// <summary>
 /// Create a JS bundle
 /// </summary>
 /// <param name="bundleManager"></param>
 /// <param name="bundleName"></param>
 /// <param name="paths"></param>
 /// <returns></returns>
 public static Bundle CreateJs(this IBundleManager bundleManager, string bundleName, params string[] paths)
 {
     return(bundleManager.Create(bundleName, WebFileType.Js, paths));
 }
Пример #23
0
 public BrowserCodeBiz(ISourceControl sourceControl,
                       IContentManagementContext contentManagementContext, IFileSystemManager fileSystemManager
                       , IWebConfigManager webConfigManager, ICompressManager compressManager, IBundleManager bundleManager
                       , ISecurityContext securityContext)
     : base(sourceControl, contentManagementContext, fileSystemManager
            , webConfigManager, securityContext)
 {
     _compressManager = compressManager;
     _bundleManager   = bundleManager;
 }
Пример #24
0
 public AbpStyleBundleViewComponent(IBundleManager bundleManager)
 {
     _bundleManager = bundleManager;
 }
        public static IApplicationBuilder UseModulesContent(this IApplicationBuilder appBuilder, IBundleManager bundles)
        {
            var env            = appBuilder.ApplicationServices.GetService <IHostingEnvironment>();
            var modules        = GetInstalledModules(appBuilder.ApplicationServices);
            var modulesOptions = appBuilder.ApplicationServices.GetRequiredService <IOptions <LocalStorageModuleCatalogOptions> >().Value;
            var cssBundleItems = modules.SelectMany(m => m.Styles).ToArray();
            var cssFiles       = cssBundleItems.OfType <ManifestBundleFile>().Select(x => new CssFile(x.VirtualPath));

            cssFiles = cssFiles.Concat(cssBundleItems.OfType <ManifestBundleDirectory>().SelectMany(x => new WebFileFolder(modulesOptions.DiscoveryPath, x.VirtualPath)
                                                                                                    .AllWebFiles <CssFile>(x.SearchPattern, x.SearchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)));

            var scriptBundleItems = modules.SelectMany(m => m.Scripts).ToArray();
            var jsFiles           = scriptBundleItems.OfType <ManifestBundleFile>().Select(x => new JavaScriptFile(x.VirtualPath));

            jsFiles = modules.Aggregate(jsFiles, (current, module) =>
            {
                return(current.Concat(module.Scripts
                                      .OfType <ManifestBundleDirectory>()
                                      .SelectMany(s =>
                                                  env.IsDevelopment() ?
                                                  new WebFileFolder(modulesOptions.DiscoveryPath, s.VirtualPath, module.ModuleName, module.Assembly.GetName().Name)
                                                  .AllWebFilesForDevelopment <JavaScriptFile>(s.SearchPattern,
                                                                                              s.SearchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly) :
                                                  new WebFileFolder(modulesOptions.DiscoveryPath, s.VirtualPath)
                                                  .AllWebFilesWithRequestRoot <JavaScriptFile>(s.SearchPattern,
                                                                                               s.SearchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))));
            });

            var options = bundles.DefaultBundleOptions;

            options.DebugOptions.FileWatchOptions.Enabled = true;
            options.DebugOptions.ProcessAsCompositeFile   = false;
            options.DebugOptions.CompressResult           = false;
            options.DebugOptions.CacheControlOptions      = new CacheControlOptions()
            {
                EnableETag = false, CacheControlMaxAge = 0
            };

            bundles.Create("vc-modules-styles", cssFiles.ToArray())
            .WithEnvironmentOptions(options);

            bundles.Create("vc-modules-scripts", bundles.PipelineFactory.Create <NuglifyJs>(), jsFiles.ToArray())
            .WithEnvironmentOptions(options);


            return(appBuilder);
        }
Пример #26
0
 public SmidgeScriptTagHelper(SmidgeHelper smidgeHelper, IBundleManager bundleManager, HtmlEncoder encoder)
 {
     _smidgeHelper  = smidgeHelper;
     _bundleManager = bundleManager;
     _encoder       = encoder;
 }
Пример #27
0
 public NuglifySourceMapController(FileSystemHelper fileSystemHelper, IBundleManager bundleManager)
 {
     _fileSystemHelper = fileSystemHelper;
     _bundleManager    = bundleManager;
 }
Пример #28
0
 public PreProcessManager(FileSystemHelper fileSystemHelper, CacheBusterResolver cacheBusterResolver, IBundleManager bundleManager)
 {
     _fileSystemHelper    = fileSystemHelper;
     _cacheBusterResolver = cacheBusterResolver;
     _bundleManager       = bundleManager;
 }
Пример #29
0
 public BundleFileProvider(IBundleManager bundleManager, IHttpContextAccessor httpContextAccessor)
 {
     _bundleManager       = bundleManager;
     _httpContextAccessor = httpContextAccessor;
 }
 public AbpScriptBundleViewComponent(IBundleManager bundleManager)
 {
     _bundleManager = bundleManager;
 }
Пример #31
0
        public BundleRequestModel(IUrlManager urlManager, IActionContextAccessor accessor, IRequestHelper requestHelper, IBundleManager bundleManager, CacheBusterResolver cacheBusterResolver)
            : base("bundle", urlManager, accessor, requestHelper)
        {
            //TODO: Pretty sure if we want to control the caching of the file, we'll have to retrieve the bundle definition here
            // In reality we'll need to do that anyways if we want to support load balancing!
            // https://github.com/Shazwazza/Smidge/issues/17


            if (!ParsedPath.Names.Any())
            {
                throw new InvalidOperationException("The bundle route value does not contain a bundle name");
            }

            FileKey = ParsedPath.Names.Single();

            Bundle bundle;

            if (!bundleManager.TryGetValue(FileKey, out bundle))
            {
                throw new InvalidOperationException("No bundle found with key " + FileKey);
            }
            Bundle = bundle;

            CacheBuster = cacheBusterResolver.GetCacheBuster(bundle.GetBundleOptions(bundleManager, Debug).GetCacheBusterType());
        }