-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ignore ensureCreateDatabase when useMemoryStore
refactory codes
- Loading branch information
1 parent
f0dcfd3
commit 4f70857
Showing
11 changed files
with
214 additions
and
257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
using System; | ||
|
||
namespace AspNetCoreSample.Models | ||
{ | ||
public class ErrorViewModel | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,73 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using AspNetCoreSample.Controllers; | ||
using Dapper; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using MySql.Data.MySqlClient; | ||
using Quartz; | ||
using Quartz.AspNetCore; | ||
using Quartz.AspNetCore.MySqlConnector; | ||
|
||
namespace AspNetCoreSample | ||
{ | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
public class Startup | ||
{ | ||
public Startup(IConfiguration configuration) | ||
{ | ||
Configuration = configuration; | ||
} | ||
|
||
public IConfiguration Configuration { get; } | ||
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.Configure<CookiePolicyOptions>(options => | ||
{ | ||
// This lambda determines whether user consent for non-essential cookies is needed for a given request. | ||
options.CheckConsentNeeded = context => true; | ||
options.MinimumSameSitePolicy = SameSiteMode.None; | ||
}); | ||
services.AddQuartz(options => | ||
{ | ||
options.UseMySqlConnector( | ||
"Database='quartz';Data Source=localhost;User ID=root;Password=1qazZAQ!;Port=3306"); | ||
}); | ||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
services.AddQuartz(options => | ||
{ | ||
options.UseMySqlConnector( | ||
"Database='quartz';Data Source=localhost;User ID=root;Password=1qazZAQ!;Port=3306"); | ||
// options.UseMemoryStore(); | ||
}); | ||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); | ||
} | ||
|
||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); | ||
} | ||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
else | ||
{ | ||
app.UseExceptionHandler("/Home/Error"); | ||
} | ||
|
||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | ||
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | ||
{ | ||
if (env.IsDevelopment()) | ||
{ | ||
app.UseDeveloperExceptionPage(); | ||
} | ||
else | ||
{ | ||
app.UseExceptionHandler("/Home/Error"); | ||
} | ||
app.UseQuartz(true); | ||
|
||
loggerFactory.AddConsole(LogLevel.Debug); | ||
using (var scope = app.ApplicationServices.CreateScope()) | ||
{ | ||
var provider = scope.ServiceProvider; | ||
var sched = provider.GetRequiredService<IScheduler>(); | ||
|
||
// using (var conn = | ||
// new MySqlConnection("Database='quartz';Data Source=localhost;User ID=root;Password=1qazZAQ!;Port=3306")) | ||
// { | ||
// try | ||
// { | ||
// conn.Execute("select * from QRTZ_LOCKS"); | ||
// } | ||
// catch (Exception e) | ||
// { | ||
// if (e.Message.Contains("Table 'quartz.QRTZ_LOCKS' doesn't exist")) | ||
// { | ||
// conn.Execute(DatabaseHelper.GetMysqlScript()); | ||
// } | ||
// } | ||
// } | ||
var job1 = JobBuilder.Create<SimpleJob>().WithIdentity("job1").Build(); | ||
if (!sched.CheckExists(job1.Key).Result) | ||
{ | ||
var trigger1 = TriggerBuilder.Create().WithIdentity("trigger1").WithCronSchedule("*/5 * * * * ?") | ||
.Build(); | ||
sched.ScheduleJob(job1, trigger1).GetAwaiter().GetResult(); | ||
} | ||
} | ||
|
||
app.UseQuartz(); | ||
app.UseStaticFiles(); | ||
|
||
using (var scope = app.ApplicationServices.CreateScope()) | ||
{ | ||
var provider = scope.ServiceProvider; | ||
var sched = provider.GetRequiredService<IScheduler>(); | ||
|
||
var job1 = JobBuilder.Create<SimpleJob>().WithIdentity("job1").Build(); | ||
if (!sched.CheckExists(job1.Key).Result) | ||
{ | ||
var trigger1 = TriggerBuilder.Create().WithIdentity("trigger1").WithCronSchedule("*/5 * * * * ?") | ||
.Build(); | ||
sched.ScheduleJob(job1, trigger1).GetAwaiter().GetResult(); | ||
} | ||
} | ||
|
||
app.UseStaticFiles(); | ||
app.UseCookiePolicy(); | ||
|
||
app.UseMvc(routes => | ||
{ | ||
routes.MapRoute( | ||
name: "default", | ||
template: "{controller=Home}/{action=Index}/{id?}"); | ||
}); | ||
} | ||
} | ||
} | ||
app.UseMvc(routes => | ||
{ | ||
routes.MapRoute( | ||
name: "default", | ||
template: "{controller=Home}/{action=Index}/{id?}"); | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.