diff --git a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.cs b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.cs index f3d367288..43e993d1b 100755 --- a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.cs +++ b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.cs @@ -60,6 +60,7 @@ namespace XenAdmin.SettingsPanels private string _OrigSmtpServerAddrTextBox; private string _OrigSmtpServerPortTextBox; private string _OrigMailLanguageCodeComboBox; + private bool _bSupportMailLanguage; private readonly ToolTip InvalidParamToolTip; @@ -112,10 +113,35 @@ namespace XenAdmin.SettingsPanels return !SmtpServerAddrTextBox.Text.ToCharArray().Any((c) => c >= 128) && SmtpServerAddrTextBox.Text.Trim().Length > 0; } + public void SetMailLanguageComboBoxValue(String code) + { + if (_bSupportMailLanguage) + { // Feature supported + if (null == code) + { // Set default value + if (PerfmonOptionsDefinition.MailLanguageHasCode(Branding.BRANDING_PERF_ALERT_MAIL_LANGUAGE_DEFAULT)) + MailLanguageComboBox.SelectedValue = Branding.BRANDING_PERF_ALERT_MAIL_LANGUAGE_DEFAULT; + else + MailLanguageComboBox.SelectedIndex = 0; + } + else if (PerfmonOptionsDefinition.MailLanguageHasCode(code)) + MailLanguageComboBox.SelectedValue = code; // Valid language code, set it to MailLanguageComboBox + else + MailLanguageComboBox.SelectedValue = null; // Invalid language code, set null to MailLanguageComboBox + } + else + MailLanguageComboBox.SelectedValue = null; // Feature not supported + } + public void SetXenObjects(IXenObject orig, IXenObject clone) { _XenModelObject = clone; + if (Helpers.FalconOrGreater(_XenModelObject.Connection)) + _bSupportMailLanguage = true; + else + _bSupportMailLanguage = false; + Repopulate(); // Save original settings for change detection @@ -123,7 +149,11 @@ namespace XenAdmin.SettingsPanels _OrigEmailAddressTextBox = EmailAddressTextBox.Text; _OrigSmtpServerAddrTextBox = SmtpServerAddrTextBox.Text; _OrigSmtpServerPortTextBox = SmtpServerPortTextBox.Text; - _OrigMailLanguageCodeComboBox = null == MailLanguageComboBox.SelectedValue ? "" : MailLanguageComboBox.SelectedValue.ToString(); + + if (_bSupportMailLanguage) + _OrigMailLanguageCodeComboBox = null == MailLanguageComboBox.SelectedValue ? null : MailLanguageComboBox.SelectedValue.ToString(); + else + _OrigMailLanguageCodeComboBox = null; } public void Repopulate() { @@ -131,6 +161,12 @@ namespace XenAdmin.SettingsPanels return; try { + if (_bSupportMailLanguage) + { + MailLanguageComboBox.Visible = true; + MailLanguageLabel.Visible = true; + } + _PerfmonOptions = PerfmonOptionsDefinition.GetPerfmonOptionsDefinitions(_XenModelObject); if (_PerfmonOptions != null) { @@ -138,16 +174,12 @@ namespace XenAdmin.SettingsPanels EmailAddressTextBox.Text = _PerfmonOptions.MailDestination; SmtpServerAddrTextBox.Text = PerfmonOptionsDefinition.GetSmtpServerAddress(_PerfmonOptions.MailHub); SmtpServerPortTextBox.Text = PerfmonOptionsDefinition.GetSmtpPort(_PerfmonOptions.MailHub); - if (null != _PerfmonOptions.MailLanguageCode) - MailLanguageComboBox.SelectedValue = _PerfmonOptions.MailLanguageCode; + + SetMailLanguageComboBoxValue(_PerfmonOptions.MailLanguageCode); } else { - // Set default language value - if (PerfmonOptionsDefinition.MailLanguageHasCode(Branding.BRANDING_PERF_ALERT_MAIL_LANGUAGE_DEFAULT)) - MailLanguageComboBox.SelectedValue = Branding.BRANDING_PERF_ALERT_MAIL_LANGUAGE_DEFAULT; - else - MailLanguageComboBox.SelectedIndex = 0; + SetMailLanguageComboBoxValue(null); } } catch { } @@ -161,7 +193,7 @@ namespace XenAdmin.SettingsPanels (_OrigEmailAddressTextBox != EmailAddressTextBox.Text) || (_OrigSmtpServerAddrTextBox != SmtpServerAddrTextBox.Text) || (_OrigSmtpServerPortTextBox != SmtpServerPortTextBox.Text) || - (_OrigMailLanguageCodeComboBox != MailLanguageComboBox.SelectedValue.ToString())); + (_bSupportMailLanguage && null != MailLanguageComboBox.SelectedValue && (_OrigMailLanguageCodeComboBox != MailLanguageComboBox.SelectedValue.ToString()))); } } @@ -207,7 +239,10 @@ namespace XenAdmin.SettingsPanels if (EmailNotificationCheckBox.Checked) { string smtpMailHub = SmtpServerAddrTextBox.Text + ":" + SmtpServerPortTextBox.Text; - perfmonOptions = new PerfmonOptionsDefinition(smtpMailHub, EmailAddressTextBox.Text, MailLanguageComboBox.SelectedValue.ToString()); + string mailLanguageCode = null; + if (_bSupportMailLanguage && null != MailLanguageComboBox.SelectedValue) + mailLanguageCode = MailLanguageComboBox.SelectedValue.ToString(); + perfmonOptions = new PerfmonOptionsDefinition(smtpMailHub, EmailAddressTextBox.Text, mailLanguageCode); } return new PerfmonOptionsDefinitionAction(_XenModelObject.Connection, perfmonOptions, true); diff --git a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.resx b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.resx index 57617c079..a2d7d3a50 100755 --- a/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.resx +++ b/XenAdmin/SettingsPanels/PerfmonAlertOptionsPage.resx @@ -210,6 +210,9 @@ 9 + + False + MailLanguageComboBox @@ -243,6 +246,9 @@ MiddleLeft + + False + MailLanguageLabel diff --git a/XenModel/Actions/Perfmon/PerfmonOptionsDefinitionAction.cs b/XenModel/Actions/Perfmon/PerfmonOptionsDefinitionAction.cs index 2d8eb4dac..d1fabdd53 100755 --- a/XenModel/Actions/Perfmon/PerfmonOptionsDefinitionAction.cs +++ b/XenModel/Actions/Perfmon/PerfmonOptionsDefinitionAction.cs @@ -68,7 +68,8 @@ namespace XenAdmin.Actions { Helpers.SetOtherConfig(Session, pool, PerfmonOptionsDefinition.MAIL_DESTINATION_KEY_NAME, perfmonOptions.MailDestination); Helpers.SetOtherConfig(Session, pool, PerfmonOptionsDefinition.SMTP_MAILHUB_KEY_NAME, perfmonOptions.MailHub); - Helpers.SetOtherConfig(Session, pool, PerfmonOptionsDefinition.MAIL_LANGUAGE_KEY_NAME, perfmonOptions.MailLanguageCode); + if(null != perfmonOptions.MailLanguageCode) + Helpers.SetOtherConfig(Session, pool, PerfmonOptionsDefinition.MAIL_LANGUAGE_KEY_NAME, perfmonOptions.MailLanguageCode); } } } diff --git a/XenModel/Alerts/PerfmonOptionsDefinition.cs b/XenModel/Alerts/PerfmonOptionsDefinition.cs index 75708c6b7..4a767fcc4 100755 --- a/XenModel/Alerts/PerfmonOptionsDefinition.cs +++ b/XenModel/Alerts/PerfmonOptionsDefinition.cs @@ -61,6 +61,9 @@ namespace XenAdmin.Alerts { String ret = null; + if (null == name) + return ret; + foreach(KeyValuePair pair in _list) { if(pair.Value == name) @@ -77,6 +80,9 @@ namespace XenAdmin.Alerts { String ret = null; + if (null == code) + return ret; + foreach (KeyValuePair pair in _list) { if (pair.Key == code)