问题
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