private static void UseFileServer(this IAppBuilder app, QuartzminOptions options)
        {
            IFileSystem fs;

            if (string.IsNullOrEmpty(options.ContentRootDirectory))
            {
                fs = new FixedEmbeddedResourceFileSystem(Assembly.GetExecutingAssembly(), nameof(Quartzmin) + ".Content");
            }
            else
            {
                fs = new PhysicalFileSystem(options.ContentRootDirectory);
            }

            var fsOoptions = new FileServerOptions()
            {
#if NETCOREAPP
                RequestPath = new PathString("/Quartzmin/Content"),
#else
                RequestPath = new PathString("/Content"),
#endif
                EnableDefaultFiles = false,
                FileSystem         = fs
            };

            var mimeMap = ((FileExtensionContentTypeProvider)fsOoptions.StaticFileOptions.ContentTypeProvider).Mappings;

            if (!mimeMap.ContainsKey(".woff2"))
            {
                mimeMap.Add(".woff2", "application/font-woff2");
            }

            app.UseFileServer(fsOoptions);
        }
        public static void UseQuartzmin(this IAppBuilder app, QuartzminOptions options, Action <Services> configure = null)
        {
            options = options ?? throw new ArgumentNullException(nameof(options));

            app.UseFileServer(options);

            var services = Services.Create(options);

            configure?.Invoke(services);

            app.Use((owin, next) =>
            {
                owin.Set(Services.ContextKey, services);
                return(next());
            });

            HttpConfiguration config = new HttpConfiguration();

            config.Routes.MapHttpRoute(
                name: nameof(Quartzmin),
                routeTemplate: "{controller}/{action}",
                defaults: new { controller = "Scheduler", action = "Index" }
                );

            config.Formatters.Add(new FormMultipartEncodedMediaTypeFormatter(new MultipartFormatterSettings()
            {
                ValidateNonNullableMissedProperty = false, CultureInfo = CultureInfo.InvariantCulture
            }));

            config.Services.Replace(typeof(IHostBufferPolicySelector), new BufferPolicySelector());
            config.Services.Replace(typeof(IExceptionHandler), new ExceptionHandler((IExceptionHandler)config.Services.GetService(typeof(IExceptionHandler)), services.ViewEngine.ErrorPage, true));

            app.UseWebApi(config);
        }
Exemple #3
0
        public static void UseQuartzmin(this IApplicationBuilder app, QuartzminOptions options, Action <Services> configure = null)
        {
            options = options ?? throw new ArgumentNullException(nameof(options));

            app.UseFileServer(options);

            var services = Services.Create(options);

            configure?.Invoke(services);

            app.Use(async(context, next) =>
            {
                context.Items[typeof(Services)] = services;
                await next.Invoke();
            });

            app.UseExceptionHandler(errorApp =>
            {
                errorApp.Run(async context =>
                {
                    var ex = context.Features.Get <IExceptionHandlerFeature>().Error;
                    context.Response.StatusCode  = 500;
                    context.Response.ContentType = "text/html";
                    await context.Response.WriteAsync(services.ViewEngine.ErrorPage(ex));
                });
            });
        }
        public static void UseQuartzmin(this IApplicationBuilder app, QuartzminOptions options, Action <Services> configure = null)
        {
            options = options ?? throw new ArgumentNullException(nameof(options));

            app.UseFileServer(options);

            var services = Services.Create(options);

            configure?.Invoke(services);

            app.Use(async(context, next) =>
            {
                context.Items[typeof(Services)] = services;
                await next.Invoke();
            });


#if NETCOREAPP
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(nameof(Quartzmin), $"{options.VirtualPathRoot}/{{controller=Scheduler}}/{{action=Index}}");
            });
#else
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: nameof(Quartzmin),
                    template: "{controller=Scheduler}/{action=Index}");
            });
#endif
        }
Exemple #5
0
        private static void UseFileServer(this IApplicationBuilder app, QuartzminOptions options)
        {
            IFileProvider fs;

            if (string.IsNullOrEmpty(options.ContentRootDirectory))
            {
                fs = new ManifestEmbeddedFileProvider(Assembly.GetExecutingAssembly(), "Content");
            }
            else
            {
                fs = new PhysicalFileProvider(options.ContentRootDirectory);
            }

            var fsOptions = new FileServerOptions()
            {
#if NETCOREAPP
                RequestPath = new PathString("/Quartzmin/Content"),
#else
                RequestPath = new PathString("/Content"),
#endif
                EnableDefaultFiles      = false,
                EnableDirectoryBrowsing = false,
                FileProvider            = fs
            };

            app.UseFileServer(fsOptions);
        }
Exemple #6
0
        public static ViewEngineFileSystem Create(QuartzminOptions options)
        {
            ViewEngineFileSystem fs;

            if (string.IsNullOrEmpty(options.ViewsRootDirectory))
            {
                fs = new EmbeddedFileSystem();
            }
            else
            {
                fs = new DiskFileSystem(options.ViewsRootDirectory);
            }

            return(fs);
        }
Exemple #7
0
        public static void UseQuartzmin(this IApplicationBuilder app, QuartzminOptions options, Action <Services> configure = null)
        {
            options = options ?? throw new ArgumentNullException(nameof(options));

            app.UseFileServer(options);

            var services = Services.Create(options);

            configure?.Invoke(services);

            app.Use(async(context, next) =>
            {
                context.Items[typeof(Services)] = services;
                await next.Invoke();
            });
        }
Exemple #8
0
        public static void UseQuartzmin(this IApplicationBuilder app, QuartzminOptions options, Action <Services> configure = null)
        {
            options = options ?? throw new ArgumentNullException(nameof(options));

            app.UseFileServer(options);

            var services = Services.Create(options);

            configure?.Invoke(services);

            app.Use(async(context, next) =>
            {
                context.Items[typeof(Services)] = services;
                await next.Invoke();
            });

            app.UseExceptionHandler(errorApp =>
            {
                errorApp.Run(async context =>
                {
                    var ex = context.Features.Get <IExceptionHandlerFeature>().Error;
                    context.Response.StatusCode  = 500;
                    context.Response.ContentType = "text/html";
                    await context.Response.WriteAsync(services.ViewEngine.ErrorPage(ex));
                });
            });

#if NETCORE
            app.UseRouting();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(nameof(Quartzmin), "{controller=Scheduler}/{action=Index}");
            });
#endif

#if NETSTANDARD
            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: nameof(Quartzmin),
                    template: "{controller=Scheduler}/{action=Index}");
            });
#endif
        }
Exemple #9
0
        public static Services Create(QuartzminOptions options)
        {
            var handlebarsConfiguration = new HandlebarsConfiguration()
            {
                FileSystem = ViewFileSystemFactory.Create(options),
                ThrowOnUnresolvedBindingExpression = true,
            };

            var services = new Services()
            {
                Options    = options,
                Scheduler  = options.Scheduler,
                Handlebars = HandlebarsDotNet.Handlebars.Create(handlebarsConfiguration),
            };

            HandlebarsHelpers.Register(services);

            services.ViewEngine   = new ViewEngine(services);
            services.TypeHandlers = new TypeHandlerService(services);
            services.Cache        = new Cache(services);

            return(services);
        }