Skip to content

Commit 74379c8

Browse files
committed
Initial commit.
1 parent ec6fc77 commit 74379c8

18 files changed

+1358
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.31101.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PointerPlace.Scheduler", "PointerPlace.Scheduler\PointerPlace.Scheduler.csproj", "{CB717645-1EAB-407F-A98E-0777758410BA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{CB717645-1EAB-407F-A98E-0777758410BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{CB717645-1EAB-407F-A98E-0777758410BA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{CB717645-1EAB-407F-A98E-0777758410BA}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{CB717645-1EAB-407F-A98E-0777758410BA}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* (C)2014 Ivan Andrew Pointer (ivan@pointerplace.us)
3+
* Date: 11/24/2014
4+
* License: Apache License 2 (https://github.com/ivanpointer/Scheduler/blob/master/LICENSE)
5+
* GitHub: https://github.com/ivanpointer/Scheduler
6+
*/
7+
8+
using System;
9+
10+
namespace PointerPlace.Scheduler
11+
{
12+
/// <summary>
13+
/// Indicates that a schedule is impossible. In other-words, either the schedule cannot be parsed,
14+
/// or there is no possible "next date" for the schedule.
15+
/// </summary>
16+
class ImpossibleScheduleException : Exception
17+
{
18+
public ImpossibleScheduleException()
19+
: base() { }
20+
21+
public ImpossibleScheduleException(string message)
22+
: base(message) { }
23+
}
24+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* (C)2014 Ivan Andrew Pointer (ivan@pointerplace.us)
3+
* Date: 11/24/2014
4+
* License: Apache License 2 (https://github.com/ivanpointer/Scheduler/blob/master/LICENSE)
5+
* GitHub: https://github.com/ivanpointer/Scheduler
6+
*/
7+
8+
using System;
9+
using System.Linq;
10+
11+
namespace PointerPlace.Scheduler.Matchers
12+
{
13+
/// <summary>
14+
/// Matches and increments the day of month field on a PointInTime
15+
/// </summary>
16+
public class DayOfMonthMatcher : MatcherBase
17+
{
18+
19+
#region Members
20+
21+
private PointInTime Point { get; set; }
22+
23+
private bool Any { get; set; }
24+
private int[] ValidDays { get; set; }
25+
26+
#endregion
27+
28+
/// <summary>
29+
/// Constructs a DayOfMonthMatcher for the given PointInTime and Schedule
30+
/// </summary>
31+
/// <param name="point">The PointInTime for which to build this matcher</param>
32+
/// <param name="schedule">The Schedule for which to build this matcher</param>
33+
public DayOfMonthMatcher(PointInTime point, Schedule schedule)
34+
{
35+
Point = point;
36+
37+
ValidDays = GenerateSimpleList(schedule.DayOfMonth, 1, 31);
38+
39+
var length = ValidDays.Length;
40+
if (length == 31)
41+
{
42+
Any = true;
43+
}
44+
else if (length != 0)
45+
{
46+
Any = false;
47+
}
48+
else
49+
{
50+
throw new ImpossibleScheduleException("Schedule has no possible valid days of month");
51+
}
52+
}
53+
54+
// Determines whether the given PointInTime matches this matcher
55+
public override bool Matches(PointInTime point)
56+
{
57+
return Any || ValidDays.Contains(point.Day);
58+
}
59+
60+
// Determins whether the point in time assigned to this matcher, matches this matcher
61+
public override bool Matches()
62+
{
63+
return Matches(Point);
64+
}
65+
66+
// Determines the next matching value for this matcher, starting from the PointInTime assigned to this matcher. If there
67+
// is no valid next value, -1 is returned.
68+
public override int NextMatch()
69+
{
70+
return NextMatch(ValidDays, Point.Day, DateTime.DaysInMonth(Point.Year, Point.Month));
71+
}
72+
73+
// Tries to increment the internal PointInTime to its next valid value, returns true if successfull, false otherwise.
74+
public override bool Increment()
75+
{
76+
var nextMatch = NextMatch();
77+
if (nextMatch != -1)
78+
{
79+
Point.AdvanceDay(nextMatch);
80+
return true;
81+
}
82+
else
83+
{
84+
return false;
85+
}
86+
}
87+
}
88+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* (C)2014 Ivan Andrew Pointer (ivan@pointerplace.us)
3+
* Date: 11/24/2014
4+
* License: Apache License 2 (https://github.com/ivanpointer/Scheduler/blob/master/LICENSE)
5+
* GitHub: https://github.com/ivanpointer/Scheduler
6+
*/
7+
8+
9+
using System.Linq;
10+
11+
namespace PointerPlace.Scheduler.Matchers
12+
{
13+
/// <summary>
14+
/// A matcher which is used to match day of week on a PointInTime. No incrementing is done
15+
/// for day of week, the incrementing is done through DayOfMonth.
16+
/// </summary>
17+
public class DayOfWeekMatcher : MatcherBase
18+
{
19+
20+
#region Members
21+
22+
private PointInTime Point { get; set; }
23+
24+
private bool Any { get; set;}
25+
private int[] ValidDaysOfWeek { get; set; }
26+
27+
#endregion
28+
29+
/// <summary>
30+
/// Constructs a DayOfWeekMatcher for the given PointInTime and Schedule
31+
/// </summary>
32+
/// <param name="point">The PointInTime for which to build this matcher</param>
33+
/// <param name="schedule">The Schedule for which to build this matcher</param>
34+
public DayOfWeekMatcher(PointInTime point, Schedule schedule)
35+
{
36+
Point = point;
37+
38+
ValidDaysOfWeek = GenerateSimpleList(schedule.DayOfWeek, 1, 7);
39+
40+
var length = ValidDaysOfWeek.Length;
41+
if (length == 7)
42+
{
43+
Any = true;
44+
}
45+
else if (length != 0)
46+
{
47+
Any = false;
48+
}
49+
else
50+
{
51+
throw new ImpossibleScheduleException("Schedule has no possible valid days of week");
52+
}
53+
}
54+
55+
// Determines whether the given PointInTime matches this matcher
56+
public override bool Matches(PointInTime point)
57+
{
58+
return Any || ValidDaysOfWeek.Contains(point.WeekDay);
59+
}
60+
61+
// Determins whether the point in time assigned to this matcher, matches this matcher
62+
public override bool Matches()
63+
{
64+
return Matches(Point);
65+
}
66+
67+
// Determines the next matching value for this matcher, starting from the PointInTime assigned to this matcher. If there
68+
// is no valid next value, -1 is returned.
69+
public override int NextMatch()
70+
{
71+
return NextMatch(ValidDaysOfWeek, Point.WeekDay);
72+
}
73+
74+
// Tries to increment the internal PointInTime to its next valid value, returns true if successfull, false otherwise.
75+
public override bool Increment()
76+
{
77+
return false;
78+
}
79+
80+
}
81+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* (C)2014 Ivan Andrew Pointer (ivan@pointerplace.us)
3+
* Date: 11/24/2014
4+
* License: Apache License 2 (https://github.com/ivanpointer/Scheduler/blob/master/LICENSE)
5+
* GitHub: https://github.com/ivanpointer/Scheduler
6+
*/
7+
8+
using System;
9+
using System.Linq;
10+
11+
namespace PointerPlace.Scheduler.Matchers
12+
{
13+
/// <summary>
14+
/// Matches and increments the hour field on a PointInTime
15+
/// </summary>
16+
public class HourMatcher : MatcherBase
17+
{
18+
19+
#region Members
20+
21+
private PointInTime Point { get; set; }
22+
23+
private bool Any { get; set; }
24+
private int[] ValidHours { get; set; }
25+
26+
#endregion
27+
28+
/// <summary>
29+
/// Constructs a HourMatcher for the given PointInTime and Schedule
30+
/// </summary>
31+
/// <param name="point">The PointInTime for which to build this matcher</param>
32+
/// <param name="schedule">The Schedule for which to build this matcher</param>
33+
public HourMatcher(PointInTime point, Schedule schedule)
34+
{
35+
Point = point;
36+
37+
ValidHours = GenerateSimpleList(schedule.Hour, 0, 24);
38+
39+
var length = ValidHours.Length;
40+
if (length == 24)
41+
{
42+
Any = true;
43+
}
44+
else if (length != 0)
45+
{
46+
Any = false;
47+
}
48+
else
49+
{
50+
throw new ImpossibleScheduleException("Schedule has no possible valid hours");
51+
}
52+
}
53+
54+
// Determines whether the given PointInTime matches this matcher
55+
public override bool Matches(PointInTime point)
56+
{
57+
return Any || ValidHours.Contains(point.Hour);
58+
}
59+
60+
// Determins whether the point in time assigned to this matcher, matches this matcher
61+
public override bool Matches()
62+
{
63+
return Matches(Point);
64+
}
65+
66+
// Determines the next matching value for this matcher, starting from the PointInTime assigned to this matcher. If there
67+
// is no valid next value, -1 is returned.
68+
public override int NextMatch()
69+
{
70+
return NextMatch(ValidHours, Point.Hour);
71+
}
72+
73+
// Tries to increment the internal PointInTime to its next valid value, returns true if successfull, false otherwise.
74+
public override bool Increment()
75+
{
76+
var nextMatch = NextMatch();
77+
if (nextMatch != -1)
78+
{
79+
Point.AdvanceHour(nextMatch);
80+
return true;
81+
}
82+
else
83+
{
84+
return false;
85+
}
86+
}
87+
88+
}
89+
}

0 commit comments

Comments
 (0)