Merge pull request #2821 from kc284/master

CA-340735: Re-wrote Page_InstallationMedia of the NewVM wizard to fix various issues
This commit is contained in:
Konstantina Chremmou 2021-08-10 14:32:18 +01:00 committed by GitHub
commit bdbdb0feb0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 327 additions and 439 deletions

View File

@ -30,6 +30,7 @@
*/
using System;
using System.ComponentModel;
using XenAPI;
using XenAdmin.Actions;
using XenCenterLib;
@ -38,17 +39,13 @@ namespace XenAdmin.Controls
{
public class CDChanger : ISODropDownBox
{
public CDChanger()
{
Empty = true;
}
private VBD cdrom;
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public VBD Drive
{
get
{
return cdrom;
}
get => cdrom;
set
{
if (cdrom != null)
@ -59,67 +56,9 @@ namespace XenAdmin.Controls
if (cdrom != null)
cdrom.PropertyChanged += cdrom_PropertyChanged;
refreshAll();
}
}
public VM TheVM
{
set
{
if (vm != null)
vm.PropertyChanged -= vm_PropertyChanged;
vm = value;
connection = vm == null ? null : vm.Connection;
if (vm != null)
vm.PropertyChanged += vm_PropertyChanged;
}
get
{
return vm;
}
}
protected override void RefreshSRs()
{
BeginUpdate();
try
{
Items.Clear();
base.RefreshSRs();
}
finally
{
EndUpdate();
}
}
public override void SelectCD()
{
if (cdrom == null || cdrom.empty || cdrom.VDI == null)
{
this.SelectedIndex = 0;
return;
}
SelectedCD = connection.Resolve(cdrom.VDI);
base.SelectCD();
}
public override void refreshAll()
{
if (!DroppedDown)
{
RefreshSRs();
SelectCD();
refreshOnClose = false;
}
else
{
refreshOnClose = true;
SelectedCD = cdrom == null || cdrom.empty || cdrom.VDI == null
? null
: connection.Resolve(cdrom.VDI);
}
}
@ -154,29 +93,34 @@ namespace XenAdmin.Controls
ChangeVMISOAction action = new ChangeVMISOAction(connection, vm, vdi, cdrom);
action.Completed += delegate
{
Program.Invoke(this, () =>
{
Program.Invoke(this, delegate()
{
changing = false;
SelectCD();
Enabled = true;
});
};
changing = false;
SelectedCD = cdrom == null || cdrom.empty || cdrom.VDI == null
? null
: connection.Resolve(cdrom.VDI);
Enabled = true;
});
};
action.RunAsync();
}
internal override void DeregisterEvents()
{
// Remove VM listeners
if (vm != null)
vm.PropertyChanged -= vm_PropertyChanged;
// Remove VBD (cdrom) listeners
if (cdrom != null)
cdrom.PropertyChanged -= cdrom_PropertyChanged;
base.DeregisterEvents();
}
private void cdrom_PropertyChanged(object sender1, PropertyChangedEventArgs e)
{
if ((e.PropertyName == "empty" || e.PropertyName == "vdi") && !changing)
{
SelectCD();
}
}
}
}

View File

