-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrigger.cs
68 lines (57 loc) · 2.37 KB
/
Trigger.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
namespace Puenktlich
{
/// <summary>
/// Provides a trigger that defines a point in time.
/// </summary>
public interface ITrigger
{
/// <summary>
/// Gets the expression for this trigger.
/// </summary>
string Expression { get; }
/// <summary>
/// Gets the (possibly infinite) upcoming occurrences of this trigger after <paramref name="baseTime" />.
/// </summary>
/// <param name="baseTime">The base time at which to start the calculation.</param>
/// <returns>An (possibly infinite) enumerable of upcoming occurrences.</returns>
IEnumerable<DateTimeOffset> GetUpcomingOccurrences(DateTimeOffset baseTime);
}
/// <summary>
/// Base class for all triggers.
/// </summary>
public abstract class Trigger : ITrigger
{
/// <summary>
/// Gets the (possibly infinite) upcoming occurrences of this trigger after <paramref name="baseTime" />.
/// </summary>
/// <param name="baseTime">The base time at which to start the calculation.</param>
/// <returns>
/// An (possibly infinite) enumerable of upcoming occurrences.
/// </returns>
public abstract IEnumerable<DateTimeOffset> GetUpcomingOccurrences(DateTimeOffset baseTime);
/// <summary>
/// Gets the expression for this trigger.
/// </summary>
public abstract string Expression { get; }
/// <summary>
/// Create a build-in trigger from an expression.
/// </summary>
/// <param name="expression"></param>
/// <returns></returns>
public static ITrigger Create(string expression)
{
NowTrigger nowTrigger;
if (NowTrigger.TryParse(expression, out nowTrigger))
return nowTrigger;
ManualTrigger manualTrigger;
if (ManualTrigger.TryParse(expression, out manualTrigger))
return manualTrigger;
CronTrigger cronTrigger;
if (CronTrigger.TryParse(expression, out cronTrigger))
return cronTrigger;
throw new ArgumentException(string.Format("No trigger for expression '{0}' found", expression), "expression");
}
}
}