Is it possible using the Quartz .NET assembly to generate a cron expression? I saw that the CronScheduleBuilder
class has a private member cronExpression
which is essentially what I am looking for. Is there any other way to get the cron expression itself?
Ian R. O'Brien
Possible using ICronTrigger.CronExpressionString
CronScheduleBuilder csb = CronScheduleBuilder
.WeeklyOnDayAndHourAndMinute(DayOfWeek.Monday, 12, 0);
ICronTrigger trigger = (ICronTrigger)TriggerBuilder
.Create()
.WithSchedule(csb)
.Build();
string cronExpression = trigger.CronExpressionString;
Thomas
Using Ian answer, I have created a small extension method. Hopefully it will be useful for someone else...
public static class QuartzExtensionMethods
{
public static string ToCronString(this CronScheduleBuilder cronSchedule)
{
ICronTrigger trigger = (ICronTrigger)TriggerBuilder
.Create()
.WithSchedule(cronSchedule)
.Build();
return trigger.CronExpressionString;
}
}
来源:https://stackoverflow.com/questions/13567180/create-cron-expression-using-quartz-net