public void Schedule(ScheduledAsyncAction subscriber, ScheduleOptions options) { // Check for existing subscription var sub = GetSubscription(subscriber, false); if (sub != null) { throw new InvalidOperationException("Already subscribed"); } // Make sure lookup exists if (m_AsyncSubscriptions == null) { m_AsyncSubscriptions = new Lookup <ScheduledAsyncAction>(); } // Threadsafe lock (m_AsyncSubscriptions) { // Add lookup m_AsyncSubscriptions[subscriber] = new Subscription() { Options = options }; } // Ensure interval EnsureMinReportInterval(options.UpdateInterval); // Start? QueryStart(); }
public void Resume(ScheduledAsyncAction subscriber) { var s = GetSubscription(subscriber); s.IsSuspended = false; EnsureMinReportInterval(s.Options.UpdateInterval); }
static private void GetSubscriber(Delegate subscriber, out ScheduledAsyncAction a, out ScheduledAction s) { a = subscriber as ScheduledAsyncAction; s = subscriber as ScheduledAction; if ((a == null) && (s == null)) { throw new InvalidOperationException(Strings.InvalidSubscriberType); } }
public void SetUpdateAction(Action updtAction) { if (m_Scheduled) { throw new InvalidOperationException("An existing update action has already been scheduled and cannot be changed"); } // Store m_AsyncUpdateAction = null; m_UpdateAction = updtAction ?? throw new ArgumentNullException("updateAction"); }
public void UpdateSchedule(ScheduledAsyncAction subscriber, ScheduleOptions options) { GetSubscription(subscriber).Options = options ?? throw new ArgumentNullException("options"); if (m_ReportInterval < options.UpdateInterval) { EnsureMinReportInterval(options.UpdateInterval); } else { RecalcReportInterval(); } }
/// <summary> /// Sets a synchronous update action to be called by the scheduler. /// </summary> /// <param name="updateAction"> /// The synchronous update action. /// </param> public void SetUpdateAction(ScheduledAction updateAction) { // Validate if (updateAction == null) { throw new ArgumentNullException("updateAction"); } if (scheduled) { throw new InvalidOperationException(Strings.ExistingUpdateAction); } // Store this.asyncUpdateAction = null; this.updateAction = updateAction; }
public void Unschedule(ScheduledAsyncAction subscriber) { if (m_AsyncSubscriptions != null) { lock (m_AsyncSubscriptions) { m_AsyncSubscriptions.Remove(subscriber); // Unschedule } } // See if we should stop QueryStop(); // Recalcualte the report interval RecalcReportInterval(); }
private Subscription GetSubscription(ScheduledAsyncAction subscriber, bool throwIfMissing = true) { // Validate if (subscriber == null) { throw new ArgumentNullException("subscriber"); } // Try to get the subscription Subscription sub = null; if ((m_AsyncSubscriptions == null) || (!m_AsyncSubscriptions.TryGetValue(subscriber, out sub))) { if (throwIfMissing) { throw new InvalidOperationException("Subscription not found"); } } return(sub); }
public void Suspend(ScheduledAsyncAction subscriber) { GetSubscription(subscriber).IsSuspended = true; RecalcReportInterval(); }
/// <summary> /// Sets a synchronous update action to be called by the scheduler. /// </summary> /// <param name="updateAction"> /// The synchronous update action. /// </param> public void SetUpdateAction(ScheduledAction updateAction) { // Validate if (updateAction == null) throw new ArgumentNullException("updateAction"); if (scheduled) { throw new InvalidOperationException(Strings.ExistingUpdateAction); } // Store this.asyncUpdateAction = null; this.updateAction = updateAction; }