Exemple #1
0
        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();
        }
Exemple #2
0
        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);
            }
        }
        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);
            }
        }
Exemple #5
0
        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");
        }
Exemple #6
0
 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;
        }
Exemple #8
0
        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();
        }
Exemple #9
0
        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);
        }
Exemple #10
0
 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;
        }