18 using System.Collections.Generic;
34 private readonly
object _eventScheduleLock =
new object();
35 private readonly List<ScheduledEvent> _preInitializedEvents;
55 _securities = securities;
60 _preInitializedEvents =
new List<ScheduledEvent>();
69 if (eventSchedule ==
null)
71 throw new ArgumentNullException(nameof(eventSchedule));
74 lock (_eventScheduleLock)
76 _eventSchedule = eventSchedule;
79 foreach (var scheduledEvent
in _preInitializedEvents)
81 _eventSchedule.
Add(scheduledEvent);
92 lock (_eventScheduleLock)
94 if (_eventSchedule !=
null)
96 _eventSchedule.
Add(scheduledEvent);
100 _preInitializedEvents.Add(scheduledEvent);
111 lock (_eventScheduleLock)
113 if (_eventSchedule !=
null)
115 _eventSchedule.
Remove(scheduledEvent);
119 _preInitializedEvents.RemoveAll(se => Equals(se, scheduledEvent));
132 return On(dateRule, timeRule, (name, time) => callback());
143 return On(dateRule, timeRule, (name, time) => {
using (Py.GIL()) callback.Invoke(); });
154 var name = $
"{dateRule.Name}: {timeRule.Name}";
155 return On(name, dateRule, timeRule, callback);
167 return On(name, dateRule, timeRule, (n, d) => callback());
179 return On(name, dateRule, timeRule, (n, d) => {
using (Py.GIL()) callback.Invoke(); });
192 var dates = GetDatesDeferred(dateRule, _securities);
194 var scheduledEvent =
new ScheduledEvent(name, eventTimes, callback);
197 Log.
Trace($
"Event Name \"{scheduledEvent.Name}\", scheduled to run.");
198 return scheduledEvent;
201 #region Fluent Scheduling
221 #region Training Events
247 var name = $
"{dateRule.Name}: {timeRule.Name}";
248 return On(name, dateRule, timeRule, (n, time) => trainingCode());
260 var name = $
"{dateRule.Name}: {timeRule.Name}";
261 return On(name, dateRule, timeRule, (n, time) => {
using (Py.GIL()) trainingCode.Invoke(); });
272 var name = $
"{dateRule.Name}: {timeRule.Name}";
273 return On(name, dateRule, timeRule, (n, time) => trainingCode(time));
284 foreach (var item
in dateRule.
GetDates(DateTime.SpecifyKind(securities.
UtcTime.Date.AddDays(-1), DateTimeKind.Unspecified),
Time.
EndOfTime))