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); }
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) { }
protected AbpTagHelperResourceService( IBundleManager bundleManager, IWebContentFileProvider webContentFileProvider, IOptions <AbpBundlingOptions> options, IWebHostEnvironment hostingEnvironment) { BundleManager = bundleManager; WebContentFileProvider = webContentFileProvider; HostingEnvironment = hostingEnvironment; Options = options.Value; Logger = NullLogger <AbpTagHelperResourceService> .Instance; }
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; }
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); } } }
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); } }
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; }
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>())); }
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); }); }
public void Init(IBundleManager bundleManager) { _bundleManager = bundleManager; }
public AbstractResources(IPathInfoParser pathInfoParser, IBundleManager manager, bool useWeakCache) { this.pathInfoParser = pathInfoParser; this.bundleManager = manager; this.useWeakCache = useWeakCache; }
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); }
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()); }
/// <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); }
/// <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)); }
/// <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) { }
/// <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) { }
public SimulationResources(IPathInfoParser pathInfoParser, IBundleManager manager) : base(pathInfoParser, manager, false) { }
public AssetResolver(IBundleManager bundleManager) { BundleManager = bundleManager; VirtualPathUtils = new VirtualPathHelper(bundleManager.VirtualPathProvider); }
/// <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)); }
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; }
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); }
public SmidgeScriptTagHelper(SmidgeHelper smidgeHelper, IBundleManager bundleManager, HtmlEncoder encoder) { _smidgeHelper = smidgeHelper; _bundleManager = bundleManager; _encoder = encoder; }
public NuglifySourceMapController(FileSystemHelper fileSystemHelper, IBundleManager bundleManager) { _fileSystemHelper = fileSystemHelper; _bundleManager = bundleManager; }
public PreProcessManager(FileSystemHelper fileSystemHelper, CacheBusterResolver cacheBusterResolver, IBundleManager bundleManager) { _fileSystemHelper = fileSystemHelper; _cacheBusterResolver = cacheBusterResolver; _bundleManager = bundleManager; }
public BundleFileProvider(IBundleManager bundleManager, IHttpContextAccessor httpContextAccessor) { _bundleManager = bundleManager; _httpContextAccessor = httpContextAccessor; }
public AbpScriptBundleViewComponent(IBundleManager bundleManager) { _bundleManager = bundleManager; }
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()); }