@ -43,22 +43,25 @@ namespace XenAdmin.Controls
{
public class ISODropDownBox : NonSelectableComboBox
{
public VM vm;
protected VBD cdrom;
protected bool refreshOnClose;
public event Action SrsRefreshed;
protected VM vm;
private bool refreshOnClose;
protected bool changing = false;
private IXenConnection _connection;
private readonly CollectionChangeEventHandler SR_CollectionChangedWithInvoke;
private VDI selectedCD;
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public VDI SelectedCD
{
get
get => (SelectedItem as ToStringWrapper<VDI>)?.item;
set
{
var selectedVdi = SelectedItem as ToStringWrapper<VDI>;
return selectedVdi == null ? null : selectedVdi.item;
selectedCD = value;
SelectCD();
}
set { selectedCD = value; }
}
public ISODropDownBox()
@ -75,26 +78,12 @@ namespace XenAdmin.Controls
base.Dispose(disposing);
}
private void RefreshSRs_()
{
BeginUpdate();
try
{
Items.Clear();
RefreshSRs();
}
finally
{
EndUpdate();
}
}
protected virtual void RefreshSRs()
private void RefreshSRs()
{
Program.AssertOnEventThread();
if (Empty)
Items.Add(new ToStringWrapper<VDI>(null, Messages.EMPTY)); //Create a special VDIWrapper for the empty dropdown item
//Create a special VDIWrapper for the empty dropdown item
Items.Add(new ToStringWrapper<VDI>(null, Messages.EMPTY));
if (connection == null)
return;
@ -148,38 +137,51 @@ namespace XenAdmin.Controls
}
}
public virtual void SelectCD()
protected void SelectCD()
{
if (selectedCD == null)
if (selectedCD != null)
{
if (Items.Count > 0)
SelectedIndex = 0;
else
SelectedIndex = -1;
return;
}
foreach (object o in Items)
{
ToStringWrapper<VDI> vdiNameWrapper = o as ToStringWrapper<VDI>;
if (vdiNameWrapper == null)
continue;
VDI iso = vdiNameWrapper.item;
if (iso == null || !iso.Show(Properties.Settings.Default.ShowHiddenVMs))
continue;
if (iso == selectedCD)
foreach (object o in Items)
{
SelectedItem = o;
break;
VDI iso = (o as ToStringWrapper<VDI>)?.item;
if (iso == null || !iso.Show(Properties.Settings.Default.ShowHiddenVMs))
continue;
if (iso == selectedCD)
{
SelectedItem = o;
return;
}
}
}
if (Items.Count > 0)
SelectedIndex = 0;
else
SelectedIndex = -1;
}
public bool Empty { get; set; }
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public VM VM
{
set
{
if (vm != null)
vm.PropertyChanged -= vm_PropertyChanged;
vm = value;
if (vm != null)
vm.PropertyChanged += vm_PropertyChanged;
connection = vm?.Connection;
//do not call RefreshAll() here as it is called within the connection setter
}
get => vm;
}
private void AddSR(ToStringWrapper<SR> srWrapper)
{
@ -249,7 +251,7 @@ namespace XenAdmin.Controls
if (connection != null)
{
RegisterEvents();
refreshAll();
RefreshAll();
}
}
get
@ -267,12 +269,14 @@ namespace XenAdmin.Controls
internal virtual void DeregisterEvents()
{
if (vm != null)
vm.PropertyChanged -= vm_PropertyChanged;
if (connection == null)
return;
// deregister collection listener
connection.Cache.DeregisterCollectionChanged<SR>(SR_CollectionChangedWithInvoke);
// Remove SR listeners
foreach (SR sr in connection.Cache.SRs)
{
sr.PropertyChanged -= sr_PropertyChanged;
@ -283,7 +287,7 @@ namespace XenAdmin.Controls
}
}
protected void RegisterEvents()
private void RegisterEvents()
{
if (connection == null)
return;
@ -304,8 +308,7 @@ namespace XenAdmin.Controls
}
}
private readonly CollectionChangeEventHandler SR_CollectionChangedWithInvoke = null;
protected void SR_CollectionChanged(object sender, CollectionChangeEventArgs e)
private void SR_CollectionChanged(object sender, CollectionChangeEventArgs e)
{
Program.AssertOnEventThread();
@ -318,16 +321,28 @@ namespace XenAdmin.Controls
sr.PropertyChanged += sr_PropertyChanged;
}
Program.Invoke(this, refreshAll);
RefreshAll();
}
public virtual void refreshAll()
private void RefreshAll()
{
if (!DroppedDown)
{
RefreshSRs_();
BeginUpdate();
try
{
Items.Clear();
RefreshSRs();
}
finally
{
EndUpdate();
}
SelectCD();
refreshOnClose = false;
SrsRefreshed?.Invoke();
}
else
{
@ -339,7 +354,7 @@ namespace XenAdmin.Controls
{
if (e.PropertyName == "VDIs" || e.PropertyName == "PBDs")
{
refreshAll();
RefreshAll();
}
}
@ -347,23 +362,15 @@ namespace XenAdmin.Controls
{
if (e.PropertyName == "currently_attached")
{
refreshAll();
RefreshAll();
}
}
protected void cdrom_PropertyChanged(object sender1, PropertyChangedEventArgs e)
{
if ((e.PropertyName == "empty" || e.PropertyName == "vdi") && !changing)
{
SelectCD();
}
}
protected void vm_PropertyChanged(object sender1, PropertyChangedEventArgs e)
private void vm_PropertyChanged(object sender1, PropertyChangedEventArgs e)
{
if (e.PropertyName == "VBDs" || e.PropertyName == "resident_on" || e.PropertyName == "affinity")
{
refreshAll();
RefreshAll();
}
}
@ -371,8 +378,7 @@ namespace XenAdmin.Controls
{
base.OnSelectionChangeCommitted(e);
var selectedVdi = SelectedItem as ToStringWrapper<VDI>;
if (selectedVdi != null)
if (SelectedItem is ToStringWrapper<VDI> selectedVdi)
selectedCD = selectedVdi.item;
}
@ -409,7 +415,7 @@ namespace XenAdmin.Controls
base.OnDropDownClosed(e);
if (refreshOnClose)
refreshAll();
RefreshAll();
}
protected override bool IsItemNonSelectable(object o)

View File

@ -85,14 +85,10 @@ namespace XenAdmin.Controls
this.cdChanger1.connection = null;
resources.ApplyResources(this.cdChanger1, "cdChanger1");
this.cdChanger1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.cdChanger1.Drive = null;
this.cdChanger1.DropDownHeight = 500;
this.cdChanger1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.cdChanger1.Empty = true;
this.cdChanger1.FormattingEnabled = true;
this.cdChanger1.Name = "cdChanger1";
this.cdChanger1.SelectedCD = null;
this.cdChanger1.TheVM = null;
//
// linkLabel1
//

View File

@ -52,23 +52,21 @@ namespace XenAdmin.Controls
InitializeComponent();
}
private VM vm = null;
private VM vm;
public VM VM
{
set
{
DeregisterEvents();
cdChanger1.vm = value;
cdChanger1.VM = value;
vm = value;
if (vm != null)
{
vm.PropertyChanged += new PropertyChangedEventHandler(vm_PropertyChanged);
}
vm.PropertyChanged += vm_PropertyChanged;
refreshDrives();
}
get
{
return cdChanger1.vm;
return cdChanger1.VM;
}
}
@ -250,7 +248,7 @@ namespace XenAdmin.Controls
if (inRefresh)
return;
cdChanger1.Drive = comboBoxDrive.SelectedItem != null ? ((VbdCombiItem)comboBoxDrive.SelectedItem).vbd : null;
cdChanger1.Drive = (comboBoxDrive.SelectedItem as VbdCombiItem)?.vbd;
}

