Exemplo n.º 1
0
 public PreProcessManager(FileSystemHelper fileSystemHelper, CacheBusterResolver cacheBusterResolver, IBundleManager bundleManager, ILogger <PreProcessManager> logger)
 {
     _fileSystemHelper    = fileSystemHelper;
     _cacheBusterResolver = cacheBusterResolver;
     _bundleManager       = bundleManager;
     _logger = logger;
 }
    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;
    }
Exemplo n.º 3
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());
        }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
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);
                }
            }
        }
Exemplo n.º 6
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);
     });
 }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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());
        }
 public CacheFilter(FileSystemHelper fileSystemHelper, CacheBusterResolver cacheBusterResolver, IBundleManager bundleManager)
 {
     _fileSystemHelper    = fileSystemHelper;
     _cacheBusterResolver = cacheBusterResolver;
     _bundleManager       = bundleManager;
 }