Beispiel #1
0
        private void releaseSession_ToolStripButton_Click(object sender, EventArgs e)
        {
            _selectedSessionCell = SelectedSession;
            var sessionId = _selectedSessionCell.Value.ToString();

            if (!GlobalSettings.IsDistributedSystem)
            {
                if (sessionData_GridView.SelectedRows[0].Cells[12].Value.ToString() != Environment.MachineName.ToUpper())
                {
                    var message = MessageBox.Show($"You are trying to release a session which was run on client machine -' { sessionData_GridView.SelectedRows[0].Cells[12].Value} ' . This will not close the Virtual worker console on that client.  Do you want to continue?", "Release Session", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (message == System.Windows.Forms.DialogResult.No)
                    {
                        return;
                    }
                }
            }

            string msg    = "This will abort the session (if it is currently running) and release all machines and other assets used in this test.  Are you sure you want to release this Session?";
            var    result = MessageBox.Show(msg, "Reset Session", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (result == System.Windows.Forms.DialogResult.No)
            {
                return;
            }

            if (!string.IsNullOrEmpty(sessionId))
            {
                _sessionResetting = sessionId;

                if (STFDispatcherManager.Dispatcher == null && STFDispatcherManager.ConnectToDispatcher() == false)
                {
                    //The user canceled the connect dialog
                    return;
                }

                // For STE, require that shutdown requester be authorized
                SessionResetManager resetManager = new SessionResetManager();
                if (GlobalSettings.IsDistributedSystem)
                {
                    if (!resetManager.IsAuthorized(sessionId))
                    {
                        return;
                    }
                }

                using (SessionShutdownForm form = new SessionShutdownForm(sessionId))
                {
                    if (form.ShowDialog(this) == DialogResult.OK)
                    {
                        resetManager.LogSessionReset(sessionId);
                        SetControls(true);
                        SessionClient.Instance.ClearSessionRequestReceived += controller_SessionResetComplete;
                        SessionClient.Instance.SetUserCredential(UserManager.CurrentUser);
                        SessionClient.Instance.Close(sessionId, form.ShutdownOptions);
                    }
                }

                statusLabel.Text = "Releasing session {0} and cleaning up associated virtual machines and resources...".FormatWith(sessionId);
            }
        }
 private void end_ToolStripButton_Click(object sender, EventArgs e)
 {
     using (SessionShutdownForm form = new SessionShutdownForm(SessionId))
     {
         if (form.ShowDialog(this) == DialogResult.OK)
         {
             end_ToolStripButton.Enabled           = false;
             dispatcherLog_ToolStripButton.Enabled = false;
             SessionClient.Instance.Shutdown(SessionId, form.ShutdownOptions);
         }
     }
 }
Beispiel #3
0
        private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            bool closeForm = true;

            ///  Check if there is a running session.
            /// If so, ask the user if they want to stop the session (and do it for them if affirmative)
            /// If they do not want to stop the session then they don't really want to exit the app
            try
            {
                switch (e.CloseReason)
                {
                case CloseReason.UserClosing:
                    if (_sessionManager != null && _sessionManager.GetActiveSessions().Any())
                    {
                        var response = MessageBox.Show("A test execution session is currently running - do you want to stop the session and exit?",
                                                       "Attempting Close", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                        closeForm = (response == DialogResult.Yes);

                        if (closeForm)
                        {
                            var session   = _sessionManager.GetActiveSessions().FirstOrDefault();
                            var sessionId = session.SessionId;
                            if (!string.IsNullOrEmpty(sessionId))
                            {
                                using (SessionShutdownForm form = new SessionShutdownForm(sessionId))
                                {
                                    if (form.ShowDialog(this) == DialogResult.OK)
                                    {
                                        using (new BusyCursor())
                                        {
                                            // start shut down of session
                                            _sessionManager.Shutdown(sessionId, form.ShutdownOptions);

                                            // wait for shut down or 1 minute to complete
                                            Stopwatch s       = Stopwatch.StartNew();
                                            TimeSpan  maxWait = TimeSpan.FromSeconds(60);
                                            int       count   = 0;
                                            while (session.State != SessionState.ShutdownComplete && s.Elapsed < maxWait)
                                            {
                                                System.Threading.Thread.Sleep(500);
                                                main_StatusLabel.Text = "Exiting in {0} seconds (or less)..{1}".FormatWith((maxWait - s.Elapsed).Seconds, new string('.', count % 3));
                                                Application.DoEvents();
                                            }
                                            s.Stop();
                                        }
                                    }
                                }
                            }
                        }
                    }
                    break;
                }
            }
            finally
            {
                e.Cancel = !closeForm;
                if (closeForm)
                {
                    try
                    {
                        SessionClient.Instance.Stop();
                    }
                    catch { }
                }
            }
        }