Since it is easy to forget calling the base class method at the end of the PageLeave

override in derived classes, enforce it by wrapping the page specific code in
a new virtual method, which the derived classes can override and PageLeave can
call before its own logic.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2018-03-08 23:55:50 +00:00 committed by Mihaela Stoica
parent 2b8bf70ee5
commit 7a1b1a6dcc
40 changed files with 53 additions and 108 deletions

View File

@ -37,9 +37,9 @@ using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using XenAdmin.Wizards;
using XenAdmin.Network;
namespace XenAdmin.Controls
{
public delegate void XenTabPageStatusChanged(XenTabPage sender);
@ -147,11 +147,10 @@ namespace XenAdmin.Controls
}
}
/// <summary>
/// Always remember to call the base method in the END when overriding this in derived classes
/// </summary>
public virtual void PageLeave(PageLoadedDirection direction, ref bool cancel)
public void PageLeave(PageLoadedDirection direction, ref bool cancel)
{
PageLeaveCore(direction, ref cancel);
if (direction == PageLoadedDirection.Forward && !cancel)
{
if (ImplementsIsDirty() && IsDirty && WizardContentUpdater != null)
@ -169,6 +168,10 @@ namespace XenAdmin.Controls
}
}
protected virtual void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
}
/// <summary>
/// Called when the wizard's Cancel button is hit while on this page
/// </summary>

View File

@ -94,12 +94,10 @@ namespace XenAdmin.Wizards.BugToolWizardFiles
PerformCheck(CheckPathValid, CheckCredentialsEntered);
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward)
cancel = !PerformCheck(CheckPathValid, CheckCredentialsEntered, CheckUploadAuthentication);
base.PageLeave(direction, ref cancel);
}
public override void SelectDefaultControl()

View File

@ -85,7 +85,7 @@ namespace XenAdmin.Wizards.BugToolWizardFiles
RunAction(CapabilityList, SelectedHosts);
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (OutputFolder == null)
{
@ -100,7 +100,6 @@ namespace XenAdmin.Wizards.BugToolWizardFiles
cancel = true;
}
}
base.PageLeave(direction, ref cancel);
}
public override void PageCancelled()

View File

@ -98,17 +98,15 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
public override bool EnableNext()
{
return _buttonNextEnabled;
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
}
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (!CrossPoolMigrateWizard.AllVMsAvailable(selectedVMs))
{
cancel = true;
SetButtonsEnabled(false);
}
base.PageLeave(direction, ref cancel);
}
#endregion

View File

@ -169,8 +169,8 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
return filters;
}
public override void PageLeave(XenAdmin.Controls.PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (!cancel)
{
@ -192,8 +192,6 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
cancel = true;
SetButtonNextEnabled(false);
}
base.PageLeave(direction, ref cancel);
}
protected override string VmColumnHeaderText

View File

@ -96,7 +96,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
return new CrossPoolMigrationNetworkResourceContainer(vifs);
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (!CrossPoolMigrateWizard.AllVMsAvailable(VmMappings, Connection))
{
@ -104,8 +104,6 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
SetButtonNextEnabled(false);
SetButtonPreviousEnabled(false);
}
base.PageLeave(direction, ref cancel);
}
protected override string NetworkColumnHeaderText

View File

@ -103,7 +103,7 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
return new CrossPoolMigrationStorageResourceContainer(vdis);
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (!CrossPoolMigrateWizard.AllVMsAvailable(VmMappings, Connection))
{
@ -111,8 +111,6 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
SetButtonNextEnabled(false);
SetButtonPreviousEnabled(false);
}
base.PageLeave(direction, ref cancel);
}
protected override string VmDiskColumnHeaderText

View File

@ -113,15 +113,13 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
return m_buttonPreviousEnabled;
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (!CrossPoolMigrateWizard.AllVMsAvailable(selectedVMs))
{
cancel = true;
SetButtonsEnabled(false);
}
base.PageLeave(direction, ref cancel);
}
#endregion

View File

@ -162,9 +162,9 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
public override bool EnablePrevious()
{
return _buttonPreviousEnabled;
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
}
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
var l = new List<VM>();
l.Add(TheVM);
@ -173,8 +173,6 @@ namespace XenAdmin.Wizards.CrossPoolMigrateWizard
cancel = true;
SetButtonsEnabled(false);
}
base.PageLeave(direction, ref cancel);
}
#endregion

View File

@ -418,14 +418,13 @@ namespace XenAdmin.Wizards.DRWizards
return checks;
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Back)
{
_worker.CancelAsync();
_worker = null;
}
base.PageLeave(direction, ref cancel);
}
public override bool EnableNext()

View File

@ -109,14 +109,13 @@ namespace XenAdmin.Wizards.DRWizards
}
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
ImageAnimator.StopAnimate(animatedImage, onFrameChanged);
if (direction == PageLoadedDirection.Back)
{
actions.Clear();
}
base.PageLeave(direction, ref cancel);
}
public override bool EnableNext()

View File

