mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2025-01-20 07:19:18 +01:00
Refactoring: removed three out of the classes deriving from the DelayLoadingOptionComboBoxItem
because the differentiation was in the filters, which can be passed in as parameters to the base class, and other than this they were only adding complexity. Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
61a2c12c45
commit
e6b2f9b293
@ -1,89 +0,0 @@
|
||||
/* Copyright (c) Citrix Systems Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms,
|
||||
* with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the
|
||||
* following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using XenAdmin.Wizards.CrossPoolMigrateWizard.Filters;
|
||||
using XenAdmin.Wizards.GenericPages;
|
||||
using XenAPI;
|
||||
|
||||
namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
||||
{
|
||||
|
||||
public class CrossPoolMigrateDelayLoadingComboBoxItem : DelayLoadingOptionComboBoxItem
|
||||
{
|
||||
private readonly Host preSelectedHost;
|
||||
private readonly List<VM> preSelectedVMs;
|
||||
private Queue<ReasoningFilter> filters;
|
||||
|
||||
/// <summary>
|
||||
/// Instantiate a delay loading combo box item for cross pool migrate
|
||||
/// </summary>
|
||||
/// <param name="itemAddedToComboBox">Item being added to the list</param>
|
||||
/// <param name="preSelectedHost">Host that was preselected by user prior to loading this item</param>
|
||||
/// <param name="preSelectedVMs">VMs selected prior to loading this item</param>
|
||||
public CrossPoolMigrateDelayLoadingComboBoxItem(IXenObject itemAddedToComboBox, Host preSelectedHost, List<VM> preSelectedVMs)
|
||||
: base(itemAddedToComboBox)
|
||||
{
|
||||
this.preSelectedHost = preSelectedHost;
|
||||
this.preSelectedVMs = preSelectedVMs;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FIFO of filters
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private void BuildFilterList()
|
||||
{
|
||||
filters = new Queue<ReasoningFilter>();
|
||||
filters.Enqueue(new CrossPoolMigrateVersionFilter(Item));
|
||||
filters.Enqueue(new ResidentHostIsSameAsSelectionFilter(Item, preSelectedVMs));
|
||||
filters.Enqueue(new CrossPoolMigrateCanMigrateFilter(Item, preSelectedVMs));
|
||||
filters.Enqueue(new WlbEnabledFilter(Item, preSelectedVMs));
|
||||
}
|
||||
|
||||
protected override string FetchFailureReason()
|
||||
{
|
||||
BuildFilterList();
|
||||
|
||||
foreach (ReasoningFilter filter in filters)
|
||||
{
|
||||
if (filter.FailureFound)
|
||||
{
|
||||
return filter.Reason;
|
||||
}
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
}
|
@ -40,7 +40,6 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
||||
{
|
||||
internal class CrossPoolMigrateDestinationPage : SelectMultipleVMDestinationPage
|
||||
{
|
||||
private Host preSelectedHost;
|
||||
private List<VM> selectedVMs;
|
||||
private WizardMode wizardMode;
|
||||
|
||||
@ -52,7 +51,6 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
||||
|
||||
public CrossPoolMigrateDestinationPage(Host preSelectedHost, List<VM> selectedVMs, WizardMode wizardMode, List<IXenConnection> ignoredConnections)
|
||||
{
|
||||
this.preSelectedHost = preSelectedHost;
|
||||
SetDefaultTarget(preSelectedHost);
|
||||
this.selectedVMs = selectedVMs;
|
||||
this.wizardMode = wizardMode;
|
||||
@ -132,10 +130,16 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
|
||||
|
||||
protected override string TargetServerSelectionIntroText { get { return Messages.CPM_WIZARD_DESTINATION_TABLE_INTRO; } }
|
||||
|
||||
|
||||
public override DelayLoadingOptionComboBoxItem CreateDelayLoadingOptionComboBoxItem(IXenObject xenItem)
|
||||
{
|
||||
return new CrossPoolMigrateDelayLoadingComboBoxItem(xenItem, preSelectedHost, selectedVMs);
|
||||
var filters = new List<ReasoningFilter>
|
||||
{
|
||||
new CrossPoolMigrateVersionFilter(xenItem),
|
||||
new ResidentHostIsSameAsSelectionFilter(xenItem, selectedVMs),
|
||||
new CrossPoolMigrateCanMigrateFilter(xenItem, selectedVMs),
|
||||
new WlbEnabledFilter(xenItem, selectedVMs)
|
||||
};
|
||||
return new DelayLoadingOptionComboBoxItem(xenItem, filters);
|
||||
}
|
||||
|
||||
protected override List<ReasoningFilter> CreateTargetServerFilterList(IEnableableXenObjectComboBoxItem selectedItem)
|
||||
|
@ -30,6 +30,7 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using XenAdmin.Controls;
|
||||
using XenAPI;
|
||||
@ -41,7 +42,7 @@ namespace XenAdmin.Wizards.GenericPages
|
||||
IXenObject Item { get; }
|
||||
}
|
||||
|
||||
public abstract class DelayLoadingOptionComboBoxItem : IEnableableXenObjectComboBoxItem
|
||||
public class DelayLoadingOptionComboBoxItem : IEnableableXenObjectComboBoxItem
|
||||
{
|
||||
public delegate void ReasonUpdatedEventHandler(object sender, EventArgs args);
|
||||
/// <summary>
|
||||
@ -52,14 +53,21 @@ namespace XenAdmin.Wizards.GenericPages
|
||||
private IXenObject xenObject;
|
||||
private const int defaultRetries = 10;
|
||||
private const int defaultTimeOut = 200;
|
||||
private readonly List<ReasoningFilter> _filters;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new class instance and starts a thread to load data
|
||||
/// </summary>
|
||||
/// <param name="xenObject"></param>
|
||||
protected DelayLoadingOptionComboBoxItem(IXenObject xenObject)
|
||||
public DelayLoadingOptionComboBoxItem(IXenObject xenObject)
|
||||
: this(xenObject, new List<ReasoningFilter>())
|
||||
{
|
||||
}
|
||||
|
||||
public DelayLoadingOptionComboBoxItem(IXenObject xenObject, List<ReasoningFilter> filters)
|
||||
{
|
||||
this.xenObject = xenObject;
|
||||
_filters = filters;
|
||||
}
|
||||
|
||||
public void CopyFrom(DelayLoadingOptionComboBoxItem toCopy)
|
||||
@ -126,19 +134,16 @@ namespace XenAdmin.Wizards.GenericPages
|
||||
}
|
||||
catch
|
||||
{
|
||||
if(retries <=0 )
|
||||
if (retries <= 0)
|
||||
{
|
||||
FailureReason = Messages.DELAY_LOADED_COMBO_BOX_ITEM_FAILURE_UNKOWN;
|
||||
return;
|
||||
}
|
||||
|
||||
Thread.Sleep(timeOut);
|
||||
}
|
||||
|
||||
} while (retries-- > 0);
|
||||
|
||||
FailureReason = threadFailureReason;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -157,10 +162,10 @@ namespace XenAdmin.Wizards.GenericPages
|
||||
/// Setter will trigger reason updated event
|
||||
/// If no failure result is found on setting set the enabled
|
||||
/// </summary>
|
||||
public string FailureReason
|
||||
private string FailureReason
|
||||
{
|
||||
get { return failureReason; }
|
||||
protected set
|
||||
set
|
||||
{
|
||||
if (failureReason == value)
|
||||
return;
|
||||
@ -190,6 +195,17 @@ namespace XenAdmin.Wizards.GenericPages
|
||||
/// Returning String.Empty or null will mean no failure has been found
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract string FetchFailureReason();
|
||||
protected virtual string FetchFailureReason()
|
||||
{
|
||||
foreach (ReasoningFilter filter in _filters)
|
||||
{
|
||||
if (filter.FailureFoundFor(Item))
|
||||
{
|
||||
return filter.Reason;
|
||||
}
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,93 +0,0 @@
|
||||
/* Copyright (c) Citrix Systems Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms,
|
||||
* with or without modification, are permitted provided
|
||||
* that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above
|
||||
* copyright notice, this list of conditions and the
|
||||
* following disclaimer.
|
||||
* * Redistributions in binary form must reproduce the above
|
||||
* copyright notice, this list of conditions and the
|
||||
* following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using XenAPI;
|
||||
|
||||
namespace XenAdmin.Wizards.GenericPages
|
||||
{
|
||||
public class HomeServerItem : DelayLoadingOptionComboBoxItem
|
||||
{
|
||||
private readonly List<ReasoningFilter> filters;
|
||||
|
||||
public HomeServerItem(IXenObject host, List<ReasoningFilter> filters)
|
||||
: base(host)
|
||||
{
|
||||
if(!(host is Host))
|
||||
{
|
||||
throw new ArgumentException("This class expects as IXenObject of type host");
|
||||
}
|
||||
|
||||
this.filters = filters;
|
||||
LoadAndWait();
|
||||
}
|
||||
|
||||
protected override string FetchFailureReason()
|
||||
{
|
||||
foreach (ReasoningFilter filter in filters)
|
||||
{
|
||||
if (filter.FailureFoundFor(Item))
|
||||
{
|
||||
return filter.Reason;
|
||||
}
|
||||
}
|
||||
|
||||
return String.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public class DoNotAssignHomeServerPoolItem : IEnableableXenObjectComboBoxItem
|
||||
{
|
||||
private readonly IXenObject pool;
|
||||
public DoNotAssignHomeServerPoolItem(IXenObject pool)
|
||||
{
|
||||
this.pool = pool;
|
||||
if(!(pool is Pool))
|
||||
throw new ArgumentException("This class epects as IXenObject of type pool");
|
||||
}
|
||||
|
||||
public IXenObject Item
|
||||
{
|
||||
get { return pool; }
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Messages.DONT_SELECT_TARGET_SERVER;
|
||||
}
|
||||
}
|
||||
}
|
@ -29,24 +29,33 @@
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
using XenAdmin.Wizards.GenericPages;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using XenAPI;
|
||||
|
||||
namespace XenAdmin.Wizards.ImportWizard
|
||||
namespace XenAdmin.Wizards.GenericPages
|
||||
{
|
||||
class ImportDelayLoadingOptionComboBoxItem : DelayLoadingOptionComboBoxItem
|
||||
public class NoTargetServerPoolItem : IEnableableXenObjectComboBoxItem
|
||||
{
|
||||
public ImportDelayLoadingOptionComboBoxItem(IXenObject xenObject) : base(xenObject)
|
||||
private readonly Pool pool;
|
||||
public NoTargetServerPoolItem(Pool pool)
|
||||
{
|
||||
this.pool = pool;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// No failure reason - all options are valid
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected override string FetchFailureReason()
|
||||
public IXenObject Item
|
||||
{
|
||||
return string.Empty;
|
||||
get { return pool; }
|
||||
}
|
||||
|
||||
public bool Enabled
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Messages.DONT_SELECT_TARGET_SERVER;
|
||||
}
|
||||
}
|
||||
}
|
@ -43,14 +43,10 @@ namespace XenAdmin.Wizards.GenericPages
|
||||
ItemToFilterOn = itemToFilterOn;
|
||||
}
|
||||
|
||||
protected ReasoningFilter()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Base item that should be used to filter on
|
||||
/// </summary>
|
||||
public IXenObject ItemToFilterOn { get; protected set; }
|
||||
protected IXenObject ItemToFilterOn { get; set; }
|
||||
public abstract bool FailureFound { get; }
|
||||
public abstract string Reason { get; }
|
||||
|
||||
@ -59,11 +55,5 @@ namespace XenAdmin.Wizards.GenericPages
|
||||
ItemToFilterOn = xenObject;
|
||||
return FailureFound;
|
||||
}
|
||||
|
||||
public KeyValuePair<bool, List<string>> Or(ReasoningFilter filter)
|
||||
{
|
||||
List<string> reasons = new List<string>{ Reason, filter.Reason };
|
||||
return new KeyValuePair<bool, List<string>>(FailureFound || filter.FailureFound, reasons);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ namespace XenAdmin.Wizards.GenericPages
|
||||
{
|
||||
foreach (var pool in Connection.Cache.Pools)
|
||||
{
|
||||
var item = new DoNotAssignHomeServerPoolItem(pool);
|
||||
var item = new NoTargetServerPoolItem(pool);
|
||||
cb.Items.Add(item);
|
||||
|
||||
if ((m_selectedObject != null && m_selectedObject.opaque_ref == pool.opaque_ref) ||
|
||||
@ -397,7 +397,8 @@ namespace XenAdmin.Wizards.GenericPages
|
||||
|
||||
foreach (var host in Connection.Cache.Hosts)
|
||||
{
|
||||
HomeServerItem item = new HomeServerItem(host, homeserverFilters);
|
||||
var item = new DelayLoadingOptionComboBoxItem(host, homeserverFilters);
|
||||
item.LoadAndWait();
|
||||
cb.Items.Add(item);
|
||||
|
||||
if ((m_selectedObject != null && m_selectedObject.opaque_ref == host.opaque_ref) ||
|
||||
|
@ -103,7 +103,7 @@ namespace XenAdmin.Wizards.ImportWizard
|
||||
|
||||
public override DelayLoadingOptionComboBoxItem CreateDelayLoadingOptionComboBoxItem(IXenObject xenItem)
|
||||
{
|
||||
return new ImportDelayLoadingOptionComboBoxItem(xenItem);
|
||||
return new DelayLoadingOptionComboBoxItem(xenItem);
|
||||
}
|
||||
|
||||
private List<Xen_ConfigurationSettingData_Type> FindVgpuSettings(EnvelopeType envelopeType)
|
||||
|
@ -3369,7 +3369,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Wizards\CrossPoolMigrateWizard\Filters\WlbEnabledFilter.cs" />
|
||||
<Compile Include="Wizards\ExportWizard\ApplianceChecks\ApplianceExistsCheck.cs" />
|
||||
<Compile Include="Wizards\GenericPages\HomeServerItem.cs" />
|
||||
<Compile Include="Wizards\GenericPages\NoTargetServerPoolItem.cs" />
|
||||
<Compile Include="Wizards\CrossPoolMigrateWizard\Filters\CrossPoolMigrateCanMigrateFilter.cs" />
|
||||
<Compile Include="Wizards\CrossPoolMigrateWizard\Filters\CrossPoolMigrateVersionFilter.cs" />
|
||||
<Compile Include="Wizards\CrossPoolMigrateWizard\CrossPoolMigrateDestinationPage.cs">
|
||||
@ -3395,7 +3395,6 @@
|
||||
</Compile>
|
||||
<Compile Include="Wizards\CrossPoolMigrateWizard\CrossPoolMigrationNetworkResource.cs" />
|
||||
<Compile Include="Wizards\CrossPoolMigrateWizard\CrossPoolMigrationStorageResource.cs" />
|
||||
<Compile Include="Wizards\CrossPoolMigrateWizard\CrossPoolMigrateDelayLoadingComboBoxItem.cs" />
|
||||
<Compile Include="Wizards\CrossPoolMigrateWizard\Filters\ResidentHostIsSameAsSelectionFilter.cs" />
|
||||
<Compile Include="Wizards\DRWizards\DRFailoverWizard.cs">
|
||||
<SubType>Form</SubType>
|
||||
@ -3474,7 +3473,6 @@
|
||||
<Compile Include="Wizards\GenericPages\ReasoningFilter.cs" />
|
||||
<Compile Include="Wizards\GenericPages\StorageResource.cs" />
|
||||
<Compile Include="Wizards\GenericPages\VMMappingSummary.cs" />
|
||||
<Compile Include="Wizards\ImportWizard\ImportDelayLoadingOptionComboBoxItem.cs" />
|
||||
<Compile Include="Wizards\ImportWizard\LunPerVdiImportPage.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
|
Loading…
Reference in New Issue
Block a user