From 940b1580b914057b3137b837ae8cbc92bff4cea5 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Fri, 30 Sep 2022 14:18:03 +0100 Subject: [PATCH] Fixes issue where the Finish page of the NewVM wizard was not showing the selected home server correctly. --- XenAdmin/Controls/AffinityPicker.Designer.cs | 1 + XenAdmin/Controls/AffinityPicker.cs | 56 ++++++------------- XenAdmin/Wizards/NewVMWizard/NewVMWizard.cs | 2 +- .../NewVMWizard/Page_HomeServer.Designer.cs | 2 +- .../Wizards/NewVMWizard/Page_HomeServer.cs | 37 ++++-------- 5 files changed, 31 insertions(+), 67 deletions(-) diff --git a/XenAdmin/Controls/AffinityPicker.Designer.cs b/XenAdmin/Controls/AffinityPicker.Designer.cs index 556860878..f8e403677 100644 --- a/XenAdmin/Controls/AffinityPicker.Designer.cs +++ b/XenAdmin/Controls/AffinityPicker.Designer.cs @@ -109,6 +109,7 @@ namespace XenAdmin.Controls this.ReasonColumn}); resources.ApplyResources(this.ServersGridView, "ServersGridView"); this.ServersGridView.Name = "ServersGridView"; + this.ServersGridView.SelectionChanged += new System.EventHandler(this.ServersGridView_SelectionChanged); this.ServersGridView.VisibleChanged += new System.EventHandler(this.ServersGridView_VisibleChanged); // // ImageColumn diff --git a/XenAdmin/Controls/AffinityPicker.cs b/XenAdmin/Controls/AffinityPicker.cs index 0f476cc17..4ec38c98d 100644 --- a/XenAdmin/Controls/AffinityPicker.cs +++ b/XenAdmin/Controls/AffinityPicker.cs @@ -48,6 +48,7 @@ namespace XenAdmin.Controls private IXenConnection Connection; private Host SrHost; private Host Affinity; + private bool selectedOnVisibleChanged; /// /// Should always be true if the AffinityPicker is used to create a VM. @@ -56,9 +57,7 @@ namespace XenAdmin.Controls /// internal bool AutoSelectAffinity = true; - public event EventHandler SelectedAffinityChanged = new EventHandler(OnSelectedAffinityChanged); - - private static void OnSelectedAffinityChanged(object obj, EventArgs e) { } + public event Action SelectedAffinityChanged; public AffinityPicker() { @@ -72,9 +71,9 @@ namespace XenAdmin.Controls SrHost = srhost; tableLayoutPanelWlbWarning.Visible = Helpers.WlbEnabledAndConfigured(connection); LoadServers(); - _UpdateControl(); + UpdateControl(); SelectRadioButtons(); - SelectedAffinityChanged(SelectedAffinity, new EventArgs()); + SelectedAffinityChanged?.Invoke(); } private void LoadServers() @@ -88,16 +87,6 @@ namespace XenAdmin.Controls } private void UpdateControl() - { - _UpdateControl(); - - SelectedAffinityChanged(SelectedAffinity, new EventArgs()); - } - - /// - /// does not fire selected affinity changed event - /// - private void _UpdateControl() { if (Connection == null) return; @@ -126,25 +115,15 @@ namespace XenAdmin.Controls } } - public Host SelectedAffinity - { - get - { - return DynamicRadioButton.Checked ? null : SelectedServer(); - } - } - + public Host SelectedAffinity => DynamicRadioButton.Checked ? null : SelectedServer(); private Host SelectedServer() { - if (ServersGridView.SelectedRows.Count == 0) - return null; + if (ServersGridView.SelectedRows.Count > 0) + return ((ServerGridRow)ServersGridView.SelectedRows[0]).Server; - Host h = ((ServerGridRow)ServersGridView.SelectedRows[0]).Server; - if (h == null) - return null; - return h; + return null; } private bool SelectServer(Host host) @@ -173,7 +152,6 @@ namespace XenAdmin.Controls private bool SelectSomething() { - //Now decide if we want to select anything. bool selected = false; if (Affinity != null) @@ -182,9 +160,6 @@ namespace XenAdmin.Controls if (!selected && SrHost != null) selected = SelectServer(SrHost); - /* if (!selected) - selected = SelectAnyServer();*/ - return selected; } @@ -193,17 +168,14 @@ namespace XenAdmin.Controls return SelectedAffinity != null || DynamicRadioButton.Checked; } - private void affinityListBox_SelectedValueChanged(object sender, EventArgs e) - { - UpdateControl(); - } - // we dont need to bother firing events if the other radio button gets checked or unchecked private void StaticRadioButton_CheckedChanged(object sender, EventArgs e) { if (StaticRadioButton.Checked && SelectedServer() == null) SelectSomething(); + UpdateControl(); + SelectedAffinityChanged?.Invoke(); if (StaticRadioButton.Checked) ServersGridView.Select(); @@ -217,8 +189,6 @@ namespace XenAdmin.Controls ServersGridView.Select(); } - bool selectedOnVisibleChanged = false; - private void ServersGridView_VisibleChanged(object sender, EventArgs e) { if (!selectedOnVisibleChanged) @@ -227,6 +197,12 @@ namespace XenAdmin.Controls SelectSomething();//CA-213728 } } + + private void ServersGridView_SelectionChanged(object sender, EventArgs e) + { + UpdateControl(); + SelectedAffinityChanged?.Invoke(); + } } internal class ServerGridRow : DataGridViewExRow diff --git a/XenAdmin/Wizards/NewVMWizard/NewVMWizard.cs b/XenAdmin/Wizards/NewVMWizard/NewVMWizard.cs index c713f75c2..3ad308c25 100644 --- a/XenAdmin/Wizards/NewVMWizard/NewVMWizard.cs +++ b/XenAdmin/Wizards/NewVMWizard/NewVMWizard.cs @@ -269,7 +269,7 @@ namespace XenAdmin.Wizards.NewVMWizard { if (!page_4_HomeServer.DisableStep) { - m_affinity = page_4_HomeServer.SelectedHomeServer; + m_affinity = page_4_HomeServer.Affinity; page_6_Storage.Affinity = m_affinity; page_CloudConfigParameters.Affinity = m_affinity; } diff --git a/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.Designer.cs b/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.Designer.cs index 410b4c8c6..a85158732 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.Designer.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.Designer.cs @@ -36,7 +36,7 @@ namespace XenAdmin.Wizards.NewVMWizard // resources.ApplyResources(this.affinityPicker1, "affinityPicker1"); this.affinityPicker1.Name = "affinityPicker1"; - this.affinityPicker1.SelectedAffinityChanged += new System.EventHandler(this.affinityPicker1_SelectedAffinityChanged); + this.affinityPicker1.SelectedAffinityChanged += new System.Action(this.affinityPicker1_SelectedAffinityChanged); // // Page_HomeServer // diff --git a/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.cs b/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.cs index 3be7ce6ab..bd6d25f30 100644 --- a/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.cs +++ b/XenAdmin/Wizards/NewVMWizard/Page_HomeServer.cs @@ -29,6 +29,7 @@ * SUCH DAMAGE. */ +using System; using System.Collections.Generic; using XenAdmin.Actions.VMActions; using XenAPI; @@ -49,31 +50,18 @@ namespace XenAdmin.Wizards.NewVMWizard #region XenTabPage overrides - public override string Text - { - get { return Messages.NEWVMWIZARD_HOMESERVERPAGE_NAME; } - } + public override string Text => Messages.NEWVMWIZARD_HOMESERVERPAGE_NAME; - public override string PageTitle - { - get { return Messages.NEWVMWIZARD_HOMESERVERPAGE_TITLE; } - } + public override string PageTitle => Messages.NEWVMWIZARD_HOMESERVERPAGE_TITLE; - public override string HelpID - { - get { return "HomeServer"; } - } + public override string HelpID => "HomeServer"; - public override List> PageSummary - { - get + public override List> PageSummary => + new List> { - List> sum = new List>(); - sum.Add(new KeyValuePair(Messages.NEWVMWIZARD_HOMESERVERPAGE_HOMESERVER, - Affinity != null ? Affinity.Name() : Messages.NEWVMWIZARD_HOMESERVER_NONE)); - return sum; - } - } + new KeyValuePair(Messages.NEWVMWIZARD_HOMESERVERPAGE_HOMESERVER, + Affinity != null ? Affinity.Name() : Messages.NEWVMWIZARD_HOMESERVER_NONE) + }; public override bool EnableNext() { @@ -122,17 +110,16 @@ namespace XenAdmin.Wizards.NewVMWizard #region Accessors - public Host SelectedHomeServer { get { return affinityPicker1.SelectedAffinity; } } - - public Host Affinity { private get; set; } + public Host Affinity { get; set; } public VM SelectedTemplate { private get; set; } public InstallMethod SelectedInstallMethod { private get; set; } public VDI SelectedCD { private get; set; } #endregion - private void affinityPicker1_SelectedAffinityChanged(object sender, System.EventArgs e) + private void affinityPicker1_SelectedAffinityChanged() { + Affinity = affinityPicker1.SelectedAffinity; OnPageUpdated(); } }