CP-36392: Amend calls that generate unused return values

Mixture of correctly implementing `Trim()` calls, and removing calls that generate useless ephemeral variables.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>
This commit is contained in:
Danilo Del Busso 2021-10-04 15:42:40 +01:00
parent a5ddcf1b97
commit dcbaf5d1a4
No known key found for this signature in database
GPG Key ID: 55F556F9A25CB037
5 changed files with 38 additions and 74 deletions

View File

@ -271,7 +271,6 @@ namespace XenAdmin.Controls
cbLUN.Items.Add(new LunComboBoxItem(vdi) { AdditionalConstraints = LunConstraints });
}
cbLUN.Items.OfType<LunComboBoxItem>().OrderBy(i=>i.Enabled);
Cells.AddRange(tbVDI, cbLUN, tbSR);
Debug.Assert(cbLUN.Items.Count == Sr.VDIs.Count, "Not all combobox items were converted");
}

View File

@ -213,12 +213,13 @@ namespace XenAdmin.Dialogs
into g
select new { ExpiryDate = g.Key, Hosts = g };
if(expiryGroups.Count() > 1)
{
expiryGroups.OrderBy(g => g.ExpiryDate);
if ((expiryGroups.ElementAt(1).ExpiryDate - expiryGroups.ElementAt(0).ExpiryDate).TotalDays > 30)
return true;
}
expiryGroups = expiryGroups.OrderBy(g => g.ExpiryDate).ToList();
if (expiryGroups.Count() <= 1)
return false;
if ((expiryGroups.ElementAt(1).ExpiryDate - expiryGroups.ElementAt(0).ExpiryDate).TotalDays > 30)
return true;
}
return false;
}

View File

@ -287,24 +287,20 @@ namespace XenAdmin.Alerts
public static PerfmonDefinition[] GetPerfmonDefinitions(IXenObject xo)
{
if (!(xo is VM) && !(xo is Host) && !(xo is SR))
return new PerfmonDefinition[0];
return Array.Empty<PerfmonDefinition>();
Dictionary<string, string> other_config = Helpers.GetOtherConfig(xo);
var other_config = Helpers.GetOtherConfig(xo);
if (other_config == null)
return new PerfmonDefinition[0];
return Array.Empty<PerfmonDefinition>();
if (!other_config.ContainsKey(PERFMON_KEY_NAME))
return new PerfmonDefinition[0];
return Array.Empty<PerfmonDefinition>();
string perfmonConfigXML = other_config[PERFMON_KEY_NAME];
var perfmonConfigXML = other_config[PERFMON_KEY_NAME];
if (perfmonConfigXML == null)
return new PerfmonDefinition[0];
return Array.Empty<PerfmonDefinition>();
perfmonConfigXML.Trim();
if (String.IsNullOrEmpty(perfmonConfigXML))
return new PerfmonDefinition[0];
return GetPerfmonDefinitions(perfmonConfigXML);
return string.IsNullOrEmpty(perfmonConfigXML) ? Array.Empty<PerfmonDefinition>() : GetPerfmonDefinitions(perfmonConfigXML);
}
/// <summary>

View File