@ -102,7 +102,8 @@ namespace XenAdmin.Wizards.DRWizards
}
private readonly ConnectionLostDialogLauncher cldl = new ConnectionLostDialogLauncher();
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
_worker.CancelAsync();
@ -111,7 +112,6 @@ namespace XenAdmin.Wizards.DRWizards
IntroduceSRs();
LoadMetadata();
}
base.PageLeave(direction, ref cancel);
}
public override void PageLoaded(PageLoadedDirection direction)

View File

@ -114,7 +114,7 @@ namespace XenAdmin.Wizards.ExportWizard
PerformCheck(CheckPathValid);
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward && IsDirty)
{
@ -122,8 +122,6 @@ namespace XenAdmin.Wizards.ExportWizard
m_textBoxApplianceName.Text = m_textBoxApplianceName.Text.Trim();
cancel = !PerformCheck(CheckDestinationFolderExists, CheckApplianceExists, CheckPermissions);
}
base.PageLeave(direction, ref cancel);
}
public override void PopulatePage()

View File

@ -132,12 +132,10 @@ namespace XenAdmin.Wizards.ExportWizard
SetButtonNextEnabled(true);
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward && IsDirty)
cancel = !(m_isSignatureOk && m_isEncryptionOk);
base.PageLeave(direction, ref cancel);
}
protected override bool ImplementsIsDirty()

View File

@ -118,12 +118,10 @@ namespace XenAdmin.Wizards.ExportWizard
EnableButtons();
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward && IsDirty)
cancel = !PerformCheck(CheckSpaceRequirements);
base.PageLeave(direction, ref cancel);
}
public override void PopulatePage()

View File

@ -89,7 +89,7 @@ namespace XenAdmin.Wizards.GenericPages
lunPerVdiPicker.Clear();
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if(direction == PageLoadedDirection.Back)
{
@ -97,7 +97,6 @@ namespace XenAdmin.Wizards.GenericPages
}
OnPageUpdated();
base.PageLeave(direction, ref cancel);
}
public bool ValidSelectionMade

View File

@ -285,15 +285,13 @@ namespace XenAdmin.Wizards.GenericPages
e.Row.Selected = false;
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Back)
return;
if (!userAcceptsWarning())
cancel = true;
base.PageLeave(direction, ref cancel);
}
private bool userAcceptsWarning()

View File

@ -100,10 +100,9 @@ namespace XenAdmin.Wizards.GenericPages
Program.Invoke(this, RefreshPage);
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
DeregisterConnectionEvents();
base.PageLeave(direction, ref cancel);
}
public override void PageCancelled()

View File

@ -94,11 +94,10 @@ namespace XenAdmin.Wizards.GenericPages
ChosenItem = null;
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
SetDefaultTarget(ChosenItem);
Program.Invoke(Program.MainWindow, ClearComboBox);
base.PageLeave(direction, ref cancel);
}
protected void InitializeText()

View File

@ -99,10 +99,9 @@ namespace XenAdmin.Wizards.GenericPages
set { targetConnection = value; }
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
targetConnection = null;
base.PageLeave(direction, ref cancel);
}
public override void PageLoaded(PageLoadedDirection direction)

View File

@ -153,14 +153,12 @@ namespace XenAdmin.Wizards.GenericPages
#region Base class (XenTabPage) overrides
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
TargetConnection = null;
if (!cancel && direction == PageLoadedDirection.Forward && IsDirty && ImplementsIsDirty())
cancel = !PerformCheck(CheckStorageRequirements);
base.PageLeave(direction, ref cancel);
}
public override void PageLoaded(PageLoadedDirection direction)

View File

@ -77,14 +77,13 @@ namespace XenAdmin.Wizards.GenericPages
OnPageUpdated();
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward && IsDirty)
{
if (!PerformCheck(CheckValidData))
cancel = true;
}
base.PageLeave(direction, ref cancel);
}
public override void PopulatePage()

View File

@ -702,10 +702,9 @@ namespace XenAdmin.Wizards.HAWizard_Pages
dataGridViewVms.Select();
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
StopNtolUpdate();
base.PageLeave(direction, ref cancel);
}
#endregion

View File

@ -52,12 +52,10 @@ namespace XenAdmin.Wizards.HAWizard_Pages
public override string PageTitle { get { return Messages.HA_WIZARD_FINISH_PAGE_TITLE; } }
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Back)
ClearControls();
base.PageLeave(direction, ref cancel);
}
public override void PageLoaded(PageLoadedDirection direction)

View File

@ -86,12 +86,10 @@ namespace XenAdmin.Wizards.ImportWizard
SetButtonNextEnabled(OkToProceed());
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward && IsDirty)
cancel = !OkToProceed();
base.PageLeave(direction, ref cancel);
}
public override void CheckPageDisabled()

View File

@ -97,7 +97,7 @@ namespace XenAdmin.Wizards.ImportWizard
return true;
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward && IsDirty)
{
@ -151,7 +151,6 @@ namespace XenAdmin.Wizards.ImportWizard
OnPageUpdated();
}
}
base.PageLeave(direction, ref cancel);
}
public override void PopulatePage()

