/// Drop the session so that we'll get a new one the next time. /// This is used when handling exceptions. private void DropSession() { Session s = session; session = null; // Do this on a new thread: if the master has died, then the session logout may block // up to the timeout. Doing this on the calling thread would mean doubling the actual time elapsed // before we decide the server is dead. connection.Logout(s); }
private void ButtonLogout_Click(object sender, EventArgs e) { Program.AssertOnEventThread(); // Double check, this method is called from a context menu as well and the state could have changed under it if (!ButtonLogout.Enabled) { return; } Session session = _connection.Session; if (session == null) { return; } // First we check through the list to check what warning message we show List <Subject> subjectsToLogout = new List <Subject>(); foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows) { if (r.IsLocalRootRow || !r.LoggedIn) { continue; } subjectsToLogout.Add(r.subject); } bool suicide = false; // Warn if user is logging themselves out if (session.Subject != null)//have already checked session not null { var warnMsg = string.Format(subjectsToLogout.Count > 1 ? Messages.AD_LOGOUT_SUICIDE_MANY : Messages.AD_LOGOUT_SUICIDE_ONE, Helpers.GetName(_connection).Ellipsise(50)); foreach (Subject entry in subjectsToLogout) { if (entry.opaque_ref == session.Subject) { DialogResult r; using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Warning, warnMsg, Messages.AD_FEATURE_NAME), ThreeButtonDialog.ButtonYes, new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true))) { r = dlg.ShowDialog(this); } //CA-64818: DialogResult can be No if the No button has been hit //or Cancel if the dialog has been closed from the control box if (r != DialogResult.Yes) { return; } suicide = true; break; } } } var logoutMessage = subjectsToLogout.Count == 1 ? string.Format(Messages.QUESTION_LOGOUT_AD_USER_ONE, subjectsToLogout[0].DisplayName ?? subjectsToLogout[0].SubjectName) : string.Format(Messages.QUESTION_LOGOUT_AD_USER_MANY, subjectsToLogout.Count); if (!suicide)//CA-68645 { DialogResult questionDialog; using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details( SystemIcons.Warning, logoutMessage, Messages.AD_FEATURE_NAME), ThreeButtonDialog.ButtonYes, new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true))) { questionDialog = dlg.ShowDialog(this); } //CA-64818: DialogResult can be No if the No button has been hit //or Cancel if the dialog has been closed from the control box if (questionDialog != DialogResult.Yes) { return; } } // Then we go through the list and disconnect each user session, doing our own last if necessary foreach (AdSubjectRow r in GridViewSubjectList.SelectedRows) { // check they are not the root row and are logged in if (r.IsLocalRootRow || !r.LoggedIn) { continue; } if (session.UserSid == r.subject.subject_identifier) { continue; } DelegatedAsyncAction logoutAction = new DelegatedAsyncAction(_connection, Messages.TERMINATING_SESSIONS, Messages.IN_PROGRESS, Messages.COMPLETED, delegate(Session s) { Session.logout_subject_identifier(s, r.subject.subject_identifier); }, "session.logout_subject_identifier"); logoutAction.RunAsync(); } if (suicide) { DelegatedAsyncAction logoutAction = new DelegatedAsyncAction(_connection, Messages.TERMINATING_SESSIONS, Messages.IN_PROGRESS, Messages.COMPLETED, delegate(Session s) { Session.logout_subject_identifier(s, session.UserSid); _connection.Logout(); }, "session.logout_subject_identifier"); logoutAction.RunAsync(); } else { // signal the background thread to update the logged in status lock (statusUpdaterLock) Monitor.Pulse(statusUpdaterLock); } }