Example #1
0
        private void UpdateScheduleOptions(ScheduleOptions options)
        {
            // Validate
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            // Ensure changing
            if (options == scheduleOptions)
            {
                return;
            }

            // Update variable first
            scheduleOptions = options;

            // If current scheduled, update the schedule
            if (scheduled)
            {
                if (asyncUpdateAction != null)
                {
                    scheduler.UpdateSchedule(asyncUpdateAction, options);
                }
                else
                {
                    scheduler.UpdateSchedule(updateAction, options);
                }
            }
        }
Example #2
0
        /// <inheritdoc/>
        public void Schedule(ScheduledAsyncAction subscriber, ScheduleOptions options)
        {
            // Check for existing subscription
            var sub = GetSubscription(subscriber, false);

            if (sub != null)
            {
                throw new InvalidOperationException(Strings.AlreadySubscribed);
            }

            // Make sure lookup exists
            if (asyncSubscriptions == null)
            {
                asyncSubscriptions = new Lookup <ScheduledAsyncAction>();
            }

            // Threadsafe
            lock (asyncSubscriptions)
            {
                // Add lookup
                asyncSubscriptions[subscriber] = new Subscription()
                {
                    Options = options
                };
            }

            // Ensure interval
            EnsureMinReportInterval(options.UpdateInterval);

            // Start?
            QueryStart();
        }
Example #3
0
        private void SetUpdateInterval(uint newInterval)
        {
            // Create new options
            var options = ScheduleOptions.WithNewUpdateInterval(newInterval);

            // Update
            UpdateScheduleOptions(options);
        }
 static public void Schedule(this IScheduler scheduler, Delegate subscriber, ScheduleOptions options)
 {
     ScheduledAsyncAction a;
     ScheduledAction s;
     GetSubscriber(subscriber, out a, out s);
     if (a != null)
     {
         scheduler.Schedule(a, options);
     }
     else
     {
         scheduler.Schedule(s, options);
     }
 }
        /// <summary>
        /// Initializes a new <see cref="ScheduledUpdater"/> instance.
        /// </summary>
        /// <param name="scheduleOptions">
        /// The options used for scheduling.
        /// </param>
        /// <param name="scheduler">
        /// The scheduler that will be used to schedule updates.
        /// </param>
        public ScheduledUpdater(ScheduleOptions scheduleOptions, IScheduler scheduler)
        {
            // Validate
            if (scheduleOptions == null) throw new ArgumentNullException("scheduleOptions");
            if (scheduler == null) throw new ArgumentNullException("scheduler");

            // Store
            this.scheduler = scheduler;
            this.scheduleOptions = scheduleOptions;
            this.defaultScheduleOptions = scheduleOptions;

            // Defaults
            StartWithEvents = true;
            StopWithEvents = true;
        }
        static public void Schedule(this IScheduler scheduler, Delegate subscriber, ScheduleOptions options)
        {
            ScheduledAsyncAction a;
            ScheduledAction      s;

            GetSubscriber(subscriber, out a, out s);
            if (a != null)
            {
                scheduler.Schedule(a, options);
            }
            else
            {
                scheduler.Schedule(s, options);
            }
        }
Example #7
0
 /// <inheritdoc/>
 public void UpdateSchedule(ScheduledAsyncAction subscriber, ScheduleOptions options)
 {
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     GetSubscription(subscriber).Options = options;
     if (reportInterval < options.UpdateInterval)
     {
         EnsureMinReportInterval(options.UpdateInterval);
     }
     else
     {
         RecalcReportInterval();
     }
 }
Example #8
0
        /// <summary>
        /// Initializes a new <see cref="ScheduledUpdater"/> instance.
        /// </summary>
        /// <param name="scheduleOptions">
        /// The options used for scheduling.
        /// </param>
        /// <param name="scheduler">
        /// The scheduler that will be used to schedule updates.
        /// </param>
        public ScheduledUpdater(ScheduleOptions scheduleOptions, IScheduler scheduler)
        {
            // Validate
            if (scheduleOptions == null)
            {
                throw new ArgumentNullException("scheduleOptions");
            }
            if (scheduler == null)
            {
                throw new ArgumentNullException("scheduler");
            }

            // Store
            this.scheduler              = scheduler;
            this.scheduleOptions        = scheduleOptions;
            this.defaultScheduleOptions = scheduleOptions;

            // Defaults
            StartWithEvents = true;
            StopWithEvents  = true;
        }
Example #9
0
 /// <summary>
 /// Initializes a new <see cref="ScheduledUpdater"/> using the default scheduler.
 /// </summary>
 /// <param name="scheduleOptions">
 /// The options used for scheduling.
 /// </param>
 public ScheduledUpdater(ScheduleOptions scheduleOptions) : this(scheduleOptions, IoTScheduler.Default)
 {
 }
        private void UpdateScheduleOptions(ScheduleOptions options)
        {
            // Validate
            if (options == null) throw new ArgumentNullException("options");

            // Ensure changing
            if (options == scheduleOptions) { return; }

            // Update variable first
            scheduleOptions = options;

            // If current scheduled, update the schedule
            if (scheduled)
            {
                if (asyncUpdateAction != null)
                {
                    scheduler.UpdateSchedule(asyncUpdateAction, options);
                }
                else
                {
                    scheduler.UpdateSchedule(updateAction, options);
                }
            }
        }
 /// <summary>
 /// Initializes a new <see cref="ScheduledUpdater"/> using the default scheduler.
 /// </summary>
 /// <param name="scheduleOptions">
 /// The options used for scheduling.
 /// </param>
 public ScheduledUpdater(ScheduleOptions scheduleOptions) : this(scheduleOptions, IoTScheduler.Default) { }