add readme

This commit is contained in:
mukmyash
2018-09-05 23:28:48 +05:00
parent 2e65fd219e
commit c86e1c3734
8 changed files with 168 additions and 2 deletions

View File

@@ -16,8 +16,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.gitattributes = .gitattributes
.gitignore = .gitignore
README.md = README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleQuartzHostedService", "sample\SampleQuartzHostedService\SampleQuartzHostedService.csproj", "{DE3C9BAF-B262-4346-996C-283E974C0449}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -52,6 +55,18 @@ Global
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2}.Release|x64.Build.0 = Release|Any CPU
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2}.Release|x86.ActiveCfg = Release|Any CPU
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2}.Release|x86.Build.0 = Release|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|x64.ActiveCfg = Debug|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|x64.Build.0 = Debug|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|x86.ActiveCfg = Debug|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Debug|x86.Build.0 = Debug|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|Any CPU.Build.0 = Release|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|x64.ActiveCfg = Release|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|x64.Build.0 = Release|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|x86.ActiveCfg = Release|Any CPU
{DE3C9BAF-B262-4346-996C-283E974C0449}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -59,6 +74,7 @@ Global
GlobalSection(NestedProjects) = preSolution
{08939639-5650-4141-9CC7-9B2956701488} = {DD437750-ADAF-4565-9B50-959A92A67100}
{B6BE5ED4-B7F3-48C3-8374-8B479F40F5F2} = {EDF98575-67B2-4C80-87FC-051AAF2A9E8A}
{DE3C9BAF-B262-4346-996C-283E974C0449} = {B2530695-ADDC-4F87-9B86-E5AEA6FF8EEC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C92A5047-9DD9-4F11-9FEE-F1AB1679F94F}

31
README.md Normal file
View File

@@ -0,0 +1,31 @@
# QuartzHostedService
Wrapper above [Quartz.NET] (https://github.com/quartznet/quartznet) for .NET Core.
## Usage
1. Create Quartz-Job implements IJob interface
``` C#
public class HelloJob : IJob
{
public Task Execute(IJobExecutionContext context)
{
Console.WriteLine("Hello");
return Task.CompletedTask;
}
}
```
1. Call extension methode __UseQuartzHostedServic__ in *IServiceCollection* and register and configure your created job.
``` C#
services.UseQuartzHostedService()
.RegiserJob<HelloJob>(() =>
{
var result = new List<TriggerBuilder>();
result.Add(TriggerBuilder.Create()
.WithSimpleSchedule(x=>x.WithIntervalInSeconds(1).RepeatForever()));
result.Add(TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInSeconds(2).RepeatForever()));
return result;
})
```

View File

@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace SampleQuartzHostedService
{
public class InjectProperty
{
public string WriteText { get; set; }
}
}

View File

@@ -0,0 +1,17 @@
using Quartz;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SampleQuartzHostedService.Jobs
{
public class HelloJob : IJob
{
public Task Execute(IJobExecutionContext context)
{
Console.WriteLine("Hello");
return Task.CompletedTask;
}
}
}

View File

@@ -0,0 +1,24 @@
using Microsoft.Extensions.Options;
using Quartz;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace SampleQuartzHostedService.Jobs
{
public class InjectSampleJob : IJob
{
InjectProperty _options;
public InjectSampleJob(IOptions<InjectProperty> options)
{
_options = options.Value;
}
public Task Execute(IJobExecutionContext context)
{
Console.WriteLine(_options.WriteText);
return Task.CompletedTask;
}
}
}

View File

@@ -0,0 +1,44 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Quartz;
using QuartzHostedService;
using SampleQuartzHostedService.Jobs;
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace SampleQuartzHostedService
{
public class Program
{
public static async Task Main(string[] args)
{
var hostBuilder = new HostBuilder()
.ConfigureServices(services =>
{
services.AddOptions();
services.Configure<InjectProperty>(options=> { options.WriteText = "This is inject string"; });
services.UseQuartzHostedService()
.RegiserJob<HelloJob>(() =>
{
var result = new List<TriggerBuilder>();
result.Add(TriggerBuilder.Create()
.WithSimpleSchedule(x=>x.WithIntervalInSeconds(1).RepeatForever()));
result.Add(TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInSeconds(2).RepeatForever()));
return result;
})
.RegiserJob<InjectSampleJob>(() =>
{
var result = new List<TriggerBuilder>();
result.Add(TriggerBuilder.Create()
.WithSimpleSchedule(x => x.WithIntervalInSeconds(10).RepeatForever()));
return result;
});
});
await hostBuilder.RunConsoleAsync();
}
}
}

View File

@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.1" />
<PackageReference Include="Quartz" Version="3.0.6" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\QuartzHostedService\QuartzHostedService.csproj" />
</ItemGroup>
</Project>

View File

@@ -11,6 +11,11 @@ namespace QuartzHostedService
{
public static class IServiceCollectionExtensions
{
public static IJobRegistrator UseQuartzHostedService(this IServiceCollection services)
{
return UseQuartzHostedService(services, null);
}
public static IJobRegistrator UseQuartzHostedService(this IServiceCollection services,
Action<NameValueCollection> stdSchedulerFactoryOptions)
{
@@ -23,7 +28,7 @@ namespace QuartzHostedService
var result = new StdSchedulerFactory();
if (options.Count > 0)
result.Initialize(options);
return new StdSchedulerFactory();
return result;
});
services.AddTransient<IJobFactory, ServiceCollectionJobFactory>();