コード例 #1
0
        public OutOfOfficeDialog(FeatureOutOfOffice feature, ZPushAccount account, ActiveSync.SettingsOOF settings)
        {
            this._feature  = feature;
            this._account  = account;
            this._settings = settings;

            InitializeComponent();

            // Add the email address to the title
            Text = string.Format(Text, account.Account.SmtpAddress);

            // Set the time formats
            timeFrom.CustomFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;
            timeTill.CustomFormat = CultureInfo.CurrentCulture.DateTimeFormat.ShortTimePattern;

            // Patch the position of the until label, to align
            // with the from text
            using (Graphics graphics = radioTime.CreateGraphics())
            {
                Size    size    = RadioButtonRenderer.GetGlyphSize(graphics, System.Windows.Forms.VisualStyles.RadioButtonState.CheckedNormal);
                Padding padding = labelTill.Margin;
                padding.Left     = radioTime.Margin.Left + size.Width + 2;
                labelTill.Margin = padding;
            }

            // Enable controls
            chkEnable_CheckedChanged(chkEnable, null);
            radioTime_CheckedChanged(radioTime, null);
        }
コード例 #2
0
 private void LoadSettings()
 {
     BusyText = Properties.Resources.OOFGet_Label;
     KUITask
     .New((ctx) =>
     {
         using (ZPushConnection con = new ZPushConnection(_account, ctx.CancellationToken))
         {
             _settings = con.Execute(new ActiveSync.SettingsOOFGet());
         }
     })
     .OnSuccess(InitSettings, true)
     .OnError((e) =>
     {
         Logger.Instance.Warning(this, "Exception getting OOF state: {0}", e);
         if (MessageBox.Show(
                 Properties.Resources.OOFGet_Failed,
                 Properties.Resources.OOFGet_Title,
                 MessageBoxButtons.OKCancel,
                 MessageBoxIcon.Error
                 ) != DialogResult.OK)
         {
             DialogResult = DialogResult.Cancel;
         }
         else
         {
             // Initialise default settings
             _settings = new ActiveSync.SettingsOOF(true);
             InitSettings();
         }
     })
     .Start(this)
     ;
 }
コード例 #3
0
        /// <summary>
        /// Shows the OOF dialog.
        /// </summary>
        /// <param name="account">The account.</param>
        /// <param name="settings">The setttings, or null, in which case the settings will be retrieved</param>
        private void ShowOOFDialog(ZPushAccount account, ActiveSync.SettingsOOF settings)
        {
            // Show dialog
            OutOfOfficeDialog dialog = new OutOfOfficeDialog(this, account, settings);

            dialog.ShowDialog();
        }
コード例 #4
0
        private ActiveSync.SettingsOOF GetSettings()
        {
            ActiveSync.SettingsOOF settings = new ActiveSync.SettingsOOF(true);

            if (chkEnable.Checked)
            {
                if (radioNoTime.Checked || !_haveTimes)
                {
                    settings.State = ActiveSync.OOFState.Enabled;
                }
                else
                {
                    settings.State = ActiveSync.OOFState.EnabledTimeBased;
                    settings.From  = GetDateTime(dateFrom, timeFrom);
                    settings.Till  = GetDateTime(dateTill, timeTill);
                }
            }
            else
            {
                settings.State = ActiveSync.OOFState.Disabled;
            }

            // Always set the message, so it's stored
            string message = textBody.Text;

            for (int i = 0; i < 3; ++i)
            {
                settings.Message[i]         = new ActiveSync.OOFMessage();
                settings.Message[i].Message = message;
            }

            return(settings);
        }
コード例 #5
0
 internal void StoreOOFSettings(ZPushAccount account, ActiveSync.SettingsOOF settings)
 {
     account.SetFeatureData(this, "OOF", settings);
     if (_button != null)
     {
         _button.IsPressed = IsOOFEnabled(settings);
     }
 }
コード例 #6
0
 private void Periodic_Sync(ZPushConnection connection)
 {
     try
     {
         // TODO: merge this into ZPushAccount, allow periodic rechecking of Z-Push confirmation. That was other
         //       features can be updated too, e.g. OOF status. That's pretty easy to do, only need to check if
         //       no other features will break if the ConfirmedChanged event is raised multiple times
         ActiveSync.SettingsOOF oof = connection.Execute(new ActiveSync.SettingsOOFGet());
         SyncSignatures(connection.Account, oof.RawResponse.SignaturesHash);
     }
     catch (System.Exception e)
     {
         Logger.Instance.Error(this, "Error fetching signature hash: {0}", e);
     }
 }
コード例 #7
0
        /// <summary>
        /// Invoked by AccountWatcher on start-up to notify of the oof status.
        /// </summary>
        public void OnOOFSettings(ZPushAccount account, ActiveSync.SettingsOOF oof)
        {
            // Store them for later use
            StoreOOFSettings(account, oof);

            // Show a message if OOF is enabled
            if (IsOOFEnabled(oof))
            {
                if (MessageBox.Show(
                        string.Format(Properties.Resources.OOFStartup_Message, account.Account.SmtpAddress),
                        Properties.Resources.OOFStartup_Title,
                        MessageBoxButtons.YesNo,
                        MessageBoxIcon.Question
                        ) == DialogResult.Yes)
                {
                    ShowOOFDialog(account, oof);
                }
            }
        }
コード例 #8
0
        internal ActiveSync.OOFState GetEffectiveState(ActiveSync.SettingsOOF settings)
        {
            if (settings == null)
            {
                return(ActiveSync.OOFState.Disabled);
            }

            if (settings.State == ActiveSync.OOFState.Disabled)
            {
                return(ActiveSync.OOFState.Disabled);
            }

            // If there's a time-based OOF, and it has expired, OOF if effectively disabled
            if (settings.State == ActiveSync.OOFState.EnabledTimeBased && IgnoreExpired)
            {
                if (settings.Till != null && settings.Till.Value.CompareTo(DateTime.Now) < 0)
                {
                    return(ActiveSync.OOFState.Disabled);
                }
            }

            return(settings.State);
        }
コード例 #9
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)
            ;
        }
コード例 #10
0
 private void CheckDirty()
 {
     ActiveSync.SettingsOOF settings = GetSettings();
     _buttons.IsDirty = _settings != null && !_settings.Equals(settings);
 }
コード例 #11
0
 internal bool IsOOFEnabled(ActiveSync.SettingsOOF settings)
 {
     return(GetEffectiveState(settings) != ActiveSync.OOFState.Disabled);
 }