Skip to content

Commit

Permalink
1. type issue
Browse files Browse the repository at this point in the history
2. auto create tables
3. implement use mysqlconnector
  • Loading branch information
Lewis Zou committed Nov 21, 2019
1 parent 06b4da8 commit f0dcfd3
Show file tree
Hide file tree
Showing 21 changed files with 986 additions and 205 deletions.
File renamed without changes.
10 changes: 9 additions & 1 deletion Quartz.AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Quartz.AspNetCore", "src\Qu
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{91FC2CB3-C370-4581-B9A5-A39287E096F8}"
ProjectSection(SolutionItems) = preProject
LICENSE = LICENSE
LICENSE.txt = LICENSE.txt
README.md = README.md
publish_myget_packages.sh = publish_myget_packages.sh
package.props = package.props
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleSample", "samples\ConsoleSample\ConsoleSample.csproj", "{EA0AD35A-5922-4A29-9248-F9AA56D10748}"
Expand All @@ -17,6 +19,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{F1AD
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNetCoreSample", "samples\AspNetCoreSample\AspNetCoreSample.csproj", "{F0B305BC-CA4C-4193-86BA-9ADCBFC50C30}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Quartz.AspNetCore.MySqlConnector", "src\Quartz.AspNetCore.MySqlConnector\Quartz.AspNetCore.MySqlConnector.csproj", "{2AB44CF7-8C3C-4145-AF74-1CBD330E69DE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -35,6 +39,10 @@ Global
{F0B305BC-CA4C-4193-86BA-9ADCBFC50C30}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0B305BC-CA4C-4193-86BA-9ADCBFC50C30}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0B305BC-CA4C-4193-86BA-9ADCBFC50C30}.Release|Any CPU.Build.0 = Release|Any CPU
{2AB44CF7-8C3C-4145-AF74-1CBD330E69DE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2AB44CF7-8C3C-4145-AF74-1CBD330E69DE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AB44CF7-8C3C-4145-AF74-1CBD330E69DE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AB44CF7-8C3C-4145-AF74-1CBD330E69DE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
27 changes: 27 additions & 0 deletions package.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@


<Project>

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Authors>zlzforever@163.com</Authors>
<Title>Quartz.AspNetCore</Title>
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
<Company>zchejian</Company>
<PackageProjectUrl>https://github.com/zlzforever/Quartz.AspNetCore</PackageProjectUrl>
<Copyright>2019 zchejian</Copyright>
<RepositoryUrl>https://github.com/zlzforever/Quartz.AspNetCore</RepositoryUrl>
<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>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\LICENSE.txt" Pack="true" PackagePath="LICENSE.txt" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions publish_myget_packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
rm -rf src/Quartz.AspNetCore/bin/Release
rm -rf src/Quartz.AspNetCore.MySqlConnector/bin/Release
dotnet publish Quartz.AspNetCore.sln -c Release
nuget push src/Quartz.AspNetCore/bin/Release/*.nupkg -source https://www.myget.org/F/zlzforever/api/v3/index.json
nuget push src/Quartz.AspNetCore.MySqlConnector/bin/Release/*.nupkg -source https://www.myget.org/F/zlzforever/api/v3/index.json
2 changes: 2 additions & 0 deletions samples/AspNetCoreSample/AspNetCoreSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Dapper" Version="2.0.30" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Quartz.AspNetCore.MySqlConnector\Quartz.AspNetCore.MySqlConnector.csproj" />
<ProjectReference Include="..\..\src\Quartz.AspNetCore\Quartz.AspNetCore.csproj" />
</ItemGroup>

Expand Down
74 changes: 27 additions & 47 deletions samples/AspNetCoreSample/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,40 @@

namespace AspNetCoreSample.Controllers
{
class MemorySimpleJob : IJob
{
public virtual Task Execute(IJobExecutionContext context)
{
JobKey jobKey = context.JobDetail.Key;
Console.WriteLine(string.Format("MemorySimpleJob says: {0} executing at {1}", jobKey, DateTime.Now.ToString("r")));
return Task.CompletedTask;
}
}


public class HomeController : Controller
{
private readonly IScheduler _sched;

public HomeController(IScheduler sched)
{
_sched = sched;
}
public class HomeController : Controller
{

public IActionResult Index()
{
public IActionResult Index()
{
return View();
}

var job1 = JobBuilder.Create<MemorySimpleJob>().WithIdentity("job1").Build();
var trigger1 = TriggerBuilder.Create().WithIdentity("trigger1").WithCronSchedule("*/5 * * * * ?").Build();
public IActionResult About()
{
ViewData["Message"] = "Your application description page.";

_sched.ScheduleJob(job1, trigger1).Wait();
return View();
}

return View();
}
public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";

