コード例 #1
0
        /// <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
                                                         );
                });
            }
        }
コード例 #2
0
        private void _buttons_Apply(object sender, EventArgs e)
        {
            BusyText = Properties.Resources.OOFSet_Label;
            ActiveSync.SettingsOOF currentSettings = GetSettings();
            KUITask
            .New((ctx) =>
            {
                using (ZPushConnection connection = new ZPushConnection(_account, ctx.CancellationToken))
                {
                    // Set the OOF state. This always seems to return ok, so we fetch the settings
                    // again, to see what happend
                    connection.Execute(new ActiveSync.SettingsOOFSet(currentSettings));

                    // Fetch the OOF state
                    return(connection.Execute(new ActiveSync.SettingsOOFGet()));
                }
            })
            .OnSuccess((appliedSettings) =>
            {
                // Store them for later use
                _feature.StoreOOFSettings(_account, appliedSettings);

                // Check what happened
                string message;
                MessageBoxIcon messageIcon;
                if (currentSettings.State == ActiveSync.OOFState.Disabled)
                {
                    // Tried to disable.
                    if (appliedSettings.State != ActiveSync.OOFState.Disabled)
                    {
                        // It's an error if its not actually disabled
                        message     = Properties.Resources.OOFSet_DisableFailed;
                        messageIcon = MessageBoxIcon.Error;
                    }
                    else
                    {
                        // All good
                        message     = Properties.Resources.OOFSet_Disabled;
                        messageIcon = MessageBoxIcon.Information;
                    }
                }
                else if (appliedSettings.State == ActiveSync.OOFState.Disabled)
                {
                    // It's an error if the state is set to disabled when we tried to enable
                    message     = Properties.Resources.OOFSet_EnableFailed;
                    messageIcon = MessageBoxIcon.Error;
                }
                else
                {
                    // All good
                    if (appliedSettings.State == ActiveSync.OOFState.EnabledTimeBased)
                    {
                        message = string.Format(Properties.Resources.OOFSet_EnabledTimeBased,
                                                appliedSettings.From, appliedSettings.Till);
                    }
                    else
                    {
                        message = Properties.Resources.OOFSet_Enabled;
                    }
                    messageIcon = MessageBoxIcon.Information;

                    // It's okay if the state is not the same, but it deserves a message
                    if (appliedSettings.State != currentSettings.State)
                    {
                        message     = Properties.Resources.OOFSet_DifferentState + message;
                        messageIcon = MessageBoxIcon.Warning;
                    }
                }

                Logger.Instance.Debug(this, "OOF state updated: {0}, {1}", message, messageIcon);
                MessageBox.Show(message,
                                Properties.Resources.OOFSet_Title,
                                MessageBoxButtons.OK,
                                messageIcon
                                );

                if (messageIcon == MessageBoxIcon.Information)
                {
                    // All good, close the dialog
                    _buttons.IsDirty = false;
                    DialogResult     = DialogResult.OK;
                }
                else
                {
                    // There was a problem, initialise the dialog to what's set.
                    _settings = appliedSettings;
                    InitSettings();
                    CheckDirty();
                }
            }, true)
            .OnError((x) =>
            {
                ErrorUtil.HandleErrorNew(this, "Exception in OOFSet", x,
                                         Properties.Resources.OOFSet_Title, Properties.Resources.OOFSet_Failed);
            })
            .Start(this)
            ;
        }