View File

@ -239,14 +239,6 @@ namespace XenAdmin.Wizards.NewVMWizard
page_4_HomeServer.DisableStep = false;
}
// if custom template has no cd drive (must have been removed via cli) don't add one
var noInstallMedia = Helpers.CustomWithNoDVD(selectedTemplate);
if (selectedTemplate != null && selectedTemplate.DefaultTemplate() && string.IsNullOrEmpty(selectedTemplate.InstallMethods()))
noInstallMedia = true;
page_3_InstallationMedia.ShowInstallationMedia = !noInstallMedia;
// The user cannot set their own affinity, use the one off the template
if (BlockAffinitySelection)
m_affinity = xenConnection.Resolve(selectedTemplate.affinity);

View File

@ -60,7 +60,7 @@ namespace XenAdmin.Wizards.NewVMWizard
this.CdRadioButton.Name = "CdRadioButton";
this.CdRadioButton.TabStop = true;
this.CdRadioButton.UseVisualStyleBackColor = true;
this.CdRadioButton.CheckedChanged += new System.EventHandler(this.PhysicalRadioButton_CheckedChanged);
this.CdRadioButton.CheckedChanged += new System.EventHandler(this.CdRadioButton_CheckedChanged);
//
// UrlRadioButton
//
@ -101,15 +101,19 @@ namespace XenAdmin.Wizards.NewVMWizard
this.CdDropDownBox.connection = null;
this.CdDropDownBox.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.CdDropDownBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.CdDropDownBox.Empty = false;
this.CdDropDownBox.FormattingEnabled = true;
this.CdDropDownBox.Name = "CdDropDownBox";
this.CdDropDownBox.SelectedCD = null;
this.CdDropDownBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.CdDropDownBox_DrawItem);
this.CdDropDownBox.SelectedIndexChanged += new System.EventHandler(this.CdDropDownBox_SelectedIndexChanged);
this.CdDropDownBox.DropDownClosed += new System.EventHandler(this.CdDropDownBox_DropDownClosed);
this.CdDropDownBox.Enter += new System.EventHandler(this.CdDropDownBox_Enter);
//
// UrlTextBox
//
resources.ApplyResources(this.UrlTextBox, "UrlTextBox");
this.UrlTextBox.Name = "UrlTextBox";
this.UrlTextBox.TextChanged += new System.EventHandler(this.UrlTextBox_TextChanged);
this.UrlTextBox.Enter += new System.EventHandler(this.UrlTextBox_Enter);
//
// panelInstallationMethod
//

View File