public IActionResult About()
{
ViewData["Message"] = "Your application description page.";
return View();
}

return View();
}
public IActionResult Privacy()
{
return View();
}

public IActionResult Contact()
{
ViewData["Message"] = "Your contact page.";

return View();
}

public IActionResult Privacy()
{
return View();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}
}
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel {RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier});
}
}
}
16 changes: 16 additions & 0 deletions samples/AspNetCoreSample/SimpleJob.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Threading.Tasks;
using Quartz;

namespace AspNetCoreSample
{
public class SimpleJob : IJob
{
public virtual Task Execute(IJobExecutionContext context)
{
var jobKey = context.JobDetail.Key;
Console.WriteLine($"SimpleJob says: {jobKey} executing at {DateTime.Now:r}");
return Task.CompletedTask;
}
}
}
130 changes: 84 additions & 46 deletions samples/AspNetCoreSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,104 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AspNetCoreSample.Controllers;
using Dapper;
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.UseMemoryStore();
});
// 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");
});

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, ILoggerFactory loggerFactory)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
loggerFactory.AddConsole(LogLevel.Debug);
// 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();
app.UseStaticFiles();
app.UseCookiePolicy();
loggerFactory.AddConsole(LogLevel.Debug);

app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
// 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());
// }
// }
// }

app.UseQuartz();

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?}");
});
}
}
}
6 changes: 3 additions & 3 deletions samples/ConsoleSample/ConsoleSample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.1.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.5.1" />
<PackageReference Include="System.Data.SqlClient" Version="4.7.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.1.1" />
<PackageReference Include="Serilog.Sinks.PeriodicBatching" Version="2.2.0" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Quartz.AspNetCore\Quartz.AspNetCore.csproj" />
Expand Down
1 change: 0 additions & 1 deletion samples/ConsoleSample/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Quartz;
using System.Threading.Tasks;
using Quartz.Logging;
using Quartz.AspNetCore.Logging;

namespace ConsoleSample
{
Expand Down
33 changes: 33 additions & 0 deletions src/Quartz.AspNetCore.MySqlConnector/MySqlConnectorDbMetadata.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using MySql.Data.MySqlClient;
using Quartz.Impl.AdoJobStore.Common;

namespace Quartz.AspNetCore.MySqlConnector
{
public class MySqlConnectorDbMetadata : DbMetadata
{
private readonly Type _parameterDbType;
private readonly Type _connectionType;
private readonly Type _commandType;
private readonly Type _parameterType;
private readonly Type _exceptionType;

public MySqlConnectorDbMetadata()
{
_parameterDbType = typeof(MySqlDbType);
_connectionType = typeof(MySqlConnection);
_commandType = typeof(MySqlCommand);
_parameterType = typeof(MySqlParameter);
_exceptionType = typeof(MySqlException);
}

public override string ProductName => "MySQL, MySQL provider";
public override string ParameterNamePrefix => "?";
public override Type ConnectionType => _connectionType;
public override Type CommandType => _commandType;
public override Type ParameterDbType => _parameterDbType;
public override Type ParameterType => _parameterType;
public override Type ExceptionType => _exceptionType;
public override bool BindByName => true;
}
}
Loading

0 comments on commit f0dcfd3

Please sign in to comment.