mirror of
https://github.com/fergalmoran/SilkierQuartz.git
synced 2025-12-22 09:37:56 +00:00
减少 startup 内的 Add和 Use
This commit is contained in:
27
sample/Properties/launchSettings.json
Normal file
27
sample/Properties/launchSettings.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"iisSettings": {
|
||||||
|
"windowsAuthentication": false,
|
||||||
|
"anonymousAuthentication": true,
|
||||||
|
"iisExpress": {
|
||||||
|
"applicationUrl": "http://localhost:64450",
|
||||||
|
"sslPort": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"profiles": {
|
||||||
|
"IIS Express": {
|
||||||
|
"commandName": "IISExpress",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"SilkierQuartz.Example": {
|
||||||
|
"commandName": "Project",
|
||||||
|
"launchBrowser": true,
|
||||||
|
"applicationUrl": "http://localhost:5000",
|
||||||
|
"environmentVariables": {
|
||||||
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,8 +32,7 @@ namespace AspNetCore31
|
|||||||
services.AddOptions();
|
services.AddOptions();
|
||||||
services.Configure<AppSettings>(Configuration);
|
services.Configure<AppSettings>(Configuration);
|
||||||
services.Configure<InjectProperty>(options => { options.WriteText = "This is inject string"; });
|
services.Configure<InjectProperty>(options => { options.WriteText = "This is inject string"; });
|
||||||
services.AddQuartzHostedService()
|
services.AddQuartzJob<HelloJob>()
|
||||||
.AddQuartzJob<HelloJob>()
|
|
||||||
.AddQuartzJob<InjectSampleJob>()
|
.AddQuartzJob<InjectSampleJob>()
|
||||||
.AddQuartzJob<HelloJobSingle>()
|
.AddQuartzJob<HelloJobSingle>()
|
||||||
.AddQuartzJob<InjectSampleJobSingle>();
|
.AddQuartzJob<InjectSampleJobSingle>();
|
||||||
|
|||||||
11
sample/app.config
Normal file
11
sample/app.config
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<configSections>
|
||||||
|
<section name="quartz" type="System.Configuration.NameValueFileSectionHandler" />
|
||||||
|
</configSections>
|
||||||
|
|
||||||
|
<quartz>
|
||||||
|
<add key="quartz.plugin.recentHistory.type" value="Quartz.Plugins.RecentHistory.ExecutionHistoryPlugin, Quartz.Plugins.RecentHistory" />
|
||||||
|
<add key="quartz.plugin.recentHistory.storeType" value="Quartz.Plugins.RecentHistory.Impl.InProcExecutionHistoryStore, Quartz.Plugins.RecentHistory" />
|
||||||
|
</quartz>
|
||||||
|
</configuration>
|
||||||
@@ -1,85 +1,70 @@
|
|||||||
#if ( NETSTANDARD || NETCOREAPP )
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Diagnostics;
|
using Microsoft.AspNetCore.Diagnostics;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Routing;
|
using Microsoft.AspNetCore.Routing;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
|
using SilkierQuartz;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Specialized;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
|
||||||
namespace SilkierQuartz
|
namespace SilkierQuartz
|
||||||
{
|
{
|
||||||
public static class ApplicationBuilderExtensions
|
public static class ApplicationBuilderExtensions
|
||||||
{
|
{
|
||||||
public static void UseSilkierQuartz( this IApplicationBuilder app, SilkierQuartzOptions options, Action<Services> configure = null )
|
public static void UseSilkierQuartz(this IApplicationBuilder app, SilkierQuartzOptions options, Action<Services> configure = null)
|
||||||
{
|
{
|
||||||
options = options ?? throw new ArgumentNullException( nameof( options ) );
|
options = options ?? throw new ArgumentNullException(nameof(options));
|
||||||
|
|
||||||
app.UseFileServer( options );
|
app.UseFileServer(options);
|
||||||
|
|
||||||
var services = Services.Create( options );
|
var services = Services.Create(options);
|
||||||
configure?.Invoke( services );
|
configure?.Invoke(services);
|
||||||
|
|
||||||
app.Use( async ( context, next ) =>
|
app.Use(async (context, next) =>
|
||||||
{
|
|
||||||
context.Items[typeof( Services )] = services;
|
|
||||||
await next.Invoke();
|
|
||||||
} );
|
|
||||||
|
|
||||||
|
|
||||||
#if NETCOREAPP
|
|
||||||
app.UseEndpoints( endpoints =>
|
|
||||||
{
|
{
|
||||||
endpoints.MapControllerRoute( nameof( SilkierQuartz ), $"{options.VirtualPathRoot}/{{controller=Scheduler}}/{{action=Index}}" );
|
context.Items[typeof(Services)] = services;
|
||||||
} );
|
await next.Invoke();
|
||||||
#else
|
});
|
||||||
app.UseMvc( routes =>
|
|
||||||
{
|
app.UseEndpoints(endpoints =>
|
||||||
routes.MapRoute(
|
{
|
||||||
name: nameof( SilkierQuartz ),
|
endpoints.MapControllerRoute(nameof(SilkierQuartz), $"{options.VirtualPathRoot}/{{controller=Scheduler}}/{{action=Index}}");
|
||||||
template: "{controller=Scheduler}/{action=Index}" );
|
});
|
||||||
} );
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void UseFileServer( this IApplicationBuilder app, SilkierQuartzOptions options )
|
private static void UseFileServer(this IApplicationBuilder app, SilkierQuartzOptions options)
|
||||||
{
|
{
|
||||||
IFileProvider fs;
|
IFileProvider fs;
|
||||||
if ( string.IsNullOrEmpty( options.ContentRootDirectory ) )
|
if (string.IsNullOrEmpty(options.ContentRootDirectory))
|
||||||
fs = new ManifestEmbeddedFileProvider( Assembly.GetExecutingAssembly(), "Content" );
|
fs = new ManifestEmbeddedFileProvider(Assembly.GetExecutingAssembly(), "Content");
|
||||||
else
|
else
|
||||||
fs = new PhysicalFileProvider( options.ContentRootDirectory );
|
fs = new PhysicalFileProvider(options.ContentRootDirectory);
|
||||||
|
|
||||||
var fsOptions = new FileServerOptions()
|
var fsOptions = new FileServerOptions()
|
||||||
{
|
{
|
||||||
RequestPath = new PathString( $"{options.VirtualPathRoot}/Content" ),
|
RequestPath = new PathString($"{options.VirtualPathRoot}/Content"),
|
||||||
EnableDefaultFiles = false,
|
EnableDefaultFiles = false,
|
||||||
EnableDirectoryBrowsing = false,
|
EnableDirectoryBrowsing = false,
|
||||||
FileProvider = fs
|
FileProvider = fs
|
||||||
};
|
};
|
||||||
|
|
||||||
app.UseFileServer( fsOptions );
|
app.UseFileServer(fsOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if NETCOREAPP
|
public static void AddSilkierQuartz(this IServiceCollection services, Action<NameValueCollection> stdSchedulerFactoryOptions = null)
|
||||||
public static void AddSilkierQuartz( this IServiceCollection services )
|
|
||||||
{
|
{
|
||||||
services.AddControllers()
|
services.AddControllers()
|
||||||
.AddApplicationPart( Assembly.GetExecutingAssembly() )
|
.AddApplicationPart(Assembly.GetExecutingAssembly())
|
||||||
.AddNewtonsoftJson();
|
.AddNewtonsoftJson();
|
||||||
|
services.UseQuartzHostedService(stdSchedulerFactoryOptions);
|
||||||
|
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
public static void AddSilkierQuartz( this IServiceCollection services )
|
|
||||||
{
|
|
||||||
services.AddMvcCore()
|
|
||||||
.AddApplicationPart( Assembly.GetExecutingAssembly() )
|
|
||||||
.AddJsonFormatters();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Quartz;
|
using Quartz;
|
||||||
using Quartz.Spi;
|
using Quartz.Spi;
|
||||||
|
using SilkierQuartz.HostedService;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -9,7 +10,7 @@ using System.Text;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace SilkierQuartz.HostedService
|
namespace SilkierQuartz
|
||||||
{
|
{
|
||||||
public static class IJobRegistratorExtensions
|
public static class IJobRegistratorExtensions
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ using Microsoft.Extensions.Hosting;
|
|||||||
using Quartz;
|
using Quartz;
|
||||||
using Quartz.Impl;
|
using Quartz.Impl;
|
||||||
using Quartz.Spi;
|
using Quartz.Spi;
|
||||||
|
using SilkierQuartz.HostedService;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Specialized;
|
using System.Collections.Specialized;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
namespace SilkierQuartz.HostedService
|
namespace SilkierQuartz
|
||||||
{
|
{
|
||||||
public static class IServiceCollectionExtensions
|
public static class IServiceCollectionExtensions
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -77,7 +77,7 @@
|
|||||||
|
|
||||||
{{#footer}}
|
{{#footer}}
|
||||||
<footer style="text-align:center; margin-top: 3em; padding: .8em 0; background-color: #f8f8f8; font-size: 90%; border-top: 1px solid rgba(34,36,38,.1);">
|
<footer style="text-align:center; margin-top: 3em; padding: .8em 0; background-color: #f8f8f8; font-size: 90%; border-top: 1px solid rgba(34,36,38,.1);">
|
||||||
<a href="https://github.com/jlucansky/SilkierQuartz" target="_blank" style="color: #909090"><i class="github icon"></i> SilkierQuartz v{{SilkierQuartzVersion}}</a>
|
<a href="https://github.com/maikebing/SilkierQuartz" target="_blank" style="color: #909090"><i class="github icon"></i> SilkierQuartz v{{SilkierQuartzVersion}}</a>
|
||||||
</footer>
|
</footer>
|
||||||
{{/footer}}
|
{{/footer}}
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in New Issue
Block a user