mirror of
https://github.com/fergalmoran/SilkierQuartz.git
synced 2025-12-22 09:37:56 +00:00
93 lines
3.5 KiB
C#
93 lines
3.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using AspNetCore31.Jobs;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Options;
|
|
using Quartz;
|
|
using Quartzmin;
|
|
|
|
namespace AspNetCore31
|
|
{
|
|
public class Startup
|
|
{
|
|
public Startup(IConfiguration configuration)
|
|
{
|
|
Configuration = configuration;
|
|
}
|
|
|
|
public IConfiguration Configuration { get; }
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
public void ConfigureServices(IServiceCollection services)
|
|
{
|
|
services.AddRazorPages();
|
|
services.AddQuartzmin();
|
|
services.AddOptions();
|
|
services.Configure<AppSettings>(Configuration);
|
|
services.Configure<InjectProperty>(options => { options.WriteText = "This is inject string"; });
|
|
services.AddQuartzHostedService()
|
|
.AddQuartzJob<HelloJob>()
|
|
.AddQuartzJob<InjectSampleJob>()
|
|
.AddQuartzJob<HelloJobSingle>()
|
|
.AddQuartzJob<InjectSampleJobSingle>();
|
|
}
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IOptions<AppSettings> settings, ISchedulerFactory factory)
|
|
{
|
|
if (env.IsDevelopment())
|
|
{
|
|
app.UseDeveloperExceptionPage();
|
|
}
|
|
else
|
|
{
|
|
app.UseExceptionHandler("/Error");
|
|
}
|
|
var scheduler = DemoScheduler.Create().Result;
|
|
|
|
app.UseStaticFiles();
|
|
app.UseRouting();
|
|
app.UseAuthorization();
|
|
app.UseQuartzmin(new QuartzminOptions() { Scheduler = scheduler, VirtualPathRoot = "/Quartzmin" , UseLocalTime =true, DefaultDateFormat="yyyy-MM-dd", DefaultTimeFormat="HH:mm:ss" });
|
|
app.UseEndpoints(endpoints =>
|
|
{
|
|
endpoints.MapRazorPages();
|
|
});
|
|
if (settings.Value.EnableHelloSingleJob)
|
|
{
|
|
app.UseQuartzJob<HelloJobSingle>(TriggerBuilder.Create().WithSimpleSchedule(x => x.WithIntervalInSeconds(1).RepeatForever()))
|
|
.UseQuartzJob<InjectSampleJobSingle>(() =>
|
|
{
|
|
return TriggerBuilder.Create()
|
|
.WithSimpleSchedule(x => x.WithIntervalInSeconds(1).RepeatForever());
|
|
});
|
|
}
|
|
if (settings.Value.EnableHelloJob)
|
|
{
|
|
app.UseQuartzJob<HelloJob>(new List<TriggerBuilder>
|
|
{
|
|
TriggerBuilder.Create()
|
|
.WithSimpleSchedule(x => x.WithIntervalInSeconds(1).RepeatForever()),
|
|
TriggerBuilder.Create()
|
|
.WithSimpleSchedule(x => x.WithIntervalInSeconds(2).RepeatForever())
|
|
});
|
|
|
|
app.UseQuartzJob<InjectSampleJob>(() =>
|
|
{
|
|
var result = new List<TriggerBuilder>();
|
|
result.Add(TriggerBuilder.Create()
|
|
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever()));
|
|
return result;
|
|
});
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|