Esempio n. 1
0
 public void NextEventTimeIsMaxValueWhenNoMoreEvents()
 {
     var time = new DateTime(2015, 08, 11, 10, 30, 0);
     var sevent = new ScheduledEvent("test", time, (n, t) => { });
     sevent.Scan(time);
     Assert.AreEqual(DateTime.MaxValue, sevent.NextEventUtcTime);
 }
Esempio n. 2
0
 public void FiresSkippedEventsInSameCallToScan()
 {
     int count = 0;
     var time = new DateTime(2015, 08, 11, 10, 30, 0);
     var sevent = new ScheduledEvent("test", new[] { time.AddSeconds(-2), time.AddSeconds(-1), time}, (n, t) => count++);
     sevent.Scan(time);
     Assert.AreEqual(3, count);
 }
Esempio n. 3
0
 public void FiresEventOnTime()
 {
     var fired = false;
     var time = new DateTime(2015, 08, 11, 10, 30, 0);
     var sevent = new ScheduledEvent("test", time, (n, t) => fired = true);
     sevent.Scan(time);
     Assert.IsTrue(fired);
 }
Esempio n. 4
0
 public void SkipsEventsUntilTime()
 {
     int count = 0;
     var time = new DateTime(2015, 08, 11, 10, 30, 0);
     var sevent = new ScheduledEvent("test", new[] { time.AddSeconds(-2), time.AddSeconds(-1), time }, (n, t) => count++);
     // skips all preceding events, not including the specified time
     sevent.SkipEventsUntil(time);
     Assert.AreEqual(time, sevent.NextEventUtcTime);
 }
Esempio n. 5
0
        public void FiresEventWhenTimePasses()
        {
            var triggered = false;
            var se = new ScheduledEvent("test", new DateTime(2015, 08, 07), (name, triggerTime) =>
            {
                triggered = true;
            });
            se.IsLoggingEnabled = true;

            se.Scan(new DateTime(2015, 08, 06));
            Assert.IsFalse(triggered);

            se.Scan(new DateTime(2015, 08, 08));
            Assert.IsTrue(triggered);
        }
Esempio n. 6
0
        public void SchedulesNextEvent()
        {
            var first = new DateTime(2015, 08, 07);
            var second = new DateTime(2015, 08, 08);
            var dates = new[] { first, second }.ToHashSet();
            var se = new ScheduledEvent("test", dates.ToList(), (name, triggerTime) =>
            {
                dates.Remove(triggerTime);
            });

            se.Scan(first);
            Assert.IsFalse(dates.Contains(first));

            se.Scan(second);
            Assert.IsFalse(dates.Contains(second));
        }
Esempio n. 7
0
 /// <summary>
 /// Schedules the callback to run using the specified date and time rules
 /// </summary>
 /// <param name="name">The event's unique name</param>
 /// <param name="dateRule">Specifies what dates the event should run</param>
 /// <param name="timeRule">Specifies the times on those dates the event should run</param>
 /// <param name="callback">The callback to be invoked</param>
 public void On(string name, IDateRule dateRule, ITimeRule timeRule, Action callback)
 {
     var dates = dateRule.GetDates(_securities.UtcTime, Time.EndOfTime);
     var eventTimes = timeRule.CreateUtcEventTimes(dates);
     var scheduledEvent = new ScheduledEvent(name, eventTimes, (s, time) => callback());
     _eventSchedule.Add(scheduledEvent);
 }
Esempio n. 8
0
 /// <summary>
 /// Adds the specified event to the schedule using the <see cref="ScheduledEvent.Name"/> as a key.
 /// </summary>
 /// <param name="scheduledEvent">The event to be scheduled, including the date/times the event fires and the callback</param>
 public void Add(ScheduledEvent scheduledEvent)
 {
     _eventSchedule.Add(scheduledEvent);
 }
 /// <summary>
 /// Register the defined event with the callback
 /// </summary>
 ScheduledEvent IFluentSchedulingRunnable.Run(Action<string, DateTime> callback)
 {
     var name = _name ?? _dateRule.Name + ": " + _timeRule.Name;
     // back the date up to ensure we get all events, the event scheduler will skip past events that whose time has passed
     var dates = _dateRule.GetDates(_securities.UtcTime.Date.AddDays(-1), Time.EndOfTime);
     var eventTimes = _timeRule.CreateUtcEventTimes(dates);
     if (_predicate != null)
     {
         eventTimes = eventTimes.Where(_predicate);
     }
     var scheduledEvent = new ScheduledEvent(name, eventTimes, callback);
     _schedule.Add(scheduledEvent);
     return scheduledEvent;
 }
Esempio n. 10
0
 /// <summary>
 /// Adds the specified event to the schedule using the <see cref="ScheduledEvent.Name"/> as a key.
 /// </summary>
 /// <param name="scheduledEvent">The event to be scheduled, including the date/times the event fires and the callback</param>
 public void Add(ScheduledEvent scheduledEvent)
 {
     lock (_eventScheduleLock)
     {
         if (_eventSchedule != null)
         {
             _eventSchedule.Add(scheduledEvent);
         }
         else
         {
             _preInitializedEvents.Add(scheduledEvent);
         }
     }
 }
Esempio n. 11
0
 /// <summary>
 /// Schedules the callback to run using the specified date and time rules
 /// </summary>
 /// <param name="name">The event's unique name</param>
 /// <param name="dateRule">Specifies what dates the event should run</param>
 /// <param name="timeRule">Specifies the times on those dates the event should run</param>
 /// <param name="callback">The callback to be invoked</param>
 public ScheduledEvent On(string name, IDateRule dateRule, ITimeRule timeRule, Action<string, DateTime> callback)
 {
     // back the date up to ensure we get all events, the event scheduler will skip past events that whose time has passed
     var dates = dateRule.GetDates(_securities.UtcTime.Date.AddDays(-1), Time.EndOfTime);
     var eventTimes = timeRule.CreateUtcEventTimes(dates);
     var scheduledEvent = new ScheduledEvent(name, eventTimes, callback);
     Add(scheduledEvent);
     return scheduledEvent;
 }
Esempio n. 12
0
        public void DoesNothingAfterEventsEnd()
        {
            var triggered = false;
            var first = new DateTime(2015, 08, 07);
            var se = new ScheduledEvent("test", first, (name, triggerTime) =>
            {
                triggered = true;
            });

            se.Scan(first);
            Assert.IsTrue(triggered);

            triggered = false;
            se.Scan(first.AddYears(100));
            Assert.IsFalse(triggered);
        }
Esempio n. 13
0
 public void NextEventTimeIsMaxValueWhenNoEvents()
 {
     var sevent = new ScheduledEvent("test", new DateTime[0], (n, t) => { });
     Assert.AreEqual(DateTime.MaxValue, sevent.NextEventUtcTime);
 }