Code repetition.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2016-10-14 12:21:59 +01:00
parent fb281e65ac
commit 0b3d3abfcc
4 changed files with 21 additions and 79 deletions

View File

@ -55,7 +55,7 @@ namespace XenAdmin.Commands
Pool poolAncestor = selection.PooAncestorFromConnection;
if ((poolAncestor != null || hostAncestor != null) //CA-61207: this check ensures there's no cross-pool selection
&& (selection.FirstIsPool || selection.FirstIsHost || selection.FirstIsRealVM || selection.FirstIsVMappliance))
&& (selection.FirstIs<Pool>() || selection.FirstIs<Host>() || selection.FirstIsRealVM || selection.FirstIs<VM_appliance>()))
{
if (selection.AllItemsAre<VM>())
return selection.AtLeastOneXenObjectCan<VM>(CanExportVm);

View File

@ -261,25 +261,11 @@ namespace XenAdmin.Commands
}
/// <summary>
/// Gets a value indicating whether the first item is a pool.
/// Gets a value indicating whether the first item is a T.
/// </summary>
public bool FirstIsPool
public bool FirstIs<T>() where T : IXenObject
{
get
{
return First is Pool;
}
}
/// <summary>
/// Gets a value indicating whether the first item is a host.
/// </summary>
public bool FirstIsHost
{
get
{
return First is Host;
}
return First is T;
}
/// <summary>
@ -289,29 +275,7 @@ namespace XenAdmin.Commands
{
get
{
return FirstIsHost && ((Host)this[0].XenObject).IsLive;
}
}
/// <summary>
/// Gets a value indicating whether the first item is a VM.
/// </summary>
public bool FirstIsVM
{
get
{
return First is VM;
}
}
/// <summary>
/// Gets a value indicating whether the first item is a SR.
/// </summary>
public bool FirstIsSR
{
get
{
return First is SR;
return FirstIs<Host>() && ((Host)this[0].XenObject).IsLive;
}
}
@ -322,7 +286,7 @@ namespace XenAdmin.Commands
{
get
{
return FirstIsVM && !((VM)this[0].XenObject).is_a_template;
return FirstIs<VM>() && !((VM)this[0].XenObject).is_a_template;
}
}
@ -333,29 +297,7 @@ namespace XenAdmin.Commands
{
get
{
return FirstIsVM && ((VM)this[0].XenObject).is_a_template && !((VM)this[0].XenObject).is_a_snapshot;
}
}
/// <summary>
/// Gets a value indicating whether the first item is a VM_appliance.
/// </summary>
public bool FirstIsVMappliance
{
get
{
return First is VM_appliance;
}
}
/// <summary>
/// Gets a value indicating whether the first item is a GroupingTag.
/// </summary>
public bool FirstIsGroup
{
get
{
return First is GroupingTag;
return FirstIs<VM>() && ((VM)this[0].XenObject).is_a_template && !((VM)this[0].XenObject).is_a_snapshot;
}
}

View File

@ -249,7 +249,7 @@ namespace XenAdmin
if (SelectionManager.Selection.FirstIsRealVM)
ConsolePanel.setCurrentSource((VM)SelectionManager.Selection.First);
else if (SelectionManager.Selection.FirstIsHost)
else if (SelectionManager.Selection.FirstIs<Host>())
ConsolePanel.setCurrentSource((Host)SelectionManager.Selection.First);
UnpauseVNC(sender == TheTabControl);
@ -1375,10 +1375,10 @@ namespace XenAdmin
bool multi = SelectionManager.Selection.Count > 1;
bool isPoolSelected = SelectionManager.Selection.FirstIsPool;
bool isVMSelected = SelectionManager.Selection.FirstIsVM;
bool isHostSelected = SelectionManager.Selection.FirstIsHost;
bool isSRSelected = SelectionManager.Selection.FirstIsSR;
bool isPoolSelected = SelectionManager.Selection.FirstIs<Pool>();
bool isVMSelected = SelectionManager.Selection.FirstIs<VM>();
bool isHostSelected = SelectionManager.Selection.FirstIs<Host>();
bool isSRSelected = SelectionManager.Selection.FirstIs<SR>();
bool isRealVMSelected = SelectionManager.Selection.FirstIsRealVM;
bool isTemplateSelected = SelectionManager.Selection.FirstIsTemplate;
bool isHostLive = SelectionManager.Selection.FirstIsLiveHost;
@ -1774,7 +1774,7 @@ namespace XenAdmin
ConsolePanel.setCurrentSource((VM)SelectionManager.Selection.First);
UnpauseVNC(e != null && sender == TheTabControl);
}
else if (SelectionManager.Selection.FirstIsHost)
else if (SelectionManager.Selection.FirstIs<Host>())
{
ConsolePanel.setCurrentSource((Host)SelectionManager.Selection.First);
UnpauseVNC(e != null && sender == TheTabControl);
@ -1782,7 +1782,7 @@ namespace XenAdmin
}
else if (t == TabPageCvmConsole)
{
if (SelectionManager.Selection.FirstIsHost)
if (SelectionManager.Selection.FirstIs<Host>())
{
CvmConsolePanel.setCurrentSource((Host)SelectionManager.Selection.First);
UnpauseVNC(e != null && sender == TheTabControl);
@ -2451,21 +2451,21 @@ namespace XenAdmin
if (TheTabControl.SelectedTab == TabPagePhysicalStorage || TheTabControl.SelectedTab == TabPageStorage || TheTabControl.SelectedTab == TabPageSR)
{
if (SelectionManager.Selection.FirstIsPool)
if (SelectionManager.Selection.FirstIs<Pool>())
return "Pool";
if (SelectionManager.Selection.FirstIsHost)
if (SelectionManager.Selection.FirstIs<Host>())
return "Server";
if (SelectionManager.Selection.FirstIsVM)
if (SelectionManager.Selection.FirstIs<VM>())
return "VM";
if (SelectionManager.Selection.FirstIsSR)
if (SelectionManager.Selection.FirstIs<SR>())
return "Storage";
}
if (TheTabControl.SelectedTab == TabPageNetwork)
{
if (SelectionManager.Selection.FirstIsHost)
if (SelectionManager.Selection.FirstIs<Host>())
return "Server";
if (SelectionManager.Selection.FirstIsVM)
if (SelectionManager.Selection.FirstIs<VM>())
return "VM";
}

View File

@ -138,7 +138,7 @@ namespace XenAdmin.Wizards.ExportWizard
m_dataGridView.Rows.Clear();
var applianceVMs = new List<XenRef<VM>>();
if (SelectedItems != null && SelectedItems.FirstIsVMappliance)
if (SelectedItems != null && SelectedItems.FirstIs<VM_appliance>())
applianceVMs.AddRange(((VM_appliance)SelectedItems.FirstAsXenObject).VMs);
foreach (var vm in Connection.Cache.VMs.Where(vm => IsVmExportable(vm) && MatchesSearchText(vm)))