通过配置文件和构造函数的混合配置 Quartz.NET [英] Configure Quartz.NET through a mixture of config file and constructor

查看:39
本文介绍了通过配置文件和构造函数的混合配置 Quartz.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过配置文件(quartz.properties 或 app.config/web.config)中保存的混合属性以及一些通过 StdSchedulerFactory 构造函数来配置 Quartz?

Is it possible to configure Quartz through a mixture of properties held in a config file (either quartz.properties or app.config / web.config) and also some via the StdSchedulerFactory constructor?

我想通过构造函数传递 AdoJobStore 连接字符串,因为它根据环境是动态的,但其余设置是静态的,因此最好放在配置文件中.

I would like to pass the AdoJobStore connectionstring via the constructor, as it is dynamic depending on the environment, but the rest of the settings are static so would be better placed in a config file.

我已经尝试通过构造函数只传入 quartz.dataSource.myDS.connectionString 属性,同时在工作目录的quartz.config 中包含其余属性.但是,我收到错误:

I've tried passing in only the quartz.dataSource.myDS.connectionString property via the constructor, whilst having the rest of the properties in a quartz.config in the working directory. However, I get the error:

Provider not specified for DataSource: myDS

所以我想这意味着如果您使用接受 NameValueCollection 的构造函数,那么它就不会费心检查配置文件.

So I guess this means that if you use the constructor that accepts the NameValueCollection, then it doesn't bother checking the config file(s).

我知道quartz.config 文件在正确的位置,因为如果我将连接字符串放在那里并使用默认构造函数,它一切正常

I know that the quartz.config file is in the right place, because if I put the connectionstring in there and use the default constructor, it all works

推荐答案

说到底,它们都是简单的命名-值对.

In the end, they are all simply named-value pairs.

您可以在 .xml 文件中包含大部分"内容……然后通过代码添加"您想要的内容.

You can have "most" of them in an .xml file...then "add in" the ones you want via code.

或者将它们全部写入代码.

Or have all of them in code.

查看源代码的单元测试,你会很清楚地看到这一点.

See the UnitTests for the source code, and you'll see this fairly clearly.

像这样:

    NameValueCollection config = (NameValueCollection)ConfigurationManager.GetSection("quartz");

    config.Add("MyCodedUpKey", "MyCodedUpValue");

如果您有冲突"(配置文件中要覆盖的密钥"..应用一些简单的名称值对更新现有密钥"逻辑"

If you have a "collision" (a "key" in the config file that you want to override..apply some simple name-valued-pair "update existing key" logic"

检查 NameValueCollection 中是否存在键

这篇关于通过配置文件和构造函数的混合配置 Quartz.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