Fixes issue where the Finish page of the NewVM wizard was not showing the selected home server correctly.

This commit is contained in:
Konstantina Chremmou 2022-09-30 14:18:03 +01:00
parent 0d70266173
commit 940b1580b9
5 changed files with 31 additions and 67 deletions

View File

@ -109,6 +109,7 @@ namespace XenAdmin.Controls
this.ReasonColumn}); this.ReasonColumn});
resources.ApplyResources(this.ServersGridView, "ServersGridView"); resources.ApplyResources(this.ServersGridView, "ServersGridView");
this.ServersGridView.Name = "ServersGridView"; this.ServersGridView.Name = "ServersGridView";
this.ServersGridView.SelectionChanged += new System.EventHandler(this.ServersGridView_SelectionChanged);
this.ServersGridView.VisibleChanged += new System.EventHandler(this.ServersGridView_VisibleChanged); this.ServersGridView.VisibleChanged += new System.EventHandler(this.ServersGridView_VisibleChanged);
// //
// ImageColumn // ImageColumn

View File

@ -48,6 +48,7 @@ namespace XenAdmin.Controls
private IXenConnection Connection; private IXenConnection Connection;
private Host SrHost; private Host SrHost;
private Host Affinity; private Host Affinity;
private bool selectedOnVisibleChanged;
/// <summary> /// <summary>
/// Should always be true if the AffinityPicker is used to create a VM. /// Should always be true if the AffinityPicker is used to create a VM.
@ -56,9 +57,7 @@ namespace XenAdmin.Controls
/// </summary> /// </summary>
internal bool AutoSelectAffinity = true; internal bool AutoSelectAffinity = true;
public event EventHandler SelectedAffinityChanged = new EventHandler(OnSelectedAffinityChanged); public event Action SelectedAffinityChanged;
private static void OnSelectedAffinityChanged(object obj, EventArgs e) { }
public AffinityPicker() public AffinityPicker()
{ {
@ -72,9 +71,9 @@ namespace XenAdmin.Controls
SrHost = srhost; SrHost = srhost;
tableLayoutPanelWlbWarning.Visible = Helpers.WlbEnabledAndConfigured(connection); tableLayoutPanelWlbWarning.Visible = Helpers.WlbEnabledAndConfigured(connection);
LoadServers(); LoadServers();
_UpdateControl(); UpdateControl();
SelectRadioButtons(); SelectRadioButtons();
SelectedAffinityChanged(SelectedAffinity, new EventArgs()); SelectedAffinityChanged?.Invoke();
} }
private void LoadServers() private void LoadServers()
@ -88,16 +87,6 @@ namespace XenAdmin.Controls
} }
private void UpdateControl() private void UpdateControl()
{
_UpdateControl();
SelectedAffinityChanged(SelectedAffinity, new EventArgs());
}
/// <summary>
/// does not fire selected affinity changed event
/// </summary>
private void _UpdateControl()
{ {
if (Connection == null) if (Connection == null)
return; return;
@ -126,25 +115,15 @@ namespace XenAdmin.Controls
} }
} }
public Host SelectedAffinity public Host SelectedAffinity => DynamicRadioButton.Checked ? null : SelectedServer();
{
get
{
return DynamicRadioButton.Checked ? null : SelectedServer();
}
}
private Host SelectedServer() private Host SelectedServer()
{ {
if (ServersGridView.SelectedRows.Count == 0) if (ServersGridView.SelectedRows.Count > 0)
return null; return ((ServerGridRow)ServersGridView.SelectedRows[0]).Server;
Host h = ((ServerGridRow)ServersGridView.SelectedRows[0]).Server; return null;
if (h == null)
return null;
return h;
} }
private bool SelectServer(Host host) private bool SelectServer(Host host)
@ -173,7 +152,6 @@ namespace XenAdmin.Controls
private bool SelectSomething() private bool SelectSomething()
{ {
//Now decide if we want to select anything.
bool selected = false; bool selected = false;
if (Affinity != null) if (Affinity != null)
@ -182,9 +160,6 @@ namespace XenAdmin.Controls
if (!selected && SrHost != null) if (!selected && SrHost != null)
selected = SelectServer(SrHost); selected = SelectServer(SrHost);
/* if (!selected)
selected = SelectAnyServer();*/
return selected; return selected;
} }
@ -193,17 +168,14 @@ namespace XenAdmin.Controls
return SelectedAffinity != null || DynamicRadioButton.Checked; 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 // we dont need to bother firing events if the other radio button gets checked or unchecked
private void StaticRadioButton_CheckedChanged(object sender, EventArgs e) private void StaticRadioButton_CheckedChanged(object sender, EventArgs e)
{ {
if (StaticRadioButton.Checked && SelectedServer() == null) if (StaticRadioButton.Checked && SelectedServer() == null)
SelectSomething(); SelectSomething();
UpdateControl(); UpdateControl();
SelectedAffinityChanged?.Invoke();
if (StaticRadioButton.Checked) if (StaticRadioButton.Checked)
ServersGridView.Select(); ServersGridView.Select();
@ -217,8 +189,6 @@ namespace XenAdmin.Controls
ServersGridView.Select(); ServersGridView.Select();
} }
bool selectedOnVisibleChanged = false;
private void ServersGridView_VisibleChanged(object sender, EventArgs e) private void ServersGridView_VisibleChanged(object sender, EventArgs e)
{ {
if (!selectedOnVisibleChanged) if (!selectedOnVisibleChanged)
@ -227,6 +197,12 @@ namespace XenAdmin.Controls
SelectSomething();//CA-213728 SelectSomething();//CA-213728
} }
} }
private void ServersGridView_SelectionChanged(object sender, EventArgs e)
{
UpdateControl();
SelectedAffinityChanged?.Invoke();
}
} }
internal class ServerGridRow : DataGridViewExRow internal class ServerGridRow : DataGridViewExRow

