Skip to content

Commit

Permalink
Detect incorrect value for ExistingSessionDetectedAction setting
Browse files Browse the repository at this point in the history
  • Loading branch information
rlktradewright committed Jul 14, 2023
1 parent 8cef9c0 commit b3222ee
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions src/ibcalpha/ibc/ExistingSessionDetectedDialogHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,31 @@ public boolean filterEvent(Window window, int eventId) {
}

public void handleWindow(Window window, int eventID) {
String setting = Settings.settings().getString("ExistingSessionDetectedAction", "manual");
final String MANUAL = "manual";
final String PRIMARY = "primary";
final String PRIMARY_OVERRIDE = "primaryoverride";
final String SECONDARY = "secondary";

String setting = Settings.settings().getString("ExistingSessionDetectedAction", "manual").toLowerCase();

switch (setting) {
case MANUAL:
case PRIMARY:
case PRIMARY_OVERRIDE:
case SECONDARY:
break;
default:
Utils.logToConsole("ExistingSessionDetectedAction has an invalid value: " + setting + ": assuming 'secondary'");
setting = SECONDARY;
}

if (setting.equalsIgnoreCase("manual")) {
if (setting.equals(MANUAL)) {
Utils.logToConsole("User must choose whether to continue with this session (scenario 1)");
// nothing to do
return;
}

if (setting.equalsIgnoreCase("secondary")) {
if (setting.equals(SECONDARY)) {
Utils.logToConsole("End this session and let the other session proceed (scenario 2)");
if (!SwingUtils.clickButton(window, "Cancel") && !SwingUtils.clickButton(window, "Exit Application")) {
Utils.logError("could not handle 'Existing session detected' dialog because the 'Cancel' or 'Exit Application' button wasn't found.");
Expand Down Expand Up @@ -73,7 +89,7 @@ public void handleWindow(Window window, int eventID) {
*/

if (LoginManager.loginManager().getLoginState() != LoginManager.LoginState.LOGGED_IN){
/* The login has not yet been completed, so this is a new IBC instance,ie we are
/* The login has not yet been completed, so this is a new IBC instance, ie we are
session B.
We don't know the type of session A, so we continue this one.
Expand Down Expand Up @@ -101,27 +117,28 @@ public void handleWindow(Window window, int eventID) {
} else {
/* The login has already been completed so we are session A. The
case where we are Secondary has already been handled, so we must
be either Primary or PrimaryOverride (but we don't know which. If
be either Primary or PrimaryOverride. If
we are primary we must continue this session. If we are
secondary, we must allow the other session to proceed in case it
PrimaryOverride, we must allow the other session to proceed in case it
is primary.
*/
if (setting.equalsIgnoreCase("primary")) {
if (setting.equals(PRIMARY)) {
Utils.logToConsole("Continue this session and let the other session exit (scenario 5)");
if (!SwingUtils.clickButton(window, "OK") &&
!SwingUtils.clickButton(window, "Continue Login") &&
!SwingUtils.clickButton(window, "Reconnect This Session")) {
Utils.logError("could not handle 'Existing session detected' dialog because the 'OK' or 'Continue Login' or 'Reconnect This Session' button wasn't found.");
}
} else {
} else if (setting.equals(PRIMARY_OVERRIDE)) {
Utils.logToConsole("Other session may be primary, so end this session and let the other one proceed (scenario 6)");

// ideally we'd just click the "Exit Application" button, but TWS doesn't react to
// it properly in these circumstances, so we have to click the button and then exit the program
if (!SwingUtils.clickButton(window, "Cancel") && !SwingUtils.clickButton(window, "Exit Application")) {
Utils.logError("could not handle 'Existing session detected' dialog because the 'Cancel' or 'Exit Application' button wasn't found.");
}
// System.exit(0);
} else {
Utils.exitWithError(ErrorCodes.INVALID_STATE, "Unexpected setting value: " + setting);
}
}
}
Expand Down

0 comments on commit b3222ee

Please sign in to comment.