Example #1
0
        private bool Execute(IXenConnection connection, bool prompt)
        {
            if (prompt)
            {
                return(PromptAndDisconnectServer(connection));
            }

            // no prompt. All tasks are cancelled and the server disconnected
            ConnectionsManager.CancelAllActions(connection);
            DoDisconnect(connection);
            return(true);
        }
Example #2
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 (!AllActionsFinished(connection, true))
            {
                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
                    {
                        DateTime startTime = DateTime.Now;
                        while ((DateTime.Now - startTime).TotalSeconds < 6.0)
                        {
                            if (AllActionsFinished(connection, false))
                            {
                                break;
                            }

                            Thread.Sleep(2000);
                        }
                    });

                    using (var pd = new ActionProgressDialog(waitForCancelAction, ProgressBarStyle.Marquee))
                    {
                        pd.ShowDialog(Parent);
                    }
                }
                else
                {
                    return(false);
                }
            }

            DoDisconnect(connection);
            return(true);
        }