View File

@ -91,7 +91,7 @@ namespace XenAdmin.Wizards.ImportWizard
m_buttonNextText = (direction == PageLoadedDirection.Forward) ? Messages.IMPORT_VM_IMPORT : Messages.WIZARD_BUTTON_NEXT;
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward && IsDirty)
{
@ -112,7 +112,6 @@ namespace XenAdmin.Wizards.ImportWizard
m_alreadyFoundVM = false;
m_actionDialog.Show(this);
}
base.PageLeave(direction, ref cancel);
}
public override string NextText(bool isLastPage)

View File

@ -65,12 +65,10 @@ namespace XenAdmin.Wizards.NewNetworkWizard_Pages
HelpersGUI.FocusFirstControl(Controls);
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward)
CheckUniqueName(txtName.Text);
base.PageLeave(direction, ref cancel);
}
public override void PopulatePage()

View File

@ -92,12 +92,10 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends
#region XenTabPage overrides
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward)
cancel = !PerformStoragePoolScan();
base.PageLeave(direction, ref cancel);
}
public override string Text { get { return Messages.STORAGE_SYSTEM; } }

View File

@ -75,12 +75,10 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends
public override string HelpID { get { return IsNetApp ? "SL_NETAPP_filer" : "SL_EQL_filer"; } }
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward)
cancel = !Scan();
base.PageLeave(direction, ref cancel);
}
public override bool EnableNext()

View File

@ -73,7 +73,7 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends
public override string HelpID { get { return "Location_HBA"; } }
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Back)
return;
@ -178,8 +178,6 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends
if (!cancel && launcher.SrDescriptors.Count > 0)
SrDescriptors.AddRange(launcher.SrDescriptors);
}
base.PageLeave(direction, ref cancel);
}
public override bool EnableNext()

View File

@ -124,7 +124,7 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends
HelpersGUI.FocusFirstControl(Controls);
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Back)
return;
@ -160,8 +160,6 @@ namespace XenAdmin.Wizards.NewSRWizard_Pages.Frontends
// Will return false on cancel
cancel = !ExamineIscsiProbeResults(IscsiProbeAction);
iscsiProbeError = cancel;
base.PageLeave(direction, ref cancel);
}
bool iscsiProbeError = false;

View File

@ -133,10 +133,9 @@ namespace XenAdmin.Wizards.PatchingWizard
}
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
tableLayoutPanel1.MouseMove -= tableLayoutPanel1_MouseMove;
base.PageLeave(direction, ref cancel);
}
/// <summary>

View File

@ -560,7 +560,7 @@ namespace XenAdmin.Wizards.PatchingWizard
resolvePrechecksAction.Cancel();
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
DeregisterEventHandlers();
if (direction == PageLoadedDirection.Back && _worker != null)
@ -568,8 +568,6 @@ namespace XenAdmin.Wizards.PatchingWizard
_worker.CancelAsync();
_worker = null;
}
base.PageLeave(direction, ref cancel);
}
public override bool EnablePrevious()

View File

@ -194,7 +194,7 @@ namespace XenAdmin.Wizards.PatchingWizard
}
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward)
{
@ -275,7 +275,6 @@ namespace XenAdmin.Wizards.PatchingWizard
Updates.CheckForUpdatesStarted -= CheckForUpdates_CheckForUpdatesStarted;
Updates.CheckForUpdatesCompleted -= CheckForUpdates_CheckForUpdatesCompleted;
}
base.PageLeave(direction, ref cancel);
}
private XenServerPatchAlert GetAlertFromFileName(string fileName)

View File

@ -381,7 +381,7 @@ namespace XenAdmin.Wizards.PatchingWizard
return false;
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
try
{
@ -420,7 +420,6 @@ namespace XenAdmin.Wizards.PatchingWizard
}
}
}
base.PageLeave(direction, ref cancel);
}
catch (Exception e)
{

View File

@ -75,7 +75,7 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
public override string HelpID { get { return "Upgradepools"; } }
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
UnregisterAllStatusUpdateActions();
ImageAnimator.StopAnimate(animatedImage, onFrameChanged);
@ -83,7 +83,6 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
{
planActions.Clear();
}
base.PageLeave(direction, ref cancel);
}
public override void PageCancelled()

View File

@ -107,10 +107,9 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
return;
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
RemoveEventHandlersToMasters();
base.PageLeave(direction, ref cancel);
}
public override void PageCancelled()

View File

@ -79,7 +79,7 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
get { return "Selectpool"; }
}
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Forward)
{
@ -106,7 +106,6 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
}
}
}
base.PageLeave(direction, ref cancel);
}
private bool AllSelectedHostsConnected()

View File

@ -85,13 +85,12 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
public override string HelpID { get { return "upgrademethod"; } }
public override void PageLeave(PageLoadedDirection direction, ref bool cancel)
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (testingAction != null)
{
StopUrlTesting();
}
base.PageLeave(direction, ref cancel);
}
public override void PageCancelled()