public GlobalInfoProvider(ImageflowMiddlewareOptions options, IWebHostEnvironment env, ILogger <ImageflowMiddleware> logger,
                                  IStreamCache streamCache,
                                  IClassicDiskCache diskCache, IList <IBlobProvider> blobProviders)
        {
            this.env         = env;
            this.streamCache = streamCache;
            this.options     = options;
            var plugins = new List <object>()
            {
                logger, streamCache, diskCache
            }.Concat(blobProviders).ToList();

            infoProviders = plugins.OfType <IInfoProvider>().ToList();

            pluginNames = plugins
                          .Where(p => p != null)
                          .Select(p =>
            {
                var t = p.GetType();
                if (t.Namespace != null &&
                    (t.Namespace.StartsWith("Imazen") ||
                     t.Namespace.StartsWith("Imageflow") ||
                     t.Namespace.StartsWith("Microsoft.Extensions.Logging") ||
                     t.Namespace.StartsWith("Microsoft.Extensions.Caching")))
                {
                    return(t.Name);
                }
                else
                {
                    return(t.FullName);
                }
            }).ToList();
        }
Exemplo n.º 2
0
        public ImageflowMiddleware(
            RequestDelegate next,
            IWebHostEnvironment env,
            IEnumerable <ILogger <ImageflowMiddleware> > logger,
            IEnumerable <IMemoryCache> memoryCache,
            IEnumerable <IDistributedCache> distributedCache,
            IEnumerable <ISqliteCache> sqliteCaches,
            IEnumerable <IClassicDiskCache> diskCache,
            IEnumerable <IBlobProvider> blobProviders,
            ImageflowMiddlewareOptions options)
        {
            this.next             = next;
            this.options          = options;
            this.env              = env;
            this.logger           = logger.FirstOrDefault();
            this.memoryCache      = memoryCache.FirstOrDefault();
            this.diskCache        = diskCache.FirstOrDefault();
            this.distributedCache = distributedCache.FirstOrDefault();
            this.sqliteCache      = sqliteCaches.FirstOrDefault();
            var providers   = blobProviders.ToList();
            var mappedPaths = options.MappedPaths.ToList();

            if (options.MapWebRoot)
            {
                if (this.env?.WebRootPath == null)
                {
                    throw new InvalidOperationException("Cannot call MapWebRoot if env.WebRootPath is null");
                }
                mappedPaths.Add(new PathMapping("/", this.env.WebRootPath));
            }

            blobProvider    = new BlobProvider(providers, mappedPaths);
            diagnosticsPage = new DiagnosticsPage(env, this.logger, this.memoryCache, this.distributedCache, this.diskCache, providers);
        }
 internal DiagnosticsPage(ImageflowMiddlewareOptions options, IWebHostEnvironment env, ILogger <ImageflowMiddleware> logger,
                          IStreamCache streamCache,
                          IClassicDiskCache diskCache, IList <IBlobProvider> blobProviders)
 {
     this.options       = options;
     this.env           = env;
     this.streamCache   = streamCache;
     this.diskCache     = diskCache;
     this.blobProviders = blobProviders;
 }
Exemplo n.º 4
0
 internal DiagnosticsPage(IWebHostEnvironment env, ILogger <ImageflowMiddleware> logger, IMemoryCache memoryCache, IDistributedCache distributedCache,
                          IClassicDiskCache diskCache, IList <IBlobProvider> blobProviders)
 {
     this.env              = env;
     this.logger           = logger;
     this.memoryCache      = memoryCache;
     this.distributedCache = distributedCache;
     this.diskCache        = diskCache;
     this.blobProviders    = blobProviders;
 }
Exemplo n.º 5
0
        public ImageflowMiddleware(
            RequestDelegate next,
            IWebHostEnvironment env,
            IEnumerable <ILogger <ImageflowMiddleware> > logger,
            IEnumerable <IClassicDiskCache> diskCaches,
            IEnumerable <IStreamCache> streamCaches,
            IEnumerable <IBlobProvider> blobProviders,
            ImageflowMiddlewareOptions options)
        {
            this.next = next;
            options.Licensing ??= new Licensing(LicenseManagerSingleton.GetOrCreateSingleton(
                                                    "imageflow_", new[] { env.ContentRootPath, Path.GetTempPath() }));
            this.options = options;
            this.env     = env;
            this.logger  = logger.FirstOrDefault();
            diskCache    = diskCaches.FirstOrDefault();

            var streamCacheArray = streamCaches.ToArray();

            if (streamCacheArray.Count() > 1)
            {
                throw new InvalidOperationException("Only 1 IStreamCache instance can be registered at a time");
            }

            streamCache = streamCacheArray.FirstOrDefault();


            var providers   = blobProviders.ToList();
            var mappedPaths = options.MappedPaths.ToList();

            if (options.MapWebRoot)
            {
                if (this.env?.WebRootPath == null)
                {
                    throw new InvalidOperationException("Cannot call MapWebRoot if env.WebRootPath is null");
                }
                mappedPaths.Add(new PathMapping("/", this.env.WebRootPath));
            }

            //Determine the active cache backend
            var streamCacheEnabled = streamCache != null && options.AllowCaching;
            var diskCacheEnabled   = this.diskCache != null && options.AllowDiskCaching;

            if (streamCacheEnabled)
            {
                options.ActiveCacheBackend = CacheBackend.StreamCache;
            }
            else if (diskCacheEnabled)
            {
                options.ActiveCacheBackend = CacheBackend.ClassicDiskCache;
            }
            else
            {
                options.ActiveCacheBackend = CacheBackend.NoCache;
            }


            options.Licensing.Initialize(this.options);

            blobProvider       = new BlobProvider(providers, mappedPaths);
            diagnosticsPage    = new DiagnosticsPage(options, env, this.logger, streamCache, this.diskCache, providers);
            licensePage        = new LicensePage(options);
            globalInfoProvider = new GlobalInfoProvider(options, env, this.logger, streamCache, this.diskCache, providers);

            options.Licensing.FireHeartbeat();
            GlobalPerf.Singleton.SetInfoProviders(new List <IInfoProvider>()
            {
                globalInfoProvider
            });
        }
Exemplo n.º 6
0
 public DiskCacheHostedServiceProxy(IClassicDiskCache cache)
 {
     this.cache = cache;
 }