@ -36,9 +36,6 @@ using XenAdmin.Actions.VMActions;
using XenAPI;
using XenAdmin.Controls;
using XenAdmin.Core;
using System.Diagnostics;
using XenAdmin.Actions;
using XenAdmin.Dialogs;
using XenCenterLib;
using System.Windows.Forms;
using System.Drawing;
@ -48,152 +45,73 @@ namespace XenAdmin.Wizards.NewVMWizard
{
public partial class Page_InstallationMedia : XenTabPage
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
private VM m_template;
public Page_InstallationMedia()
{
InitializeComponent();
CdDropDownBox.SrsRefreshed += CdDropDownBox_SrsRefreshed;
}
bool defaultTemplate, userTemplate, hvm, eli, installMethods, installCd, installUrl, cds, installed;
#region Accessors
public Host Affinity { private get; set; }
public bool ShowInstallationMedia { private get; set; }
public BootMode SelectedBootMode => SelectedTemplate.IsHVM()
? bootModesControl1.SelectedOption
: BootMode.NOT_AVAILABLE;
public bool IsSelectedTemplateHVM { get { return SelectedTemplate.IsHVM(); } }
protected override void PageLoadedCore(PageLoadedDirection direction)
public InstallMethod SelectedInstallMethod
{
VM oldTemplate = m_template;
m_template = SelectedTemplate;
// We only want to do all these updates if the template has changed (or has gone from null -> selected)
if (oldTemplate == m_template)
return;
/* This method is supposed to do the following:
*
* PV -> Install from DVD drive (no empty)
* Url
*
* HVM -> Install from DVD drive (no empty)
* Boot from network
*
* Custom -> DVD drive (inc empty)
*
* Disable Installation method section if the custom template has no DVD drive (except debian etch template)
*/
PvBootBox.Visible = !IsSelectedTemplateHVM;
PvBootTextBox.Text = m_template.PV_args;
bootModesControl1.Visible = IsSelectedTemplateHVM &&
BootModesControl.ShowBootModeOptions(SelectedTemplate.Connection);
;
bootModesControl1.TemplateVM = m_template;
if (!ShowInstallationMedia)
get
{
CdRadioButton.Checked = UrlRadioButton.Checked = false;
CdDropDownBox.Items.Clear();
UrlTextBox.Text = string.Empty;
panelInstallationMethod.Enabled = false;
return;
}
panelInstallationMethod.Enabled = true;
if (CdRadioButton.Enabled && CdRadioButton.Checked)
return InstallMethod.CD;
defaultTemplate = m_template.DefaultTemplate();
userTemplate = !defaultTemplate;
if (UrlRadioButton.Enabled && UrlRadioButton.Checked)
return InstallMethod.Network;
return InstallMethod.None;
}
}
public string SelectedPvArgs => SelectedTemplate.IsHVM() ? string.Empty : PvBootTextBox.Text;
public VDI SelectedCD => CdRadioButton.Enabled && CdRadioButton.Checked
? CdDropDownBox.SelectedCD
: null;
public string SelectedUrl => UrlRadioButton.Enabled && UrlRadioButton.Checked && UrlTextBox.Visible
? UrlTextBox.Text
: string.Empty;
public VM SelectedTemplate { private get; set; }
#endregion
private void AnalyseTemplate(out bool isUserTemplate, out bool hvm, out bool eli,
out string installMethods, out bool installCd, out bool installUrl)
{
isUserTemplate = !m_template.DefaultTemplate();
hvm = m_template.IsHVM();
eli = !hvm && m_template.PV_bootloader == "eliloader";
installMethods = m_template.InstallMethods();
installCd = installMethods != null && installMethods.Contains("cdrom");
installUrl = installMethods != null &&
(installMethods.Contains("http") || installMethods.Contains("ftp") || installMethods.Contains("nfs"));
}
var tmplMethods = m_template.InstallMethods();
installMethods = !string.IsNullOrEmpty(tmplMethods);
installCd = installMethods && tmplMethods.Contains("cdrom") && (hvm || eli);
installUrl = installMethods &&
(tmplMethods.Contains("http") || tmplMethods.Contains("ftp") || tmplMethods.Contains("nfs")) &&
eli;
cds = Helpers.CDsExist(Connection);
installed = userTemplate || !installMethods;
CdRadioButton.Text = installed ? Messages.NEWVMWIZARD_INSTALLMEDIA_DVD : Messages.NEWVMWIZARD_INSTALLMEDIA_INSTALLDVD;
CdRadioButton.Enabled = (installed || installCd) && cds;
CdDropDownBox.Empty = installed;
UrlRadioButton.Text = hvm ? Messages.NEWVMWIZARD_INSTALLMEDIA_INSTALLPXE : Messages.NEWVMWIZARD_INSTALLMEDIA_INSTALLURL;
UrlRadioButton.Enabled = (!installed && ((eli && installUrl) || hvm));
UrlTextBox.Visible = !hvm;
UrlTextBox.Text = !installed ? m_template.InstallRepository() ?? "" : "";
if (installed || (installCd && cds)) // if installed we will always have the empty cd
{
CdRadioButton.Checked = true;
CdDropDownBox.Select();
}
else if (eli && installUrl)
{
UrlRadioButton.Checked = true;
UrlTextBox.Select();
}
else
{
// oh dear, select anything that is enabled
if (CdRadioButton.Enabled)
CdRadioButton.Checked = true;
else if (UrlRadioButton.Enabled)
UrlRadioButton.Checked = true;
else
Trace.Assert(false, string.Format("No install options were enabled, something is wrong with the template '{0}'", m_template.Name()));
}
if(IsBootFromNetworkCustomTemplate(userTemplate))
{
UrlRadioButton.Enabled = true;
UrlRadioButton.Checked = true;
private void EnableCdRadioButton(bool isUserTemplate, bool hvm, bool eli, string installMethods, bool installCd)
{
if (isUserTemplate && m_template.GetBootOrder().StartsWith("N"))
CdRadioButton.Enabled = false;
}
LoadCdBox();
UpdateEnablement();
else
CdRadioButton.Enabled = isUserTemplate || string.IsNullOrEmpty(installMethods) || installCd && (hvm || eli);
}
public BootMode SelectedBootMode { get { return IsSelectedTemplateHVM ? bootModesControl1.SelectedOption : BootMode.NOT_AVAILABLE; } }
private bool IsBootFromNetworkCustomTemplate(bool userTemplate)
{
return (userTemplate && m_template.GetBootOrder().StartsWith("N"));
}
private void LoadCdBox()
{
CdDropDownBox.vm = m_template;
CdDropDownBox.refreshAll();
RegisterBespokeEventsAgainstCdDropDownBox();
VBD cddrive = m_template.FindVMCDROM();
VDI cd = cddrive != null && !cddrive.empty
? Connection.Resolve<VDI>(cddrive.VDI)
: (CdDropDownBox.Empty ? null : GetAffinityDvdDrive());
if (cd == null)
return; // select default whatever that is
SR sr = Connection.Resolve<SR>(cd.SR);
if (sr == null)
return; // select default whatever that is
CdDropDownBox.SelectedCD = cd;
CdDropDownBox.SelectCD();
}
public VDI GetAffinityDvdDrive()
private VDI GetAffinityDvdDrive()
{
if (Affinity == null || Affinity.Connection == null)
return null;
@ -206,67 +124,114 @@ namespace XenAdmin.Wizards.NewVMWizard
return null;
}
public InstallMethod SelectedInstallMethod
#region XenTabPage overrides
protected override void PageLoadedCore(PageLoadedDirection direction)
{
get
if (m_template == SelectedTemplate)
return;
/* This method is supposed to do the following:
*
* PV -> Install from DVD drive (selecting <empty> disables Next)
* -> Url
*
* HVM -> Install from DVD drive (selecting <empty> disables Next)
* -> Boot from network
*
* Custom with DVD drive -> DVD drive (selecting <empty> does not disable Next)
*
* Custom without DVD drive -> Disable Installation method section
*/
m_template = SelectedTemplate;
AnalyseTemplate(out bool isUserTemplate, out bool hvm, out bool eli,
out string installMethods, out bool installCd, out bool installUrl);
VBD cdDrive = m_template.FindVMCDROM();
PvBootBox.Visible = !hvm;
PvBootTextBox.Text = hvm ? string.Empty : m_template.PV_args;
bootModesControl1.Visible = hvm && BootModesControl.ShowBootModeOptions(SelectedTemplate.Connection);
bootModesControl1.TemplateVM = m_template;
if (isUserTemplate && cdDrive == null ||
!isUserTemplate && string.IsNullOrEmpty(m_template.InstallMethods()))
{
if (!ShowInstallationMedia || m_template.DefaultTemplate() && String.IsNullOrEmpty(m_template.InstallMethods()))
return InstallMethod.None;
if (CdRadioButton.Checked)
return InstallMethod.CD;
if (UrlRadioButton.Checked)
return InstallMethod.Network;
return InstallMethod.None;
CdRadioButton.Checked = UrlRadioButton.Checked = false;
CdDropDownBox.Items.Clear();
UrlTextBox.Text = string.Empty;
panelInstallationMethod.Enabled = false;
OnPageUpdated();
return;
}
}
public string SelectedPvArgs
{
get
panelInstallationMethod.Enabled = true;
CdRadioButton.Text = isUserTemplate || string.IsNullOrEmpty(installMethods)
? Messages.NEWVMWIZARD_INSTALLMEDIA_DVD
: Messages.NEWVMWIZARD_INSTALLMEDIA_INSTALLDVD;
EnableCdRadioButton(isUserTemplate, hvm, eli, installMethods, installCd);
CdDropDownBox.Enabled = CdRadioButton.Enabled;
UrlRadioButton.Text = hvm ? Messages.NEWVMWIZARD_INSTALLMEDIA_INSTALLPXE : Messages.NEWVMWIZARD_INSTALLMEDIA_INSTALLURL;
UrlRadioButton.Enabled = isUserTemplate && m_template.GetBootOrder().StartsWith("N") ||
!isUserTemplate && !string.IsNullOrEmpty(installMethods) && (hvm || eli && installUrl);
UrlTextBox.Enabled = UrlRadioButton.Enabled;
UrlTextBox.Visible = !hvm;
UrlTextBox.Text = isUserTemplate || string.IsNullOrEmpty(installMethods) ? "" : m_template.InstallRepository() ?? "";
if (CdRadioButton.Enabled)
{
return !IsSelectedTemplateHVM ? PvBootTextBox.Text : string.Empty;
CdRadioButton.Checked = true;
CdDropDownBox.Select();
}
}
public VDI SelectedCD
{
get
else if (UrlRadioButton.Enabled)
{
return ShowInstallationMedia && CdRadioButton.Checked ? CdDropDownBox.SelectedCD : null;
UrlRadioButton.Checked = true;
UrlTextBox.Select();
}
}
public string SelectedUrl
{
get
{
return ShowInstallationMedia && UrlRadioButton.Checked ? UrlTextBox.Text : string.Empty;
}
}
CdDropDownBox.VM = m_template;
public VM SelectedTemplate { private get; set; }
VDI cd = null;
if (cdDrive != null && !cdDrive.empty)
cd = Connection.Resolve(cdDrive.VDI);
else if (!isUserTemplate && !string.IsNullOrEmpty(installMethods))
cd = GetAffinityDvdDrive();
CdDropDownBox.SelectedCD = cd != null && Connection.Resolve(cd.SR) != null ? cd : null;
OnPageUpdated();
}
public override bool EnableNext()
{
return ShowInstallationMedia ? CdRadioButton.Checked || UrlRadioButton.Checked : true;
if (!panelInstallationMethod.Enabled)
return true;
if (CdRadioButton.Enabled && CdRadioButton.Checked)
return !m_template.DefaultTemplate() ||
string.IsNullOrEmpty(m_template.InstallMethods()) ||
CdDropDownBox.SelectedCD != null;
if (UrlRadioButton.Enabled && UrlRadioButton.Checked)
return !UrlTextBox.Visible || !string.IsNullOrEmpty(UrlTextBox.Text);
return false;
}
public override string Text
{
get { return Messages.NEWVMWIZARD_INSTALLATIONMEDIAPAGE_NAME; }
}
public override string Text => Messages.NEWVMWIZARD_INSTALLATIONMEDIAPAGE_NAME;
public override string PageTitle
{
get { return Messages.NEWVMWIZARD_INSTALLATIONMEDIAPAGE_TITLE; }
}
public override string PageTitle => Messages.NEWVMWIZARD_INSTALLATIONMEDIAPAGE_TITLE;
public override string HelpID
{
get { return "InstallationMedia"; }
}
public override string HelpID => "InstallationMedia";
public override List<KeyValuePair<string, string>> PageSummary
{
@ -284,84 +249,69 @@ namespace XenAdmin.Wizards.NewVMWizard
sum.Add(new KeyValuePair<string, string>(Messages.NEWVMWIZARD_NETWORKMEDIAPAGE_INSTALLATIONURL, SelectedUrl));
break;
}
if (Helpers.NaplesOrGreater(SelectedTemplate.Connection) && IsSelectedTemplateHVM)
if (Helpers.NaplesOrGreater(SelectedTemplate.Connection) && SelectedTemplate.IsHVM())
sum.Add(new KeyValuePair<string, string>(Messages.BOOT_MODE, SelectedBootMode.StringOf()));
return sum;
}
}
private void UpdateEnablement()
{
CdDropDownBox.Enabled = CdRadioButton.Checked;
UrlTextBox.Enabled = UrlRadioButton.Checked;
#endregion
OnPageUpdated();
}
private void PhysicalRadioButton_CheckedChanged(object sender, EventArgs e)
#region Event Handlers
private void CdRadioButton_CheckedChanged(object sender, EventArgs e)
{
UpdateEnablement();
if (CdRadioButton.Checked)
OnPageUpdated();
}
private void UrlRadioButton_CheckedChanged(object sender, EventArgs e)
{
UpdateEnablement();
if (UrlRadioButton.Checked)
OnPageUpdated();
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
NewSRWizard wizard = new NewSRWizard(Connection);
wizard.CheckNFSISORadioButton();
CdRadioButton.Enabled = CdDropDownBox.Enabled = false; //disable until the SRs are refreshed
if (wizard.ShowDialog() == DialogResult.Cancel)
return;
// Return if we lost connection
if (Connection == null || Helpers.GetPoolOfOne(Connection) == null)
using (var wizard = new NewSRWizard(Connection))
{
log.Error("Page_InstallationMedia: connection to the server was lost");
return;
wizard.CheckNFSISORadioButton();
if (wizard.ShowDialog() == DialogResult.Cancel)
CdDropDownBox_SrsRefreshed();
}
// There's a chance the cd radio button was disabled because we didnt have any isos to select from, so refresh that bool
// and the enablement of that button.
cds = Helpers.CDsExist(Connection);
CdRadioButton.Enabled = (installed || installCd) && cds;
// We can get a lot of refresh flickering in the ISO box as all the VDIs are discovered
// Possibly slightly rude, but were going to have a pretend action here which gives it some breathing space before we look for VDIs
DelegatedAsyncAction waitAction = new DelegatedAsyncAction(Connection, Messages.SR_REFRESH_ACTION_TITLE, Messages.SR_REFRESH_ACTION_DESC, Messages.COMPLETED,
delegate
{
System.Threading.Thread.Sleep(10000);
}, true);
using (var dlg = new ActionProgressDialog(waitAction, System.Windows.Forms.ProgressBarStyle.Marquee))
dlg.ShowDialog(this);
// Set the connection on the drop down iso box. This causes a complete refresh rather than a mini one - otherwise we miss out on
// getting event handlers for the new SR
CdDropDownBox.connection = Connection;
}
private void RegisterBespokeEventsAgainstCdDropDownBox()
private void CdDropDownBox_SrsRefreshed()
{
CdDropDownBox.DrawMode = DrawMode.OwnerDrawFixed;
CdDropDownBox.DrawItem += AddToolTipToCdDropDownBox_DrawItemEvent;
CdDropDownBox.DropDownClosed += HideToolTipOnCdDropDownBox_DropDownClosedEvent;
AnalyseTemplate(out bool isUserTemplate, out bool hvm, out bool eli,
out string installMethods, out bool installCd, out bool _);
EnableCdRadioButton(isUserTemplate, hvm, eli, installMethods, installCd);
CdDropDownBox.Enabled = CdRadioButton.Enabled;
OnPageUpdated();
}
private void HideToolTipOnCdDropDownBox_DropDownClosedEvent(object sender, EventArgs e)
private void CdDropDownBox_DropDownClosed(object sender, EventArgs e)
{
comboBoxToolTip.Hide(CdDropDownBox);
}
private void AddToolTipToCdDropDownBox_DrawItemEvent(object sender, DrawItemEventArgs e)
private void CdDropDownBox_DrawItem(object sender, DrawItemEventArgs e)
{
string selectedText = "";
if (e.Index != -1)
selectedText = CdDropDownBox.GetItemText(CdDropDownBox.Items[e.Index]);
if (e.Index < 0 || e.Index > CdDropDownBox.Items.Count - 1)
{
comboBoxToolTip.Hide(CdDropDownBox);
return;
}
Font font = (e.Index != -1 && CdDropDownBox.Items[e.Index] is ToStringWrapper<SR>) ? Program.DefaultFontBold : Program.DefaultFont;
string selectedText = CdDropDownBox.GetItemText(CdDropDownBox.Items[e.Index]);
Font font = CdDropDownBox.Items[e.Index] is ToStringWrapper<SR> ? Program.DefaultFontBold : Program.DefaultFont;
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected &&
CdDropDownBox.DroppedDown &&
@ -371,9 +321,30 @@ namespace XenAdmin.Wizards.NewVMWizard
}
else
{
HideToolTipOnCdDropDownBox_DropDownClosedEvent(sender, e);
comboBoxToolTip.Hide(CdDropDownBox);
}
}
private void CdDropDownBox_Enter(object sender, EventArgs e)
{
CdRadioButton.Checked = true;
}
private void CdDropDownBox_SelectedIndexChanged(object sender, EventArgs e)
{
OnPageUpdated();
}
private void UrlTextBox_Enter(object sender, EventArgs e)
{
UrlRadioButton.Checked = true;
}
private void UrlTextBox_TextChanged(object sender, EventArgs e)
{
OnPageUpdated();
}
#endregion
}
}

