Beispiel #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.Use(async(context, next) =>
            {
                if (!context.Request.Path.StartsWithSegments("/storage", out PathString remaining))
                {
                    await next();
                    return;
                }

                if (!TryParseDeepZoom(remaining, out var result))
                {
                    await next();
                    return;
                }

                if (result.format != "jpeg")
                {
                    await next();
                    return;
                }

                var provider = context.RequestServices.GetService <ImageProvider>();
                var response = context.Response;
                if (!provider.TryGetImagePath(result.name, out string path))
                {
                    response.StatusCode = 404;
                    await response.WriteAsync("FileNotFound.");
                    return;
                }

                RetainableDeepZoomGenerator dz = provider.RetainDeepZoomGenerator(result.name, path);
                try
                {
                    response.ContentType = "image/jpeg";
                    await dz.GetTileAsJpegToStreamAsync(result.level, result.col, result.row, response.Body);
                }
                finally
                {
                    dz.Release();
                }
            });

            app.UseStaticFiles();

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Beispiel #2
0
        public IActionResult GetDzi(string name)
        {
            if (!_provider.TryGetImagePath(name, out string path))
            {
                return(NotFound());
            }
            RetainableDeepZoomGenerator dz = _provider.RetainDeepZoomGenerator(name, path);

            try
            {
                return(Content(dz.GetDzi(), "application/xml", Encoding.UTF8));
            }
            finally
            {
                dz.Release();
            }
        }