本文整理汇总了C#中CronExpression类的典型用法代码示例。如果您正苦于以下问题:C# CronExpression类的具体用法?C# CronExpression怎么用?C# CronExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CronExpression类属于命名空间,在下文中一共展示了CronExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCronExpressionPassingMidnight
public void TestCronExpressionPassingMidnight()
{
CronExpression cronExpression = new CronExpression("0 15 23 * * ?");
DateTimeOffset cal = new DateTime(2005, 6, 1, 23, 16, 0).ToUniversalTime();
DateTimeOffset nextExpectedFireTime = new DateTime(2005, 6, 2, 23, 15, 0).ToUniversalTime();
Assert.AreEqual(nextExpectedFireTime, cronExpression.GetTimeAfter(cal).Value);
}
示例2: GetTargetObject
/// <summary>
/// Get the object to serialize when generating serialized file for future
/// tests, and against which to validate deserialized object.
/// </summary>
/// <returns></returns>
protected override object GetTargetObject()
{
CronExpression cronExpression = new CronExpression("0 15 10 * * ? 2005");
cronExpression.TimeZone = testTimeZone;
return cronExpression;
}
示例3: TestCronExpressionLastDayOfMonth
public void TestCronExpressionLastDayOfMonth()
{
CronExpression cronExpression = new CronExpression("0 0 12 L * ?");
int[] arrJuneDaysThatShouldFire = new int[] { 30 };
List<int> juneDays = new List<int>(arrJuneDaysThatShouldFire);
TestCorrectWeekFireDays(cronExpression, juneDays);
}
示例4: Should_be_able_to_create_an_all_inclusive_expression
public void Should_be_able_to_create_an_all_inclusive_expression()
{
var date = new DateTime(2011, 1, 1, 0, 0, 0);
var cron = new CronExpression("* * * * *", date);
for (var i = 1; i < 121; i++)
{
Assert.AreEqual(date.AddMinutes(i), cron.NextOccurrence());
}
}
示例5: TestCronExpressionParsingIncorrectDayOfWeek
public void TestCronExpressionParsingIncorrectDayOfWeek()
{
// test failed before because of improper trimming
try
{
string expr = string.Format(" * * * * * {0}", DateTime.Now.Year);
CronExpression ce = new CronExpression(expr);
ce.IsSatisfiedBy(DateTime.UtcNow.AddMinutes(2));
Assert.Fail("Accepted wrong format");
}
catch (FormatException fe)
{
Assert.AreEqual("Day-of-Week values must be between 1 and 7", fe.Message);
}
}
示例6: Should_be_able_to_get_week_days_across_month_boundary
public void Should_be_able_to_get_week_days_across_month_boundary()
{
var date = new DateTime(2011, 1, 23, 0, 0, 0);
var cron = new CronExpression("0 0 ? * 3,6", date);
Assert.AreEqual(new DateTime(2011, 1, 25, 0, 0, 0), cron.NextOccurrence());
Assert.AreEqual(new DateTime(2011, 1, 28, 0, 0, 0), cron.NextOccurrence());
Assert.AreEqual(new DateTime(2011, 2, 1, 0, 0, 0), cron.NextOccurrence());
Assert.AreEqual(new DateTime(2011, 2, 4, 0, 0, 0), cron.NextOccurrence());
Assert.AreEqual(new DateTime(2011, 2, 8, 0, 0, 0), cron.NextOccurrence());
date = new DateTime(2011, 2, 10, 0, 0, 0);
cron = new CronExpression("0 0 ? * 3,6", date);
Assert.AreEqual(new DateTime(2011, 2, 8, 0, 0, 0), cron.PreviousOccurrence());
Assert.AreEqual(new DateTime(2011, 2, 4, 0, 0, 0), cron.PreviousOccurrence());
Assert.AreEqual(new DateTime(2011, 2, 1, 0, 0, 0), cron.PreviousOccurrence());
Assert.AreEqual(new DateTime(2011, 1, 28, 0, 0, 0), cron.PreviousOccurrence());
Assert.AreEqual(new DateTime(2011, 1, 25, 0, 0, 0), cron.PreviousOccurrence());
}
示例7: Should_be_able_to_get_last_day_of_month_across_multiple_months
public void Should_be_able_to_get_last_day_of_month_across_multiple_months()
{
var date = new DateTime(2011, 1, 1, 0, 0, 0);
var cron = new CronExpression("0 0 L 1,2,5,6,9,12 *", date);
Assert.AreEqual(new DateTime(2011, 1, 31, 0, 0, 0), cron.NextOccurrence());
Assert.AreEqual(new DateTime(2011, 2, 28, 0, 0, 0), cron.NextOccurrence());
Assert.AreEqual(new DateTime(2011, 5, 31, 0, 0, 0), cron.NextOccurrence());
Assert.AreEqual(new DateTime(2011, 6, 30, 0, 0, 0), cron.NextOccurrence());
Assert.AreEqual(new DateTime(2011, 9, 30, 0, 0, 0), cron.NextOccurrence());
Assert.AreEqual(new DateTime(2011, 12, 31, 0, 0, 0), cron.NextOccurrence());
date = new DateTime(2012, 1, 1, 0, 0, 0);
cron = new CronExpression("0 0 L 1,2,5,6,9,12 *", date);
Assert.AreEqual(new DateTime(2011, 12, 31, 0, 0, 0), cron.PreviousOccurrence());
Assert.AreEqual(new DateTime(2011, 9, 30, 0, 0, 0), cron.PreviousOccurrence());
Assert.AreEqual(new DateTime(2011, 6, 30, 0, 0, 0), cron.PreviousOccurrence());
Assert.AreEqual(new DateTime(2011, 5, 31, 0, 0, 0), cron.PreviousOccurrence());
Assert.AreEqual(new DateTime(2011, 2, 28, 0, 0, 0), cron.PreviousOccurrence());
Assert.AreEqual(new DateTime(2011, 1, 31, 0, 0, 0), cron.PreviousOccurrence());
}
示例8: TestIsSatisfiedBy
public void TestIsSatisfiedBy()
{
CronExpression cronExpression = new CronExpression("0 15 10 * * ? 2005");
DateTime cal = new DateTime(2005, 6, 1, 10, 15, 0).ToUniversalTime();
Assert.IsTrue(cronExpression.IsSatisfiedBy(cal));
cal = cal.AddYears(1);
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal));
cal = new DateTime(2005, 6, 1, 10, 16, 0).ToUniversalTime();
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal));
cal = new DateTime(2005, 6, 1, 10, 14, 0).ToUniversalTime();
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal));
cronExpression = new CronExpression("0 15 10 ? * MON-FRI");
// weekends
cal = new DateTime(2007, 6, 9, 10, 15, 0).ToUniversalTime();
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal));
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal.AddDays(1)));
}
示例9: TestMonthShift
public void TestMonthShift()
{
// QRTZNET-28
CronExpression cronExpression = new CronExpression("* * 1 * * ?");
DateTimeOffset cal = new DateTime(2005, 7, 31, 22, 59, 57).ToUniversalTime();
DateTimeOffset nextExpectedFireTime = new DateTime(2005, 8, 1, 1, 0, 0).ToUniversalTime();
Assert.AreEqual(nextExpectedFireTime, cronExpression.GetTimeAfter(cal).Value);
}
示例10: TestHourShift
public void TestHourShift()
{
// cronexpression that fires every 5 seconds
CronExpression cronExpression = new CronExpression("0/5 * * * * ?");
DateTimeOffset cal = new DateTimeOffset(2005, 6, 1, 1, 59, 55, TimeSpan.Zero);
DateTimeOffset nextExpectedFireTime = new DateTimeOffset(2005, 6, 1, 2, 0, 0, TimeSpan.Zero);
Assert.AreEqual(nextExpectedFireTime, cronExpression.GetTimeAfter(cal).Value);
}
示例11: TestLastDayOffset
public void TestLastDayOffset()
{
CronExpression cronExpression = new CronExpression("0 15 10 L-2 * ? 2010");
DateTime cal = new DateTime(2010, 10, 29, 10, 15, 0).ToUniversalTime(); // last day - 2
Assert.IsTrue(cronExpression.IsSatisfiedBy(cal));
cal = new DateTime(2010, 10, 28, 10, 15, 0).ToUniversalTime();
Assert.IsFalse(cronExpression.IsSatisfiedBy(cal));
cronExpression = new CronExpression("0 15 10 L-5W * ? 2010");
cal = new DateTime(2010, 10, 26, 10, 15, 0).ToUniversalTime(); // last day - 5
Assert.IsTrue(cronExpression.IsSatisfiedBy(cal));
cronExpression = new CronExpression("0 15 10 L-1 * ? 2010");
cal = new DateTime(2010, 10, 30, 10, 15, 0).ToUniversalTime(); // last day - 1
Assert.IsTrue(cronExpression.IsSatisfiedBy(cal));
cronExpression = new CronExpression("0 15 10 L-1W * ? 2010");
cal = new DateTime(2010, 10, 29, 10, 15, 0).ToUniversalTime(); // nearest weekday to last day - 1 (29th is a friday in 2010)
Assert.IsTrue(cronExpression.IsSatisfiedBy(cal));
}
示例12: TestFormatExceptionWildCardDayOfMonthAndSpecifiedDayOfWeek
public void TestFormatExceptionWildCardDayOfMonthAndSpecifiedDayOfWeek()
{
CronExpression cronExpression = new CronExpression("0 0 * * * 4");
}
示例13: TestGetTimeAfter_QRTZNET149
public void TestGetTimeAfter_QRTZNET149()
{
CronExpression expression = new CronExpression("0 0 0 29 * ?");
DateTimeOffset? after = expression.GetNextValidTimeAfter(new DateTime(2009, 1, 30, 0, 0, 0).ToUniversalTime());
Assert.IsTrue(after.HasValue);
Assert.AreEqual(new DateTime(2009, 3, 29, 0, 0, 0).ToUniversalTime(), after.Value.DateTime);
after = expression.GetNextValidTimeAfter(new DateTime(2009, 12, 30).ToUniversalTime());
Assert.IsTrue(after.HasValue);
Assert.AreEqual(new DateTime(2010, 1, 29, 0, 0, 0).ToUniversalTime(), after.Value.DateTime);
}
示例14: CronCalendar
/// <summary>
/// Initializes a new instance of the <see cref="CronCalendar"/> class.
/// </summary>
/// <param name="expression">a string representation of the desired cron expression</param>
public CronCalendar(string expression)
{
cronExpression = new CronExpression(expression);
}
示例15: SetCronExpressionString
/// <summary>
/// Sets the cron expression for the calendar to a new value.
/// </summary>
/// <param name="expression">The expression.</param>
public void SetCronExpressionString(string expression)
{
CronExpression newExp = new CronExpression(expression);
cronExpression = newExp;
}