View File

@ -142,7 +142,7 @@
<value>3, 3, 3, 3</value>
</data>
<data name="bootModesControl1.Size" type="System.Drawing.Size, System.Drawing">
<value>542, 149</value>
<value>542, 192</value>
</data>
<data name="bootModesControl1.TabIndex" type="System.Int32, mscorlib">
<value>7</value>
@ -250,7 +250,7 @@
<value>524, 70</value>
</data>
<data name="tableLayoutPanel2.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
<value>0</value>
</data>
<data name="&gt;&gt;tableLayoutPanel2.Name" xml:space="preserve">
<value>tableLayoutPanel2</value>
@ -307,7 +307,7 @@
<value>149, 17</value>
</data>
<data name="CdRadioButton.TabIndex" type="System.Int32, mscorlib">
<value>0</value>
<value>1</value>
</data>
<data name="CdRadioButton.Text" xml:space="preserve">
<value>Install from this &amp;DVD drive:</value>
@ -340,7 +340,7 @@
<value>122, 17</value>
</data>
<data name="UrlRadioButton.TabIndex" type="System.Int32, mscorlib">
<value>3</value>
<value>4</value>
</data>
<data name="UrlRadioButton.Text" xml:space="preserve">
<value>Install from this &amp;URL:</value>
@ -358,7 +358,7 @@
<value>3</value>
</data>
<data name="CdDropDownBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
<value>Left, Right</value>
</data>
<data name="CdDropDownBox.Location" type="System.Drawing.Point, System.Drawing">
<value>23, 69</value>
@ -370,7 +370,7 @@
<value>381, 21</value>
</data>
<data name="CdDropDownBox.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
<value>2</value>
</data>
<data name="&gt;&gt;CdDropDownBox.Name" xml:space="preserve">
<value>CdDropDownBox</value>
@ -385,7 +385,7 @@
<value>5</value>
</data>
<data name="UrlTextBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
<value>Left, Right</value>
</data>
<data name="UrlTextBox.Location" type="System.Drawing.Point, System.Drawing">
<value>23, 128</value>
@ -397,7 +397,7 @@
<value>381, 20</value>
</data>
<data name="UrlTextBox.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
<value>5</value>
</data>
<data name="&gt;&gt;UrlTextBox.Name" xml:space="preserve">
<value>UrlTextBox</value>
@ -411,33 +411,27 @@
<data name="&gt;&gt;UrlTextBox.ZOrder" xml:space="preserve">
<value>6</value>
</data>
<data name="linkLabelAttachNewIsoStore.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Left</value>
</data>
<data name="linkLabelAttachNewIsoStore.AutoSize" type="System.Boolean, mscorlib">
<value>True</value>
</data>
<data name="linkLabelAttachNewIsoStore.Dock" type="System.Windows.Forms.DockStyle, System.Windows.Forms">
<value>Fill</value>
</data>
<data name="linkLabelAttachNewIsoStore.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="linkLabelAttachNewIsoStore.Location" type="System.Drawing.Point, System.Drawing">
<value>419, 66</value>
</data>
<data name="linkLabelAttachNewIsoStore.Margin" type="System.Windows.Forms.Padding, System.Windows.Forms">
<value>12, 0, 3, 0</value>
<value>410, 73</value>
</data>
<data name="linkLabelAttachNewIsoStore.Size" type="System.Drawing.Size, System.Drawing">
<value>123, 27</value>
<value>89, 13</value>
</data>
<data name="linkLabelAttachNewIsoStore.TabIndex" type="System.Int32, mscorlib">
<value>2</value>
<value>3</value>
</data>
<data name="linkLabelAttachNewIsoStore.Text" xml:space="preserve">
<value>New ISO library...</value>
</data>
<data name="linkLabelAttachNewIsoStore.TextAlign" type="System.Drawing.ContentAlignment, System.Drawing">
<value>MiddleLeft</value>
</data>
<data name="&gt;&gt;linkLabelAttachNewIsoStore.Name" xml:space="preserve">
<value>linkLabelAttachNewIsoStore</value>
</data>
@ -463,10 +457,10 @@
<value>8</value>
</data>
<data name="panelInstallationMethod.Size" type="System.Drawing.Size, System.Drawing">
<value>548, 418</value>
<value>548, 464</value>
</data>
<data name="panelInstallationMethod.TabIndex" type="System.Int32, mscorlib">
<value>1</value>
<value>0</value>
</data>
<data name="&gt;&gt;panelInstallationMethod.Name" xml:space="preserve">
<value>panelInstallationMethod</value>
@ -520,7 +514,7 @@
<value>96, 96</value>
</data>
<data name="$this.Size" type="System.Drawing.Size, System.Drawing">
<value>548, 418</value>
<value>548, 464</value>
</data>
<data name="&gt;&gt;comboBoxToolTip.Name" xml:space="preserve">
<value>comboBoxToolTip</value>

View File

@ -1597,23 +1597,6 @@ namespace XenAdmin.Core
} while (true);
}
public static bool CDsExist(IXenConnection connection)
{
if (connection == null)
return false;
foreach (SR sr in connection.Cache.SRs)
{
if (sr.content_type != SR.Content_Type_ISO)
continue;
if (sr.VDIs.Count > 0)
return true;
}
return false;
}
public static bool CompareLists<T>(List<T> l1, List<T> l2)
{
if (l1 == l2)