CP-36392: Simplify if and else if blocks to reduce nesting in AddServerDialog.cs

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>
This commit is contained in:
Danilo Del Busso 2021-11-15 09:57:08 +00:00
parent 1acce3638c
commit cc917e2a66
No known key found for this signature in database
GPG Key ID: 0C48542619080FD4

View File

@ -137,37 +137,35 @@ namespace XenAdmin.Dialogs
ServerNameComboBox.Enabled = true;
AddButton.Text = Messages.ADD;
}
else
else if (!_changedPass)
return;
else if (connection.Password == null)
{
if (!_changedPass)
return;
if (connection.Password == null)
{
Text = Messages.CONNECT_TO_SERVER;
labelInstructions.Text = Messages.CONNECT_TO_SERVER_BLURB;
labelError.Text = "";
ServerNameComboBox.Enabled = false;
AddButton.Text = Messages.CONNECT;
}
else if (connection.ExpectPasswordIsCorrect)
{
// This situation should be rare, it normally comes from logging in a new session after an existing one has been made
// We now use duplicate sessions instead most of the time which don't log in again.
Text = Messages.CONNECT_TO_SERVER;
labelInstructions.Text = string.Format(Messages.ADDSERVER_PASS_NEW, BrandManager.BrandConsole);
labelError.Text = "";
ServerNameComboBox.Enabled = false;
AddButton.Text = Messages.OK;
}
else // the password probably hasn't actually changed but we do know the user has typed it in wrong
{
Text = Messages.CONNECT_TO_SERVER;
labelInstructions.Text = string.Format(Messages.ERROR_CONNECTING_BLURB, BrandManager.BrandConsole);
labelError.Text = Messages.ADD_NEW_INCORRECT;
ServerNameComboBox.Enabled = false;
AddButton.Text = Messages.CONNECT;
}
Text = Messages.CONNECT_TO_SERVER;
labelInstructions.Text = Messages.CONNECT_TO_SERVER_BLURB;
labelError.Text = "";
ServerNameComboBox.Enabled = false;
AddButton.Text = Messages.CONNECT;
}
else if (connection.ExpectPasswordIsCorrect)
{
// This situation should be rare, it normally comes from logging in a new session after an existing one has been made
// We now use duplicate sessions instead most of the time which don't log in again.
Text = Messages.CONNECT_TO_SERVER;
labelInstructions.Text = string.Format(Messages.ADDSERVER_PASS_NEW, BrandManager.BrandConsole);
labelError.Text = "";
ServerNameComboBox.Enabled = false;
AddButton.Text = Messages.OK;
}
else // the password probably hasn't actually changed but we do know the user has typed it in wrong
{
Text = Messages.CONNECT_TO_SERVER;
labelInstructions.Text = string.Format(Messages.ERROR_CONNECTING_BLURB, BrandManager.BrandConsole);
labelError.Text = Messages.ADD_NEW_INCORRECT;
ServerNameComboBox.Enabled = false;
AddButton.Text = Messages.CONNECT;
}
}
private void AddButton_Click(object sender, EventArgs e)
@ -205,7 +203,7 @@ namespace XenAdmin.Dialogs
{
if (conn == null)
{
conn = new XenConnection {fromDialog = true};
conn = new XenConnection { fromDialog = true };
conn.CachePopulated += conn_CachePopulated;
}
else if (!_changedPass)