public void Initialize(string pluginName, IScheduler scheduler) { var liveLogPlugin = new LiveLogPlugin(); scheduler.ListenerManager.AddJobListener(liveLogPlugin); scheduler.ListenerManager.AddTriggerListener(liveLogPlugin); scheduler.ListenerManager.AddSchedulerListener(liveLogPlugin); // TODO REMOVE scheduler.AddCalendar(typeof (AnnualCalendar).Name, new AnnualCalendar(), false, false); scheduler.AddCalendar(typeof (CronCalendar).Name, new CronCalendar("0 0/5 * * * ?"), false, false); scheduler.AddCalendar(typeof (DailyCalendar).Name, new DailyCalendar("12:01", "13:04"), false, false); scheduler.AddCalendar(typeof (HolidayCalendar).Name, new HolidayCalendar(), false, false); scheduler.AddCalendar(typeof (MonthlyCalendar).Name, new MonthlyCalendar(), false, false); scheduler.AddCalendar(typeof (WeeklyCalendar).Name, new WeeklyCalendar(), false, false); }
public void Initialize(string pluginName, IScheduler scheduler) { var liveLogPlugin = new LiveLogPlugin(); scheduler.ListenerManager.AddJobListener(liveLogPlugin); scheduler.ListenerManager.AddTriggerListener(liveLogPlugin); scheduler.ListenerManager.AddSchedulerListener(liveLogPlugin); // TODO REMOVE scheduler.AddCalendar(typeof(AnnualCalendar).Name, new AnnualCalendar(), false, false); scheduler.AddCalendar(typeof(CronCalendar).Name, new CronCalendar("0 0/5 * * * ?"), false, false); scheduler.AddCalendar(typeof(DailyCalendar).Name, new DailyCalendar("12:01", "13:04"), false, false); scheduler.AddCalendar(typeof(HolidayCalendar).Name, new HolidayCalendar(), false, false); scheduler.AddCalendar(typeof(MonthlyCalendar).Name, new MonthlyCalendar(), false, false); scheduler.AddCalendar(typeof(WeeklyCalendar).Name, new WeeklyCalendar(), false, false); }
public void AddBuilder(IApplicationBuilder app) { if (app == null) { throw new ArgumentNullException(nameof(app)); } IServiceProvider provider = app.ApplicationServices; //ServiceLocator.Instance.SetApplicationServiceProvider(provider); //var loggingProvider = provider.GetService<LoggingProvider>(); //if (loggingProvider == null) //{ // throw new InvalidOperationException( // "AddQuartz() must be called on the service collection. eg: services.AddQuartz(...)"); //} var scheduler = provider.GetService <IScheduler>(); if (scheduler == null) { throw new InvalidOperationException( "You must be config used message queue provider at AddQuartz() options! eg: services.AddQuartz(options=>{ options.UseInMemory(...) })"); } //:jobFactory quartz.net Execute 使用依赖注入 //var jobFactory = provider.GetService<JobFactory>(); //scheduler.JobFactory = jobFactory ?? throw new InvalidOperationException( // "You must be config used message queue provider at AddQuartz() options! eg: services.AddQuartz(options=>{ options.UseInMemory(...) })"); scheduler.JobFactory = new JobFactory(provider); //LogProvider.SetCurrentLogProvider(loggingProvider); var liveLogPlugin = new LiveLogPlugin(provider); scheduler.ListenerManager.AddJobListener(liveLogPlugin); scheduler.ListenerManager.AddTriggerListener(liveLogPlugin); scheduler.ListenerManager.AddSchedulerListener(liveLogPlugin); //scheduler.Start(); //启动 关闭 var lifetime = provider.GetService <IApplicationLifetime>(); lifetime.ApplicationStarted.Register(() => { scheduler.Start().Wait(); //网站启动完成执行 }); lifetime.ApplicationStopped.Register(() => { scheduler.Shutdown().Wait(); //网站停止完成执行 }); var dashboardQuartzOptions = provider.GetService <DashboardQuartzOptions>(); if (dashboardQuartzOptions != null) { //#if DEBUG // app.UseDeveloperExceptionPage(); //#else // app.UseExceptionHandler(dashboardQuartzOptions.ErrorPath); //#endif // app.UseStaticFiles(); var Configuration = provider.GetService <IHybridStartupConfiguration>(); Configuration.Localization.Sources.Add( new DictionaryBasedLocalizationSource( QuartzConsts.LocalizationSourceName, new JsonEmbeddedFileLocalizationDictionaryProvider( typeof(QuartzOptions).GetAssembly(), "Hybrid.Quartz.Dashboard.Localization.Sources.JsonSource" ))); //todo:UseAuthentication app.UseAuthentication(); app.UseMiddleware <DashboardMiddeware>(dashboardQuartzOptions); ////todo:UseSignalR //app.UseSignalR(routes => //{ // //这里要说下,为啥地址要写 /api/xxx // //如果你不用/api/xxx的这个规则的话,会出现跨域问题,毕竟这个不是我的MVC的路由,而且自己定义的路由 // routes.MapHub<LiveLogHub>("/api/liveLogHub"); //}); app.UseConnections(routes => { //var hubRouteBuilder = provider.GetService<HubRouteBuilder>(); //hubRouteBuilder.MapHub<LiveLogHub>("/api/liveLogHub"); //这里要说下,为啥地址要写 /api/xxx //如果你不用/api/xxx的这个规则的话,会出现跨域问题,毕竟这个不是我的MVC的路由,而且自己定义的路由 new HubRouteBuilder(routes).MapHub <LiveLogHub>("/api/liveLogHub"); }); //app.UseMvc(routes => //{ // //https://github.com/aspnet/AspNetCore/issues/7772 // //routes.MapAreaRoute( // // name: "QuartzAreaRoute", // // areaName: "Quartz", // // template: "Quartz/{controller=Home}/{action=Index}/{id?}" // //); // routes.MapRoute( // name: options.RouteName, // template: "{area:exists}/{controller=Dashboard}/{action=Index}/{id?}" // ); //}); // Verify if AddMvc was done before calling UseMvc // We use the MvcMarkerService to make sure if all the services were added. if (provider.GetService(typeof(MvcMarkerService)) == null) { throw new InvalidOperationException( "AddMvc() must be called on the service collection. eg: services.AddMvc(...)"); } //todo:mvc //var middlewarePipelineBuilder = app.ApplicationServices.GetRequiredService<MiddlewareFilterBuilder>(); //middlewarePipelineBuilder.ApplicationBuilder = app.New(); var routeBuilder = new RouteBuilder(app) { DefaultHandler = provider.GetRequiredService <MvcRouteHandler>(), }; //configureRoutes(routes); //routeBuilder.Routes.Insert(0, AttributeRouting.CreateAttributeMegaRoute(app.ApplicationServices)); routeBuilder.MapRoute(dashboardQuartzOptions.RouteName, "{area:exists}/{controller=Dashboard}/{action=Index}/{id?}"); app.UseRouter(routeBuilder.Build()); //app.UseRouter(routes=> { // routes.MapRoute( // name: options.RouteName, // template: "{area:exists}/{controller=Dashboard}/{action=Index}/{id?}" // ); //}); } }
public override void UseModule(IApplicationBuilder app) { if (!_enabled) { return; } IServiceProvider provider = app.ApplicationServices; var quartzOptions = provider.GetRequiredService <QuartzOptions>(); if (quartzOptions.StorageType.Equals(QuartzStorageType.InMemory)) { // 初始化数据库 MySqlObjectsInstaller.Initialize(quartzOptions.ConnectionStringOrCacheName, quartzOptions.TablePrefix); } if (quartzOptions.StorageType.Equals(QuartzStorageType.SqlServer)) { // 初始化SqlServer数据库 SqlServerObjectsInstaller.Initialize(quartzOptions.ConnectionStringOrCacheName, quartzOptions.TablePrefix); } var scheduler = provider.GetService <IScheduler>(); //:jobFactory quartz.net Execute 使用依赖注入 //scheduler.JobFactory = jobFactory ?? throw new InvalidOperationException( // "You must be config used message queue provider at AddQuartz() options! eg: services.AddQuartz(options=>{ options.UseInMemory(...) })"); scheduler.JobFactory = new JobFactory(provider); //LogProvider.SetCurrentLogProvider(loggingProvider); var liveLogPlugin = new LiveLogPlugin(provider); scheduler.ListenerManager.AddJobListener(liveLogPlugin); scheduler.ListenerManager.AddTriggerListener(liveLogPlugin); scheduler.ListenerManager.AddSchedulerListener(liveLogPlugin); scheduler.Start().Wait(); //var lifetime = provider.GetService<IApplicationLifetime>(); //lifetime.ApplicationStarted.Register(() => //{ // scheduler.Start().Wait(); //网站启动完成执行 //}); //lifetime.ApplicationStopped.Register(() => //{ // scheduler.Shutdown().Wait(); //网站停止完成执行 //}); //var dashboardQuartzOptions = provider.GetService<DashboardQuartzOptions>(); //if (dashboardQuartzOptions == null) return; //app.UseDashboard(dashboardQuartzOptions); var Configuration = provider.GetService <IHybridStartupConfiguration>(); Configuration.Localization.Sources.Add( new DictionaryBasedLocalizationSource( LocalizationConsts.QuartzSourceName, new JsonEmbeddedFileLocalizationDictionaryProvider( typeof(QuartzModuleBase).GetAssembly(), "Hybrid.Quartz.Dashboard.Localization.Sources.JsonSource" ))); app.UseSignalR(routes => { //这里要说下,为啥地址要写 /api/xxx //如果你不用/api/xxx的这个规则的话,会出现跨域问题,毕竟这个不是我的MVC的路由,而且自己定义的路由 routes.MapHub <LiveLogHub>("/api/liveLogHub"); }); base.UseModule(app); }
internal static IApplicationBuilder UseQuartz(this IApplicationBuilder app) { if (app == null) { throw new ArgumentNullException(nameof(app)); } IServiceProvider provider = app.ApplicationServices; //ServiceLocator.Instance.SetApplicationServiceProvider(provider); //var loggingProvider = provider.GetService<LoggingProvider>(); //if (loggingProvider == null) //{ // throw new InvalidOperationException( // "AddQuartz() must be called on the service collection. eg: services.AddQuartz(...)"); //} var scheduler = provider.GetService <IScheduler>(); if (scheduler == null) { throw new InvalidOperationException( "You must be config used message queue provider at AddQuartz() options! eg: services.AddQuartz(options=>{ options.UseInMemory(...) })"); } //:jobFactory quartz.net Execute 使用依赖注入 //var jobFactory = provider.GetService<JobFactory>(); //scheduler.JobFactory = jobFactory ?? throw new InvalidOperationException( // "You must be config used message queue provider at AddQuartz() options! eg: services.AddQuartz(options=>{ options.UseInMemory(...) })"); scheduler.JobFactory = new JobFactory(provider); //LogProvider.SetCurrentLogProvider(loggingProvider); var liveLogPlugin = new LiveLogPlugin(provider); scheduler.ListenerManager.AddJobListener(liveLogPlugin); scheduler.ListenerManager.AddTriggerListener(liveLogPlugin); scheduler.ListenerManager.AddSchedulerListener(liveLogPlugin); scheduler.Start(); //todo:启动 关闭 //var lifetime = provider.GetService<IApplicationLifetime>(); //lifetime.ApplicationStarted.Register(() => //{ // scheduler.Start().Wait(); //网站启动完成执行 //}); //lifetime.ApplicationStopped.Register(() => //{ // scheduler.Shutdown().Wait(); //网站停止完成执行 //}); var dashboardQuartzOptions = provider.GetService <DashboardQuartzOptions>(); if (dashboardQuartzOptions == null) { return(app); } app.UseDashboard(dashboardQuartzOptions); return(app); }