Exemple #1
0
 public Schedule(SyncTaskImpl task, ZPushAccount account, TickHandler scheduleTick, TimeSpan period)
 {
     this.Task    = task;
     this.Account = account;
     this._tick   = scheduleTick;
     this._period = period;
 }
Exemple #2
0
        /// <summary>
        /// Adds a synchronisation task.
        /// </summary>
        /// <param name="owner">The feature owning the task.</param>
        /// <param name="name">The task's name, for logging.</param>
        /// <param name="action">The action to execute.</param>
        public SyncTask AddTask(Feature owner, string name, SyncAction action)
        {
            if (_started)
            {
                throw new Exception("Already started, cannot add task");
            }
            SyncTaskImpl task = new SyncTaskImpl(owner, name, action, null);

            _tasks.Add(task);
            return(task);
        }
Exemple #3
0
        /// <summary>
        /// Sets a custom schedule for the specified task.
        /// </summary>
        /// <param name="task">The task</param>
        /// <param name="account">The specific account to set the schedule for, or null to set it for all accounts.
        /// If a per-account schedule is set, and an all-account schedule, the quickest of both applies.</param>
        /// <param name="period">The schedule. Specify null to clear the schedule and resume the original.</param>
        /// <returns>The old schedule, or null if there was none.</returns>
        public TimeSpan?SetTaskSchedule(SyncTask task, ZPushAccount account, TimeSpan?period, bool executeNow = false)
        {
            SyncTaskImpl impl = (SyncTaskImpl)task;

            Logger.Instance.Trace(this, "Setting task schedule for {0}{1} to {2}",
                                  impl.ToString(),
                                  account == null ? "" : (" for account " + account),
                                  period == null ? "default" : period.Value.ToString());

            // Check if there's an existing schedule to modify
            Schedule schedule = impl.GetTaskSchedule(account);
            TimeSpan?old      = schedule?.Period;

            if (period == null)
            {
                // Clearing the schedule
                if (schedule != null)
                {
                    // Clear the existing schedule
                    schedule.Cancel();
                    impl.SetTaskSchedule(account, null);
                }
                // If there was no schedule, we're already done
            }
            else
            {
                // Setting the schedule
                if (schedule == null)
                {
                    // Create a new schedule
                    schedule = new Schedule(impl, account, ScheduleTick, period.Value);
                    impl.SetTaskSchedule(account, schedule);
                    schedule.Start(executeNow);
                }
                else
                {
                    // Update the existing schedule
                    schedule.SetPeriod(period.Value, executeNow);
                }
            }

            return(old);
        }