-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNowTrigger.cs
46 lines (39 loc) · 1.08 KB
/
NowTrigger.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
using System;
using System.Collections.Generic;
namespace Puenktlich
{
/// <summary>
/// A trigger that fires as soon as possible and only one time.
/// </summary>
public class NowTrigger : Trigger
{
private const string NowExpression = "now";
public override string Expression
{
get { return NowExpression; }
}
private bool _fired;
public override IEnumerable<DateTimeOffset> GetUpcomingOccurrences(DateTimeOffset baseTime)
{
if (!_fired)
{
_fired = true;
yield return baseTime;
}
}
public static bool TryParse(string expression, out NowTrigger trigger)
{
if (expression == NowExpression)
{
trigger = new NowTrigger();
return true;
}
trigger = null;
return false;
}
public override string ToString()
{
return NowExpression;
}
}
}