Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在ASP.NET Web API核心应用程序上使用QUARTZ实现调度器?_C#_Asp.net_Asp.net Web Api_Asp.net Core_Quartz Scheduler - Fatal编程技术网

C# 如何在ASP.NET Web API核心应用程序上使用QUARTZ实现调度器?

C# 如何在ASP.NET Web API核心应用程序上使用QUARTZ实现调度器?,c#,asp.net,asp.net-web-api,asp.net-core,quartz-scheduler,C#,Asp.net,Asp.net Web Api,Asp.net Core,Quartz Scheduler,我目前正在开发一个Web API,用于处理约会和重复事件。我发现quartz-scheduler.net是合适的,但问题是它与asp.net核心版本不兼容 是否有办法将quartz.NET实现到asp.NET core,或者是否有某种替代品或替代品?quartz.NET 3.0 Alpha 1发布:支持.NET core/netstandard 1.3。 更多信息请参见此 您可以监视此记录单中的进度:我按照以下步骤完成了此操作: 已创建.NET核心服务扩展(QuartzExtension.cs)

我目前正在开发一个Web API,用于处理约会和重复事件。我发现quartz-scheduler.net是合适的,但问题是它与asp.net核心版本不兼容


是否有办法将quartz.NET实现到asp.NET core,或者是否有某种替代品或替代品?

quartz.NET 3.0 Alpha 1发布:支持.NET core/netstandard 1.3。 更多信息请参见此


您可以监视此记录单中的进度:

我按照以下步骤完成了此操作:

  • 已创建.NET核心服务扩展(QuartzExtension.cs):

  • PS1:我使用的所有东西都是从和获得的

    PS2:不要忘记创建localdb数据库,并按照quartznet提供的脚本填充它

    public static class QuartzExtensions
    {
        public static void UseQuartz(this IApplicationBuilder app)
        {
            app.ApplicationServices.GetService<IScheduler>();
        }
    
        public static async void AddQuartz(this IServiceCollection services)
        {
            var properties = new NameValueCollection
            {
                // json serialization is the one supported under .NET Core (binary isn't)
                ["quartz.serializer.type"] = "json",
    
                // the following setup of job store is just for example and it didn't change from v2
                ["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobStoreTX, Quartz",
                ["quartz.jobStore.useProperties"] = "false",
                ["quartz.jobStore.dataSource"] = "default",
                ["quartz.jobStore.tablePrefix"] = "QRTZ_",
                ["quartz.jobStore.driverDelegateType"] = "Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz",
                ["quartz.dataSource.default.provider"] = "SqlServer-41", // SqlServer-41 is the new provider for .NET Core
                ["quartz.dataSource.default.connectionString"] = @"Server=(localdb)\MSSQLLocalDB;Database=sta-scheduler-quartz;Integrated Security=true"
            };
    
            var schedulerFactory = new StdSchedulerFactory(properties);
            var scheduler = schedulerFactory.GetScheduler().Result;
            scheduler.Start().Wait();
    
            services.AddSingleton<IScheduler>(scheduler);
        }
    }
    
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }
    
        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.AddMvc();
    
            // Authentication service
            JwtAuthentication.AddJwtAuthentication(services);
    
            services.AddQuartz(); // <======== THIS LINE
    
            services.AddSingleton<IHttpRequestScheduler, HttpRequestScheduler>();
        }
    
        // 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,
                              IApplicationLifetime lifetime)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
    
            app.UseMvc();
    
            app.UseAuthentication();
    
            // Add JWT generation endpoint:
            var options = new TokenProviderOptions
            {
                Audience = "ExampleAudience",
                Issuer = "ExampleIssuer",
                SigningCredentials = new SigningCredentials(JwtAuthentication.SIGNING_KEY, SecurityAlgorithms.HmacSha256),
            };
    
            app.UseMiddleware<TokenProviderMiddleware>(Options.Create(options));
    
            app.UseQuartz(); // <======== THIS LINE
        }
    }
    
    public class HttpRequestScheduler : IHttpRequestScheduler
    {
        private IScheduler _scheduler;
    
        public HttpRequestScheduler(IScheduler scheduler)
        {
            _scheduler = scheduler;
        }
    
        public void Schedule()
        {
            // Whatever you want to do with the scheduler
            ...
        }
    }