diff --git a/XenAdmin/Commands/ExportCommand.cs b/XenAdmin/Commands/ExportCommand.cs index cdf2cc511..36cdd7754 100644 --- a/XenAdmin/Commands/ExportCommand.cs +++ b/XenAdmin/Commands/ExportCommand.cs @@ -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() || selection.FirstIs() || selection.FirstIsRealVM || selection.FirstIs())) { if (selection.AllItemsAre()) return selection.AtLeastOneXenObjectCan(CanExportVm); diff --git a/XenAdmin/Commands/SelectedItemCollection.cs b/XenAdmin/Commands/SelectedItemCollection.cs index a20bf704c..63a740ad1 100644 --- a/XenAdmin/Commands/SelectedItemCollection.cs +++ b/XenAdmin/Commands/SelectedItemCollection.cs @@ -261,25 +261,11 @@ namespace XenAdmin.Commands } /// - /// Gets a value indicating whether the first item is a pool. + /// Gets a value indicating whether the first item is a T. /// - public bool FirstIsPool + public bool FirstIs() where T : IXenObject { - get - { - return First is Pool; - } - } - - /// - /// Gets a value indicating whether the first item is a host. - /// - public bool FirstIsHost - { - get - { - return First is Host; - } + return First is T; } /// @@ -289,29 +275,7 @@ namespace XenAdmin.Commands { get { - return FirstIsHost && ((Host)this[0].XenObject).IsLive; - } - } - - /// - /// Gets a value indicating whether the first item is a VM. - /// - public bool FirstIsVM - { - get - { - return First is VM; - } - } - - /// - /// Gets a value indicating whether the first item is a SR. - /// - public bool FirstIsSR - { - get - { - return First is SR; + return FirstIs() && ((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)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; - } - } - - /// - /// Gets a value indicating whether the first item is a VM_appliance. - /// - public bool FirstIsVMappliance - { - get - { - return First is VM_appliance; - } - } - - /// - /// Gets a value indicating whether the first item is a GroupingTag. - /// - public bool FirstIsGroup - { - get - { - return First is GroupingTag; + return FirstIs() && ((VM)this[0].XenObject).is_a_template && !((VM)this[0].XenObject).is_a_snapshot; } } diff --git a/XenAdmin/MainWindow.cs b/XenAdmin/MainWindow.cs index 982122032..419f22406 100644 --- a/XenAdmin/MainWindow.cs +++ b/XenAdmin/MainWindow.cs @@ -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()) 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(); + bool isVMSelected = SelectionManager.Selection.FirstIs(); + bool isHostSelected = SelectionManager.Selection.FirstIs(); + bool isSRSelected = SelectionManager.Selection.FirstIs(); 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()) { 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()) { 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()) return "Pool"; - if (SelectionManager.Selection.FirstIsHost) + if (SelectionManager.Selection.FirstIs()) return "Server"; - if (SelectionManager.Selection.FirstIsVM) + if (SelectionManager.Selection.FirstIs()) return "VM"; - if (SelectionManager.Selection.FirstIsSR) + if (SelectionManager.Selection.FirstIs()) return "Storage"; } if (TheTabControl.SelectedTab == TabPageNetwork) { - if (SelectionManager.Selection.FirstIsHost) + if (SelectionManager.Selection.FirstIs()) return "Server"; - if (SelectionManager.Selection.FirstIsVM) + if (SelectionManager.Selection.FirstIs()) return "VM"; } diff --git a/XenAdmin/Wizards/ExportWizard/ExportSelectVMsPage.cs b/XenAdmin/Wizards/ExportWizard/ExportSelectVMsPage.cs index 046d35c5a..39bb9115c 100644 --- a/XenAdmin/Wizards/ExportWizard/ExportSelectVMsPage.cs +++ b/XenAdmin/Wizards/ExportWizard/ExportSelectVMsPage.cs @@ -138,7 +138,7 @@ namespace XenAdmin.Wizards.ExportWizard m_dataGridView.Rows.Clear(); var applianceVMs = new List>(); - if (SelectedItems != null && SelectedItems.FirstIsVMappliance) + if (SelectedItems != null && SelectedItems.FirstIs()) applianceVMs.AddRange(((VM_appliance)SelectedItems.FirstAsXenObject).VMs); foreach (var vm in Connection.Cache.VMs.Where(vm => IsVmExportable(vm) && MatchesSearchText(vm)))