@ -205,74 +205,53 @@ namespace XenAdmin.Alerts
public static string GetMailDestination(IXenConnection connection)
{
Pool pool = Helpers.GetPoolOfOne(connection);
var pool = Helpers.GetPoolOfOne(connection);
if (pool == null)
return null;
Dictionary<String, String> other_config = Helpers.GetOtherConfig(pool);
if (other_config == null)
var otherConfig = Helpers.GetOtherConfig(pool);
if (otherConfig == null)
return null;
if (!other_config.ContainsKey(MAIL_DESTINATION_KEY_NAME))
if (!otherConfig.ContainsKey(MAIL_DESTINATION_KEY_NAME))
return null;
String mailAddress = other_config[MAIL_DESTINATION_KEY_NAME];
if (mailAddress == null)
return null;
mailAddress.Trim();
if (String.IsNullOrEmpty(mailAddress))
return null;
return mailAddress;
var mailAddress = otherConfig[MAIL_DESTINATION_KEY_NAME]?.Trim();
return string.IsNullOrEmpty(mailAddress) ? null : mailAddress;
}
public static string GetSmtpMailHub(IXenConnection connection)
{
Pool pool = Helpers.GetPoolOfOne(connection);
var pool = Helpers.GetPoolOfOne(connection);
if (pool == null)
return null;
Dictionary<String, String> other_config = Helpers.GetOtherConfig(pool);
if (other_config == null)
var otherConfig = Helpers.GetOtherConfig(pool);
if (otherConfig == null)
return null;
if (!other_config.ContainsKey(SMTP_MAILHUB_KEY_NAME))
if (!otherConfig.ContainsKey(SMTP_MAILHUB_KEY_NAME))
return null;
String mailHub = other_config[SMTP_MAILHUB_KEY_NAME];
if (mailHub == null)
return null;
mailHub.Trim();
if (String.IsNullOrEmpty(mailHub))
return null;
return mailHub;
var mailHub = otherConfig[SMTP_MAILHUB_KEY_NAME]?.Trim();
return string.IsNullOrEmpty(mailHub) ? null : mailHub;
}
public static string GetMailLanguageCode(IXenConnection connection)
{
Pool pool = Helpers.GetPoolOfOne(connection);
var pool = Helpers.GetPoolOfOne(connection);
if (pool == null)
return null;
Dictionary<String, String> other_config = Helpers.GetOtherConfig(pool);
if (other_config == null)
var otherConfig = Helpers.GetOtherConfig(pool);
if (otherConfig == null)
return null;
if (!other_config.ContainsKey(MAIL_LANGUAGE_KEY_NAME))
if (!otherConfig.ContainsKey(MAIL_LANGUAGE_KEY_NAME))
return null;
String mailLanguageCode = other_config[MAIL_LANGUAGE_KEY_NAME];
if (mailLanguageCode == null)
return null;
mailLanguageCode.Trim();
if (String.IsNullOrEmpty(mailLanguageCode))
return null;
return mailLanguageCode;
var mailLanguageCode = otherConfig[MAIL_LANGUAGE_KEY_NAME]?.Trim();
return string.IsNullOrEmpty(mailLanguageCode) ? null : mailLanguageCode;
}
public static String MailLanguageNameFromCode(String code)

View File

@ -68,36 +68,25 @@ namespace XenAdmin.CustomFields
private static List<CustomFieldDefinition> GetCustomFieldsFromGuiConfig(IXenConnection connection)
{
Pool pool = Helpers.GetPoolOfOne(connection);
var pool = Helpers.GetPoolOfOne(connection);
if (pool == null)
{
return new List<CustomFieldDefinition>();
}
Dictionary<String, String> other_config = Helpers.GetGuiConfig(pool);
if (other_config == null)
var otherConfig = Helpers.GetGuiConfig(pool);
if (otherConfig == null)
{
return new List<CustomFieldDefinition>();
}
if (!other_config.ContainsKey(CustomFieldsManager.CUSTOM_FIELD_BASE_KEY))
if (!otherConfig.ContainsKey(CustomFieldsManager.CUSTOM_FIELD_BASE_KEY))
{
return new List<CustomFieldDefinition>();
}
String customFields = other_config[CustomFieldsManager.CUSTOM_FIELD_BASE_KEY];
if (customFields == null)
{
return new List<CustomFieldDefinition>();
}
customFields.Trim();
if (String.IsNullOrEmpty(customFields))
{
return new List<CustomFieldDefinition>();
}
return GetCustomFieldDefinitions(customFields);
var customFields = otherConfig[CustomFieldsManager.CUSTOM_FIELD_BASE_KEY]?.Trim();
return string.IsNullOrEmpty(customFields) ? new List<CustomFieldDefinition>() : GetCustomFieldDefinitions(customFields);
}
public List<CustomFieldDefinition> GetCustomFields()