简体   繁体   English

配置文件名“ quartz.config”是否固定(表示硬编码,不能更改)?

[英]Is the config file name “quartz.config” fixed (means hard-code, cannot be changed)?

I know that Quartz.Net has several ways to loads it configuration upon startup: (from http://jvilalta.blogspot.com/2011/03/how-does-quartznet-configuration-work.html ) 我知道Quartz.Net有几种在启动时加载其配置的方法:(来自http://jvilalta.blogspot.com/2011/03/how-does-quartznet-configuration-work.html

  1. The hosting application's configuration file 托管应用程序的配置文件
  2. A file specified in an environment variable 在环境变量中指定的文件
  3. The quartz.config file quartz.config文件
  4. The embedded configuration file 嵌入式配置文件

Notice the quartz.config file. 请注意quartz.config文件。

My question: 我的问题:

  1. Is the config file name "quartz.config" fixed (means hard-code, cannot be changed)? 配置文件名“ quartz.config”是否固定(表示硬编码,不能更改)?

  2. If no, how can I change it? 如果没有,我该如何更改? eg I want to read from FinancialQuartz.config instead of quartz.config. 例如,我想从FinancialQuartz.config而不是quartz.config中读取。

  3. If no option to change the name "quartz.config". 如果没有选项,则更改名称“ quartz.config”。 How can I specify when to read from FinancialQuartz.config or CalculationQuartz.config? 如何指定何时从FinancialQuartz.config或CalculationQuartz.config中读取? (I have no real scenario for this question, just wonder) (对于这个问题,我没有实际情况,只是想知道)

Regards, 问候,

I'm confused. 我糊涂了。

In DotNet. 在DotNet中。 You can point the app.config or web.config file to your file of choice, like below. 您可以将app.config或web.config文件指向您选择的文件,如下所示。

<?xml version="1.0" encoding="utf-8"?>
<configuration>


    <configSections>
        <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        </sectionGroup>

    </configSections>

    <quartz configSource="MyQuartzSettings.config" />

And "MyQuartzSettings.config" looks something like this (one example of many) 而且“ MyQuartzSettings.config”看起来像这样(很多示例)

<quartz>

    <add key="quartz.plugin.jobInitializer.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin" />
    <add key="quartz.scheduler.instanceName" value="DefaultQuartzScheduler" />
    <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
    <add key="quartz.threadPool.threadCount" value="10" />
    <add key="quartz.threadPool.threadPriority" value="2" />
    <add key="quartz.jobStore.misfireThreshold" value="60000" />
    <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
    <add key="quartz.plugin.jobInitializer.fileNames" value="Quartz_Jobs_001.xml" />
    <add key="quartz.plugin.jobInitializer.failOnFileNotFound" value="true" />
    <add key="quartz.plugin.jobInitializer.scanInterval" value="120" />

</quartz>

Is that what you're talking about? 那是你在说什么吗?

In addition to the answer given by @granadaCoder, you can also set the quartz.config environment variable to the name of the file you want to load. 除了@granadaCoder给出的答案外,您还可以将quartz.config环境变量设置为要加载的文件的名称。 Note that the configSource attribute is not quartz.net specific but a feature of the .Net framework: SectionInformation.ConfigSource Property 请注意,configSource属性不是特定于quartz.net,而是.Net框架的功能: SectionInformation.ConfigSource属性

I think it's fixed now. 我认为现在已经解决。 But there's a workaround for it. 但是有一个解决方法。

Read the configuration from other ways into a System.Collections.Specialized.NameValueCollection . 从其他方式将配置读取到System.Collections.Specialized.NameValueCollection

var builder = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddIniFile("someotherfile.ini", false, true);

var config = builder.Build();

var quartzProperties = new System.Collections.Specialized.NameValueCollection();
foreach (var p in config.GetSection("Quartz").GetChildren().AsEnumerable())
{
    quartzProperties.Add(p.Key, p.Value);
}

IScheduler scheduler = new StdSchedulerFactory(quartzProperties).GetScheduler();
scheduler.Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM