Configure Quartz.NET through a mixture of config file and constructor

夙愿已清 提交于 2019-12-24 03:34:10

问题


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?

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.

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

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).

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


回答1:


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

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.

Something like this:

    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"

Check if Key Exists in NameValueCollection



来源:https://stackoverflow.com/questions/22078761/configure-quartz-net-through-a-mixture-of-config-file-and-constructor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!