コード例 #1
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)
     ;
 }
コード例 #2
0
        private void AddSharedFolderDialog_Shown(object sender, EventArgs args)
        {
            BusyText = Properties.Resources.SharedFolders_Fetching_Label;
            KUITask
            .New((ctx) =>
            {
                // TODO: bind cancellation token to Cancel button
                // Fetch current shares
                ICollection <SharedFolder> folders = _folders.GetCurrentShares(ctx.CancellationToken);

                // Find the initial folder if required
                if (_initialSyncId != null)
                {
                    _initialFolder = folders.FirstOrDefault(f => f.SyncId == _initialSyncId);
                }

                // Group by store and folder id
                return(folders.GroupBy(f => f.Store)
                       .ToDictionary(group => group.Key,
                                     group => group.ToDictionary(folder => folder.BackendId)));
            })
            .OnSuccess(InitialiseTree, true)
            .OnError((e) =>
            {
                UI.ErrorUtil.HandleErrorNew(typeof(FeatureSharedFolders), "Exception fetching shared folders for account {0}", e,
                                            Properties.Resources.SharedFolders_Fetching_Title,
                                            Properties.Resources.SharedFolders_Fetching_Failure,
                                            _account.DisplayName);
                DialogResult = DialogResult.Cancel;
            })
            .Start(this)
            ;
        }
コード例 #3
0
        private void dialogButtons_Apply(object sender, EventArgs e)
        {
            BusyText = Properties.Resources.SharedFolders_Applying_Label;
            KUITask.New((ctx) =>
            {
                // We reuse the same busy indicationg for all calls. A count is kept to ensure it's removed.
                int count = 0;

                foreach (StoreTreeNode storeNode in _userFolders.Values)
                {
                    if (storeNode.IsDirty)
                    {
                        ctx.AddBusy(1);
                        ++count;

                        _folders.SetSharesForStore(storeNode.User, storeNode.CurrentShares, ctx.CancellationToken);
                    }
                }

                return(count);
            })
            .OnSuccess((ctx, count) =>
            {
                // Update UI state
                foreach (StoreTreeNode storeNode in _userFolders.Values)
                {
                    if (storeNode.IsDirty)
                    {
                        storeNode.ChangesApplied();
                    }
                }

                ctx.AddBusy(-count);

                // Sync account
                _account.Account.SendReceive();

                // Show success
                ShowCompletion(Properties.Resources.SharedFolders_Applying_Success);
            }, true)
            .OnError((x) =>
            {
                ErrorUtil.HandleErrorNew(typeof(FeatureSharedFolders), "Exception applying shared folders for account {0}", x,
                                         Properties.Resources.SharedFolders_Applying_Title,
                                         Properties.Resources.SharedFolders_Applying_Failure,
                                         _account.DisplayName);
            })
            .Start(this);
        }
コード例 #4
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)
            ;
        }
