Replaced own method ConvertToSelection<T>() with Linq queries.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2020-09-12 23:40:27 +01:00
parent db89699bac
commit 0d10e1e53f
5 changed files with 22 additions and 81 deletions

View File

@ -112,20 +112,6 @@ namespace XenAdmin.Commands
{
}
/// <summary>
/// Gets a list of <see cref="SelectedItem"/>s from the specified <see cref="IXenObject"/>s.
/// </summary>
protected static IEnumerable<SelectedItem> ConvertToSelection<T>(IEnumerable<T> xenObjects) where T : IXenObject
{
Util.ThrowIfParameterNull(xenObjects, "selection");
List<SelectedItem> selection = new List<SelectedItem>();
foreach (T xenObject in xenObjects)
{
selection.Add(new SelectedItem(xenObject));
}
return selection;
}
/// <summary>
/// Gets the current selection context for the Command.
/// </summary>

View File

@ -30,6 +30,7 @@
*/
using System.Collections.Generic;
using System.Linq;
using XenAdmin.Actions;
using XenAdmin.Core;
using XenAPI;
@ -51,18 +52,18 @@ namespace XenAdmin.Commands
{
}
public DestroySRCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selection)
: base(mainWindow, selection)
public DestroySRCommand(IMainWindow mainWindow, IEnumerable<SelectedItem> selectedItems)
: base(mainWindow, selectedItems)
{
}
public DestroySRCommand(IMainWindow mainWindow, SR selection)
: base(mainWindow, selection)
public DestroySRCommand(IMainWindow mainWindow, SR sr)
: base(mainWindow, sr)
{
}
public DestroySRCommand(IMainWindow mainWindow, IEnumerable<SR> selection)
: base(mainWindow, ConvertToSelection(selection))
public DestroySRCommand(IMainWindow mainWindow, IEnumerable<SR> srs)
: base(mainWindow, srs.Select(s => new SelectedItem(s)).ToList())
{
}
@ -90,21 +91,9 @@ namespace XenAdmin.Commands
/// <summary>
/// Gets the text for a menu item which launches this Command.
/// </summary>
public override string MenuText
{
get
{
return Messages.MAINWINDOW_DESTROY_SR;
}
}
public override string MenuText => Messages.MAINWINDOW_DESTROY_SR;
protected override bool ConfirmationRequired
{
get
{
return true;
}
}
protected override bool ConfirmationRequired => true;
protected override string ConfirmationDialogText
{
@ -163,20 +152,8 @@ namespace XenAdmin.Commands
return base.GetCantExecuteReasonCore(item);
}
protected override string ConfirmationDialogYesButtonLabel
{
get
{
return Messages.MESSAGEBOX_DESTROY_SR_YES_BUTTON_LABEL;
}
}
protected override string ConfirmationDialogYesButtonLabel => Messages.MESSAGEBOX_DESTROY_SR_YES_BUTTON_LABEL;
protected override bool ConfirmationDialogNoButtonSelected
{
get
{
return true;
}
}
protected override bool ConfirmationDialogNoButtonSelected => true;
}
}

View File

@ -62,7 +62,7 @@ namespace XenAdmin.Commands
}
public InstallToolsCommand(IMainWindow mainWindow, IEnumerable<VM> vms)
: this(mainWindow, ConvertToSelection(vms))
: this(mainWindow, vms.Select(v => new SelectedItem(v)).ToList())
{
}

View File

@ -66,7 +66,7 @@ namespace XenAdmin.Commands
}
public RemoveHostFromPoolCommand(IMainWindow mainWindow, IEnumerable<Host> hosts)
: base(mainWindow, ConvertToSelection<Host>(hosts))
: base(mainWindow, hosts.Select(h => new SelectedItem(h)).ToList())
{
}

View File

@ -29,16 +29,12 @@
* SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Text;
using XenAdmin.Core;
using XenAPI;
using System.Windows.Forms;
using XenAdmin.Dialogs;
using XenAdmin.Properties;
using System.Drawing;
using System.Collections.ObjectModel;
using System.Linq;
using XenAdmin.Core;
using XenAdmin.Dialogs;
using XenAPI;
namespace XenAdmin.Commands
@ -66,8 +62,8 @@ namespace XenAdmin.Commands
{
}
public RepairSRCommand(IMainWindow mainWindow, IEnumerable<SR> selection)
: base(mainWindow, ConvertToSelection<SR>(selection))
public RepairSRCommand(IMainWindow mainWindow, IEnumerable<SR> srs)
: base(mainWindow, srs.Select(s => new SelectedItem(s)).ToList())
{
}
@ -94,28 +90,10 @@ namespace XenAdmin.Commands
return sr != null && sr.HasPBDs() && (sr.IsBroken() || !sr.MultipathAOK()) && !HelpersGUI.GetActionInProgress(sr) && sr.CanRepairAfterUpgradeFromLegacySL();
}
public override Image MenuImage
{
get
{
return Images.StaticImages._000_StorageBroken_h32bit_16;
}
}
public override Image MenuImage => Images.StaticImages._000_StorageBroken_h32bit_16;
public override string MenuText
{
get
{
return Messages.MAINWINDOW_REPAIR_SR;
}
}
public override string MenuText => Messages.MAINWINDOW_REPAIR_SR;
public override string ContextMenuText
{
get
{
return Messages.MAINWINDOW_REPAIR_SR_CONTEXT_MENU;
}
}
public override string ContextMenuText => Messages.MAINWINDOW_REPAIR_SR_CONTEXT_MENU;
}
}