シュタイナーの答えは私を正しい方向に導きました。中程度の信頼のホスティング環境で QuartZNet を動作させるための手順をここで共有します。
QuartzNet は当初、中程度の信頼でアクセス許可の問題に遭遇しました。問題を解決するには、次のことを行う必要がありました。
(1) github から QuartzNet コード ( 2.1.0.400 ) をダウンロードし、AssemblyInfo.cs に次の変更を加えてからビルドします。
交換済み
#if !NET_40
[assembly: System.Security.AllowPartiallyTrustedCallers]
#endif
と
[assembly: AllowPartiallyTrustedCallers]
#if NET_40
[assembly: SecurityRules(SecurityRuleSet.Level1)]
#endif
(2) C5 コード (v 2.1) をダウンロードし、
[assembly: AllowPartiallyTrustedCallersAttribute()
C5 が Qartznet と同じ .NET バージョンでコンパイルされていることを確認します。
(3) TGH 内の web.config に Quartz セクションを追加しました。このセクションでは、requirepermission が false に設定されていました。共通ログ セクションも requirepermission を false に設定し、Common.Logging.Simple.NoOpLoggerFactoryAdapter を使用するように構成しました。
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" requirePermission="false" />
</sectionGroup>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Simple.NoOpLoggerFactoryAdapter, Common.Logging">
<arg key="showLogName" value="true" />
<arg key="showDataTime" value="true" />
<arg key="level" value="OFF" />
<arg key="dateTimeFormat" value="HH:mm:ss:fff" />
</factoryAdapter>
</logging>
</common>
<quartz>
<add key="quartz.scheduler.instanceName" value="QuartzScheduler" />
<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" />
</quartz>
(4) namecollection をパラメーターとしてコンストラクターを使用してスケジューラーを初期化しました。namecollection は、web.config から取得された Quartz セクションでした。
global.asax 内
QuartzScheduler.Start();
クラス
public class QuartzScheduler
{
public static void Start()
{
ISchedulerFactory schedulerFactory = new StdSchedulerFactory((NameValueCollection)ConfigurationManager.GetSection("quartz"));
IScheduler scheduler = schedulerFactory.GetScheduler();
scheduler.Start();
IJobDetail inviteRequestProcessor = new JobDetailImpl("ProcessInviteRequest", null, typeof(InviteRequestJob));
IDailyTimeIntervalTrigger trigger = new DailyTimeIntervalTriggerImpl("Invite Request Trigger", Quartz.TimeOfDay.HourMinuteAndSecondOfDay(0, 0, 0), Quartz.TimeOfDay.HourMinuteAndSecondOfDay(23, 23, 59), Quartz.IntervalUnit.Second, 1);
scheduler.ScheduleJob(inviteRequestProcessor, trigger);
}
}
public class InviteRequestJob : IJob
{
public void Execute(IJobExecutionContext context)
{
RequestInvite.ProcessInviteRequests();
}
}