コード例 #5
0
        private void dialogButtons_Apply(object sender, EventArgs e)
        {
            int folderCount = 0;

            // Check if all fields are properly set
            foreach (StoreTreeNode storeNode in _userFolders.Values)
            {
                // Check totals
                folderCount += storeNode.CurrentShares.Count();

                // Check modified folders
                if (storeNode.IsDirty)
                {
                    foreach (SharedFolder folder in storeNode.CurrentShares)
                    {
                        // Check if the send-as address has been resolved (or entered) correctly
                        if (folder.FlagSendAsOwner && string.IsNullOrWhiteSpace(folder.SendAsAddress))
                        {
                            // Find the tree node
                            KTreeNode folderNode = storeNode.FindNode(folder);
                            if (folderNode != null)
                            {
                                // See if we can obtain it from a parent
                                TryInitSendAsAddressParent(folderNode as FolderTreeNode);
                                if (!string.IsNullOrWhiteSpace(folder.SendAsAddress))
                                {
                                    continue;
                                }

                                // If the node is already selected, explicitly warn about the send-as address
                                // Otherwise, selecting it will pop up the warning
                                if (folderNode.IsSelected)
                                {
                                    TryInitSendAsAddress();
                                }
                                else
                                {
                                    FocusNode(folderNode, false);
                                }
                            }
                            return;
                        }
                    }
                }
            }

            // Check total number of folders
            if (folderCount >= _feature.MaxFolderCount)
            {
                MessageBox.Show(ThisAddIn.Instance.Window,
                                Properties.Resources.SharedFolders_TooManyFolders_Body,
                                Properties.Resources.SharedFolders_TooManyFolders_Title,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error
                                );
                // And don't apply anything
                return;
            }

            BusyText = Properties.Resources.SharedFolders_Applying_Label;
            KUITask.New((ctx) =>
            {
                // We reuse the same busy indicationg for all calls. A count is kept to ensure it's removed.
                ApplyState state = new ApplyState();

                foreach (StoreTreeNode storeNode in _userFolders.Values)
                {
                    // Check modified folders
                    if (storeNode.IsDirty)
                    {
                        ctx.AddBusy(1);
                        ++state.folders;

                        // Check removed shares
                        _folders.RemoveSharesForStore(storeNode.User, storeNode.RemovedShares);

                        // Set shares
                        _folders.SetSharesForStore(storeNode.User, storeNode.CurrentShares, ctx.CancellationToken);
                    }

                    // And modified stores
                    if (storeNode.IsWholeStoreDirty)
                    {
                        state.stores.Add(storeNode);
                    }
                }

                return(state);
            })
            .OnSuccess((ctx, state) =>
            {
                // Update UI state
                foreach (StoreTreeNode storeNode in _userFolders.Values)
                {
                    if (storeNode.IsDirty)
                    {
                        storeNode.ChangesApplied();
                    }
                }

                ctx.AddBusy(-state.folders);

                List <ZPushAccount> syncAdditional = new List <ZPushAccount>();

                // Handle stores
                if (state.stores.Count > 0)
                {
                    List <StoreTreeNode> add = new List <StoreTreeNode>();

                    // Remove any unshared store
                    foreach (StoreTreeNode store in state.stores)
                    {
                        if (store.WantShare)
                        {
                            // Check if it must be added
                            if (!store.IsShared)
                            {
                                add.Add(store);
                            }

                            // Update reminders for existing stores
                            if (store.ShowReminders != store.ShowRemindersInitial)
                            {
                                ZPushAccount storeAccount = store.WholeStoreAccount;
                                if (storeAccount != null)
                                {
                                    storeAccount.ShowReminders = store.ShowReminders;
                                    syncAdditional.Add(storeAccount);
                                    // Update UI state
                                    store.ShowRemindersInitial = store.ShowReminders;
                                    WholeStoreShareChanged(store);
                                }
                            }
                            continue;
                        }
                        else
                        {
                            // Remove it
                            _feature.RemoveSharedStore(_account, store.User);
                            store.IsShared = false;
                            WholeStoreShareChanged(store);
                        }
                    }

                    // Check for any new stores
                    if (add.Count > 0)
                    {
                        bool restart = MessageBox.Show(ThisAddIn.Instance.Window,
                                                       Properties.Resources.SharedFolders_WholeStoreRestart_Body,
                                                       Properties.Resources.SharedFolders_WholeStoreRestart_Title,
                                                       MessageBoxButtons.OKCancel,
                                                       MessageBoxIcon.Information
                                                       ) == DialogResult.OK;

                        // Reset state. Also do this when restarting, to avoid warning message about unsaved changes
                        foreach (StoreTreeNode node in state.stores)
                        {
                            node.WantShare = node.IsShared;
                        }

                        if (!restart)
                        {
                            return;
                        }

                        // Restart
                        IRestarter restarter   = ThisAddIn.Instance.Restarter();
                        restarter.CloseWindows = true;
                        foreach (StoreTreeNode node in state.stores)
                        {
                            restarter.OpenShare(_account, node.User, node.ShowReminders);
                        }
                        restarter.Restart();
                    }

                    // Update UI state
                    foreach (StoreTreeNode storeNode in _userFolders.Values)
                    {
                        storeNode.ChangesApplied();
                    }
                    CheckDirty();
                }

                // Sync accounts
                foreach (ZPushAccount account in syncAdditional)
                {
                    _feature.Sync(account);
                }

                if (state.folders != 0)
                {
                    // Sync account
                    _feature.Sync(_account);

                    // Show success
                    ShowCompletion(Properties.Resources.SharedFolders_Applying_Success);
                }
            }, true)
            .OnError((x) =>
            {
                ErrorUtil.HandleErrorNew(typeof(FeatureSharedFolders), "Exception applying shared folders for account {0}", x,
                                         Properties.Resources.SharedFolders_Applying_Title,
                                         Properties.Resources.SharedFolders_Applying_Failure,
                                         _account.DisplayName);
            })
            .Start(this);
        }