Files
SilkierQuartz/sample/Startup.cs
2021-02-26 20:49:34 +07:00

109 lines
4.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Quartz;
using SilkierQuartz.Example.Jobs;
using System.Collections.Generic;
namespace SilkierQuartz.Example
{
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.AddSilkierQuartz();
services.AddOptions();
services.Configure<AppSettings>(Configuration);
services.Configure<InjectProperty>(options => { options.WriteText = "This is inject string"; });
services.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)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthentication();
app.AddSilkierQuartzAuthentication();
app.UseAuthorization();
app.UseSilkierQuartz(
new SilkierQuartzOptions()
{
VirtualPathRoot = "/SilkierQuartz",
UseLocalTime = true,
DefaultDateFormat = "yyyy-MM-dd",
DefaultTimeFormat = "HH:mm:ss",
CronExpressionOptions = new CronExpressionDescriptor.Options()
{
DayOfWeekStartIndexZero = false //Quartz uses 1-7 as the range
},
AccountName = "admin",
AccountPassword = "password",
IsAuthenticationPersist = false
}
);
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
//How to compatible old code to SilkierQuartz
//<2F><><EFBFBD>ɵ<EFBFBD>ԭ<EFBFBD><D4AD><EFBFBD>Ĺ滮Job<6F>Ĵ<EFBFBD><C4B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֲ<EFBFBD><D6B2><EFBFBD>ݵ<EFBFBD>ʾ<EFBFBD><CABE>
// app.SchedulerJobs();
#region <EFBFBD><EFBFBD>ʹ<EFBFBD><EFBFBD> SilkierQuartzAttribe <EFBFBD><EFBFBD><EFBFBD>ԵĽ<EFBFBD><EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD>IJob<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD>UseQuartzJob<EFBFBD><EFBFBD>IJob<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ConfigureServices<EFBFBD><EFBFBD><EFBFBD><EFBFBD>AddQuartzJob
app.UseQuartzJob<HelloJobSingle>(TriggerBuilder.Create().WithSimpleSchedule(x => x.WithIntervalInSeconds(1).RepeatForever()))
.UseQuartzJob<InjectSampleJobSingle>(() =>
{
return TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInSeconds(1).RepeatForever());
});
app.UseQuartzJob<HelloJob>(new List<TriggerBuilder>
{
TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInSeconds(1).RepeatForever()),
TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInSeconds(2).RepeatForever()),
//Add a sample that uses 1-7 for dow
TriggerBuilder.Create()
.WithCronSchedule("0 0 2 ? * 7 *"),
});
app.UseQuartzJob<InjectSampleJob>(() =>
{
var result = new List<TriggerBuilder>();
result.Add(TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever()));
return result;
});
#endregion
}
}
}