Skip to content

Commit

Permalink
ignore ensureCreateDatabase when useMemoryStore
Browse files Browse the repository at this point in the history
refactory codes
  • Loading branch information
zlzforever committed Nov 21, 2019
1 parent f0dcfd3 commit 4f70857
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 257 deletions.
6 changes: 2 additions & 4 deletions package.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


<Project>

<PropertyGroup>
Expand All @@ -15,8 +13,8 @@
<PackageTags>Quartz, AspNetCore</PackageTags>
<Description>A package to help you use Quartz.NET in Asp.Net core by DI easily</Description>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<Version>1.0.3</Version>
<FileVersion>1.0.3</FileVersion>
<Version>1.0.4</Version>
<FileVersion>1.0.4</FileVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions samples/AspNetCoreSample/AspNetCoreSample.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Dapper" Version="2.0.30" />
</ItemGroup>

Expand Down
7 changes: 1 addition & 6 deletions samples/AspNetCoreSample/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using AspNetCoreSample.Models;
using Quartz;

namespace AspNetCoreSample.Controllers
{
Expand Down
2 changes: 0 additions & 2 deletions samples/AspNetCoreSample/Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System;

namespace AspNetCoreSample.Models
{
public class ErrorViewModel
Expand Down
14 changes: 6 additions & 8 deletions samples/AspNetCoreSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace AspNetCoreSample
Expand All @@ -19,6 +13,10 @@ public static void Main(string[] args)

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>();
.UseStartup<Startup>().ConfigureLogging(x =>
{
x.AddConsole();
x.SetMinimumLevel(LogLevel.Information);
});
}
}
138 changes: 53 additions & 85 deletions samples/AspNetCoreSample/Startup.cs
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?}");
});
}
}
}
3 changes: 0 additions & 3 deletions samples/ConsoleSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Serilog;
using System;
using Quartz.AspNetCore;
using System.Collections.Specialized;
using Quartz;
using System.Threading.Tasks;
using Quartz.Logging;

namespace ConsoleSample
{
Expand Down
2 changes: 1 addition & 1 deletion src/Quartz.AspNetCore/Quartz.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.1" />
<PackageReference Include="Quartz" Version="3.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="DDL" />
Expand Down
3 changes: 0 additions & 3 deletions src/Quartz.AspNetCore/QuartzOtpionsBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;

namespace Quartz.AspNetCore
{
Expand Down
Loading

0 comments on commit 4f70857

Please sign in to comment.