View File

@ -269,7 +269,7 @@ namespace XenAdmin.Wizards.NewVMWizard
{ {
if (!page_4_HomeServer.DisableStep) if (!page_4_HomeServer.DisableStep)
{ {
m_affinity = page_4_HomeServer.SelectedHomeServer; m_affinity = page_4_HomeServer.Affinity;
page_6_Storage.Affinity = m_affinity; page_6_Storage.Affinity = m_affinity;
page_CloudConfigParameters.Affinity = m_affinity; page_CloudConfigParameters.Affinity = m_affinity;
} }

View File

@ -36,7 +36,7 @@ namespace XenAdmin.Wizards.NewVMWizard
// //
resources.ApplyResources(this.affinityPicker1, "affinityPicker1"); resources.ApplyResources(this.affinityPicker1, "affinityPicker1");
this.affinityPicker1.Name = "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 // Page_HomeServer
// //

View File

@ -29,6 +29,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
using System;
using System.Collections.Generic; using System.Collections.Generic;
using XenAdmin.Actions.VMActions; using XenAdmin.Actions.VMActions;
using XenAPI; using XenAPI;
@ -49,31 +50,18 @@ namespace XenAdmin.Wizards.NewVMWizard
#region XenTabPage overrides #region XenTabPage overrides
public override string Text public override string Text => Messages.NEWVMWIZARD_HOMESERVERPAGE_NAME;
{
get { return Messages.NEWVMWIZARD_HOMESERVERPAGE_NAME; }
}
public override string PageTitle public override string PageTitle => Messages.NEWVMWIZARD_HOMESERVERPAGE_TITLE;
{
get { return Messages.NEWVMWIZARD_HOMESERVERPAGE_TITLE; }
}
public override string HelpID public override string HelpID => "HomeServer";
{
get { return "HomeServer"; }
}
public override List<KeyValuePair<string, string>> PageSummary public override List<KeyValuePair<string, string>> PageSummary =>
{ new List<KeyValuePair<string, string>>
get
{ {
List<KeyValuePair<string, string>> sum = new List<KeyValuePair<string, string>>(); new KeyValuePair<string, string>(Messages.NEWVMWIZARD_HOMESERVERPAGE_HOMESERVER,
sum.Add(new KeyValuePair<string, string>(Messages.NEWVMWIZARD_HOMESERVERPAGE_HOMESERVER, Affinity != null ? Affinity.Name() : Messages.NEWVMWIZARD_HOMESERVER_NONE)
Affinity != null ? Affinity.Name() : Messages.NEWVMWIZARD_HOMESERVER_NONE)); };
return sum;
}
}
public override bool EnableNext() public override bool EnableNext()
{ {
@ -122,17 +110,16 @@ namespace XenAdmin.Wizards.NewVMWizard
#region Accessors #region Accessors
public Host SelectedHomeServer { get { return affinityPicker1.SelectedAffinity; } } public Host Affinity { get; set; }
public Host Affinity { private get; set; }
public VM SelectedTemplate { private get; set; } public VM SelectedTemplate { private get; set; }
public InstallMethod SelectedInstallMethod { private get; set; } public InstallMethod SelectedInstallMethod { private get; set; }
public VDI SelectedCD { private get; set; } public VDI SelectedCD { private get; set; }
#endregion #endregion
private void affinityPicker1_SelectedAffinityChanged(object sender, System.EventArgs e) private void affinityPicker1_SelectedAffinityChanged()
{ {
Affinity = affinityPicker1.SelectedAffinity;
OnPageUpdated(); OnPageUpdated();
} }
} }