The Reasoning filters should look for failures on the item passed in their constructor:

This is ensured when abstract class FailureFoundFor(IXenObject) is protected.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2022-04-28 20:18:20 +01:00
parent 8699f8803f
commit a8bb8a7baa
7 changed files with 30 additions and 44 deletions

View File

@ -68,10 +68,9 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters
canceled = true;
}
public override bool FailureFoundFor(IXenObject itemToFilterOn)
protected override bool FailureFoundFor(IXenObject itemToFilterOn)
{
Pool targetPool;
List<Host> targets = CollateHosts(itemToFilterOn, out targetPool);
List<Host> targets = CollateHosts(itemToFilterOn, out var targetPool);
foreach (VM vm in preSelectedVMs)
{

View File

@ -49,7 +49,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters
this.preSelectedVMs = preSelectedVMs;
}
public override bool FailureFoundFor(IXenObject itemToFilterOn)
protected override bool FailureFoundFor(IXenObject itemToFilterOn)
{
var residentHosts = from VM vm in preSelectedVMs
let home = vm.Home()

View File

@ -50,7 +50,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard.Filters
this.preSelectedVMs = preSelectedVMs;
}
public override bool FailureFoundFor(IXenObject itemToFilterOn)
protected override bool FailureFoundFor(IXenObject itemToFilterOn)
{
bool targetWlb = false;

View File

@ -66,7 +66,7 @@ namespace XenAdmin.Wizards.GenericPages
public void CopyFrom(DelayLoadingOptionComboBoxItem toCopy)
{
xenObject = toCopy.xenObject;
xenObject = toCopy.Item;
failureReason = toCopy.FailureReason;
Enabled = toCopy.Enabled;
PreferAsSelectedItem = toCopy.PreferAsSelectedItem;
@ -75,10 +75,7 @@ namespace XenAdmin.Wizards.GenericPages
/// <summary>
/// Underlying Xen Object
/// </summary>
public IXenObject Item
{
get { return xenObject; }
}
public IXenObject Item => xenObject;
/// <summary>
/// You would prefer this item to be the one that is selected
@ -125,7 +122,18 @@ namespace XenAdmin.Wizards.GenericPages
{
try
{
FailureReason = FetchFailureReason();
var result = string.Empty;
foreach (ReasoningFilter filter in _filters)
{
if (filter.FailureFound)
{
result = filter.Reason;
break;
}
}
FailureReason = result;
return;
}
catch
@ -179,24 +187,5 @@ namespace XenAdmin.Wizards.GenericPages
return String.Format(Messages.DELAY_LOADED_COMBO_BOX_ITEM_FAILURE_REASON, Item.Name(), FailureReason);
}
/// <summary>
/// Fetch the reason from somewhere that may take some time
/// Called in a separate thread by the constructor
/// Returning String.Empty or null will mean no failure has been found
/// </summary>
/// <returns></returns>
protected virtual string FetchFailureReason()
{
foreach (ReasoningFilter filter in _filters)
{
if (filter.FailureFoundFor(Item))
{
return filter.Reason;
}
}
return string.Empty;
}
}
}

View File

@ -36,24 +36,21 @@ namespace XenAdmin.Wizards.GenericPages
{
public abstract class ReasoningFilter
{
private readonly IXenObject _baseItemToFilterOn;
protected ReasoningFilter(IXenObject itemToFilterOn)
{
if (!(itemToFilterOn is Host) && !(itemToFilterOn is Pool))
throw new ArgumentException("Target should be host or pool");
baseItemToFilterOn = itemToFilterOn;
_baseItemToFilterOn = itemToFilterOn;
}
/// <summary>
/// Base item that should be used to filter on
/// </summary>
private IXenObject baseItemToFilterOn { get; set; }
//public abstract bool FailureFound { get; }
public abstract string Reason { get; }
public abstract bool FailureFoundFor(IXenObject xenObject);
protected abstract bool FailureFoundFor(IXenObject xenObject);
public bool FailureFound => FailureFoundFor(baseItemToFilterOn);
public bool FailureFound => FailureFoundFor(_baseItemToFilterOn);
public virtual void Cancel() { }
}

View File

@ -388,7 +388,7 @@ namespace XenAdmin.Wizards.GenericPages
}
}
private void PopulateDataGridView(IEnableableXenObjectComboBoxItem selectedItem)
private void PopulateDataGridView()
{
Program.AssertOnEventThread();
@ -407,7 +407,6 @@ namespace XenAdmin.Wizards.GenericPages
{
var tb = new DataGridViewTextBoxCell {Value = kvp.Value.VmNameLabel, Tag = kvp.Key};
var cb = new DataGridViewEnableableComboBoxCell{FlatStyle = FlatStyle.Flat};
var homeserverFilters = CreateTargetServerFilterList(selectedItem, new List<string> {kvp.Key});
if (target != null)
{
@ -430,9 +429,11 @@ namespace XenAdmin.Wizards.GenericPages
var sortedHosts = new List<Host>(target.Item.Connection.Cache.Hosts);
sortedHosts.Sort();
var homeServerFilters = CreateTargetServerFilterList(target, new List<string> {kvp.Key});
foreach (var host in sortedHosts)
{
var item = new DelayLoadingOptionComboBoxItem(host, homeserverFilters);
var item = new DelayLoadingOptionComboBoxItem(host, homeServerFilters);
cb.Items.Add(item);
item.ParentComboBox = cb;
item.PreferAsSelectedItem = m_selectedObject != null && m_selectedObject.opaque_ref == host.opaque_ref ||
@ -630,8 +631,8 @@ namespace XenAdmin.Wizards.GenericPages
try
{
Cursor.Current = Cursors.WaitCursor;
ChosenItem = item == null ? null : item.Item;
PopulateDataGridView(item);
ChosenItem = item?.Item;
PopulateDataGridView();
}
finally
{

View File

@ -54,7 +54,7 @@ namespace XenAdmin.Wizards.ImportWizard.Filters
_hosts.AddRange(pool.Connection.Cache.Hosts);
}
public override bool FailureFoundFor(IXenObject itemToFilterOn)
protected override bool FailureFoundFor(IXenObject itemToFilterOn)
{
foreach (var setting in _hardwarePlatformSettings)
{