Esempio n. 1
0
        /// <summary>
        /// First prompts the user if there are any actions running, then cancels and d/c if they give the OK.
        /// </summary>
        /// <param name="connection"></param>
        /// <returns>True if the user agreed to d/c and cancel their tasks, false if we are going to remain connected</returns>
        private bool PromptAndDisconnectServer(IXenConnection connection)
        {
            if (!AsyncAction.AllActionsFinishedOrCanceling(connection, ConnectionsManager.History))
            {
                if (MainWindowCommandInterface.RunInAutomatedTestMode || new CloseXenCenterWarningDialog(connection).ShowDialog(Parent) == DialogResult.OK)
                {
                    ConnectionsManager.CancelAllActions(connection);

                    DelegatedAsyncAction WaitForCancelAction = new DelegatedAsyncAction(connection, Messages.CANCELING_TASKS, Messages.CANCELING, Messages.COMPLETED,
                                                                                        delegate(Session s)
                    {
                        DateTime startTime = DateTime.Now;
                        while (((TimeSpan)(DateTime.Now - startTime)).TotalSeconds < 6.0)
                        {
                            if (ConnectionsManager.AllActionsFinished(connection))
                            {
                                break;
                            }
                            else
                            {
                                Thread.Sleep(2000);
                            }
                        }
                    });
                    ActionProgressDialog pd = new ActionProgressDialog(WaitForCancelAction, ProgressBarStyle.Marquee);
                    pd.ShowDialog(Parent);
                }
                else
                {
                    return(false);
                }
            }
            DoDisconnect(connection);

            return(true);
        }