/// <summary> /// Sets a custom schedule for the task. This method only records the schedule, execution is done by ZPushSync. /// </summary> /// <param name="account">The specific account to set the schedule for, or null to set it for all accounts</param> /// <param name="schedule">The schedule. Specify null to clear the schedule and resume the original.</param> public void SetTaskSchedule(ZPushAccount account, Schedule schedule) { if (account == null) { _scheduleAll = schedule; } else { if (schedule == null) { _schedulesAccount.Remove(account); } else { _schedulesAccount[account] = schedule; } } }
/// <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); }
/// <summary> /// Handles a new account. /// </summary> /// <param name="account">The account.</param> internal void OnAccountDiscovered(ZPushAccount account) { // Notify any account listeners AccountDiscovered?.Invoke(account); // Register any events HandleFolderWatchers(account); if (account.Account.HasPassword) { // Send an OOF request to get the OOF state and capabilities Tasks.Task(null, null, "ZPushCheck: " + account.DisplayName, () => { // TODO: if this fails, retry? ActiveSync.SettingsOOF oof; using (ZPushConnection connection = new ZPushConnection(account, new System.Threading.CancellationToken(false))) { oof = connection.Execute(new ActiveSync.SettingsOOFGet()); } account.OnConfirmationResponse(oof.RawResponse); // [ZO-109] Always update the current selection, it might have changed. Explorer_SelectionChange(); // Notify the OOF feature. // TODO: this coupling is pretty hideous ThisAddIn.Instance.GetFeature <FeatureOutOfOffice>()?.OnOOFSettings(account, oof); }); } else { ThisAddIn.Instance.InvokeUI(() => { Logger.Instance.Warning(this, "Password not available for account: {0}", account); System.Windows.Forms.MessageBox.Show(ThisAddIn.Instance.Window, string.Format(Properties.Resources.AccountNoPassword_Body, account.DisplayName), Properties.Resources.AccountNoPassword_Title, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Information ); }); } }
/// <summary> /// Returns the task for execution. /// </summary> /// <param name="schedule">The schedule that triggered the task execution, or null if this is a sync.</param> /// <param name="account">The account for which the tasks are requested.</param> /// <returns>The task instance, or null if there is no task to execute in this schedule.</returns> public AcaciaTask GetInstance(Schedule schedule, ZPushAccount account) { if (!IsTaskScheduleApplicable(schedule, account)) { return(null); } if (_actionConnection != null) { return(new AcaciaTask(null, _owner, _name, () => { // TODO: reuse connections using (ZPushConnection con = account.Connect()) { _actionConnection(con); } })); } else { return(new AcaciaTask(null, _owner, _name, () => _action(account))); } }
/// <summary> /// Invoked when a new ZPush account is discovered, runs tasks for that account. /// This is also invoked at start-up, so triggers initial sync. /// </summary> private void Watcher_AccountDiscovered(ZPushAccount account) { ExecuteTasks(account); }
private void HandleFolderWatchers(ZPushAccount account) { // We need to keep the object alive to keep receiving events _rootFolder = new ZPushFolder(this, account.Account.Store.GetRootFolder()); }
public ZPushChannel Get(Feature feature, ZPushAccount account, string name) { ZPushChannel channel = new ZPushChannel(_watcher, account, feature, name); return(channel); }