From 404ee1680a838469a8f3aac864c8dc0b06e3f965 Mon Sep 17 00:00:00 2001 From: Konstantina Chremmou Date: Tue, 26 Apr 2022 15:38:20 +0100 Subject: [PATCH] Tidy up. Signed-off-by: Konstantina Chremmou --- .../DRWizards/DRFailoverWizardRecoverPage.cs | 82 ++++++++----------- 1 file changed, 35 insertions(+), 47 deletions(-) diff --git a/XenAdmin/Wizards/DRWizards/DRFailoverWizardRecoverPage.cs b/XenAdmin/Wizards/DRWizards/DRFailoverWizardRecoverPage.cs index 3647fe98c..558595492 100644 --- a/XenAdmin/Wizards/DRWizards/DRFailoverWizardRecoverPage.cs +++ b/XenAdmin/Wizards/DRWizards/DRFailoverWizardRecoverPage.cs @@ -50,6 +50,13 @@ namespace XenAdmin.Wizards.DRWizards { private static readonly ILog log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType); + private static Bitmap animatedImage = Resources.ajax_loader; + + private readonly Dictionary> _actions = new Dictionary>(); + private int objectsToBeRecovered; + private MultipleAction multipleRecoverAction; + private Session metadataSession; + public event Action ReportStarted; public event Action ReportActionResultGot; public event Action ReportLineGot; @@ -93,8 +100,6 @@ namespace XenAdmin.Wizards.DRWizards } } - private static Bitmap animatedImage = Resources.ajax_loader; - private void onFrameChanged(object sender, EventArgs e) { try @@ -113,7 +118,7 @@ namespace XenAdmin.Wizards.DRWizards ImageAnimator.StopAnimate(animatedImage, onFrameChanged); if (direction == PageLoadedDirection.Back) { - actions.Clear(); + _actions.Clear(); } } @@ -161,17 +166,17 @@ namespace XenAdmin.Wizards.DRWizards public DRWizardType WizardType { private get; set; } - private Dictionary> actions = new Dictionary>(); - private int objectsToBeRecovered; + internal List RecoveredVmsUuids { get; } = new List(); - private StartActionAfterRecovery startActionAfterRecovery; - public StartActionAfterRecovery StartActionAfterRecovery { set { startActionAfterRecovery = value; } } + internal List RecoveredVmAppliancesUuids { get; } = new List(); + + public StartActionAfterRecovery StartActionAfterRecovery { private get; set; } public Dictionary, PoolMetadata> SelectedPoolMetadata { private get; set; } protected override void PageLoadedCore(PageLoadedDirection direction) { - if (direction == PageLoadedDirection.Back || actions.Count > 0) + if (direction == PageLoadedDirection.Back || _actions.Count > 0) return; ImageAnimator.Animate(animatedImage, onFrameChanged); @@ -183,18 +188,18 @@ namespace XenAdmin.Wizards.DRWizards OnPageUpdated(); dataGridView1.Rows.Clear(); - actions.Clear(); + _actions.Clear(); objectsToBeRecovered = 0; // add "recovery" tasks foreach (var poolMetadata in SelectedPoolMetadata.Values) { - actions.Add(poolMetadata.Vdi, CreateSubActionsFor(poolMetadata)); + _actions.Add(poolMetadata.Vdi, CreateSubActionsFor(poolMetadata)); } // add a row for "Start VMs and Appliances" task, if required - if (startActionAfterRecovery != StartActionAfterRecovery.None) + if (StartActionAfterRecovery != StartActionAfterRecovery.None) dataGridView1.Rows.Add(new DataGridViewRowRecover(Messages.ACTION_START_VMS_AND_APPLIANCES_TITLE)); labelOverallProgress.Text = string.Format(Messages.DR_WIZARD_RECOVERPAGE_OVERALL_PROGRESS, 0, dataGridView1.Rows.Count); @@ -242,9 +247,6 @@ namespace XenAdmin.Wizards.DRWizards return subActions; } - internal List RecoveredVmsUuids = new List(); - internal List RecoveredVmAppliancesUuids = new List(); - private void SingleRecoverActionCompleted(ActionBase sender) { DrRecoverAction senderAction = (DrRecoverAction)sender; @@ -297,10 +299,6 @@ namespace XenAdmin.Wizards.DRWizards }); } - - private MultipleAction multipleRecoverAction; - private Session metadataSession; - private void OpenDatabaseActionCompleted(ActionBase sender) { VdiOpenDatabaseAction senderAction = (VdiOpenDatabaseAction)sender; @@ -314,7 +312,7 @@ namespace XenAdmin.Wizards.DRWizards // assign metadata session to all recover actions List recoverSubActions = new List(); - foreach (var action in actions[senderAction.Vdi]) + foreach (var action in _actions[senderAction.Vdi]) { if (action is DrRecoverAction) { @@ -345,7 +343,7 @@ namespace XenAdmin.Wizards.DRWizards { if (objectsToBeRecovered == 0) // finished recovering, now start VMs, if required { - switch (startActionAfterRecovery) + switch (StartActionAfterRecovery) { case StartActionAfterRecovery.Start : StartRecoveredVMs(false); @@ -369,7 +367,7 @@ namespace XenAdmin.Wizards.DRWizards private void RecoverNextPool() { - foreach (var actionList in actions.Values) + foreach (var actionList in _actions.Values) { bool startRecovery = false; foreach (var action in actionList) @@ -421,12 +419,9 @@ namespace XenAdmin.Wizards.DRWizards } var action = new StartVMsAndAppliancesAction(Connection, vmsToStart, vmAppliancesToStart, VMOperationCommand.WarningDialogHAInvalidConfig, VMOperationCommand.StartDiagnosisForm, paused); - if (action != null) - { - action.Completed += StartVMsActionCompleted; - action.Changed += StartVMsActionChanged; - action.RunAsync(); - } + action.Completed += StartVMsActionCompleted; + action.Changed += StartVMsActionChanged; + action.RunAsync(); } private void StartVMsActionChanged(ActionBase sender) @@ -483,22 +478,20 @@ namespace XenAdmin.Wizards.DRWizards public class DataGridViewRowRecover : DataGridViewRow { public readonly IXenObject XenObject; // it can be VM or VM_appliance - private DataGridViewImageCell imageCell = new DataGridViewImageCell(); - private DataGridViewTextBoxCell taskCell = new DataGridViewTextBoxCell(); - private DataGridViewTextBoxCell statusCell = new DataGridViewTextBoxCell(); + private readonly DataGridViewImageCell _imageCell = new DataGridViewImageCell(); + private readonly DataGridViewTextBoxCell _taskCell = new DataGridViewTextBoxCell(); + private readonly DataGridViewTextBoxCell _statusCell = new DataGridViewTextBoxCell(); private DataGridViewRowRecover() { - this.Cells.Add(taskCell); - this.Cells.Add(imageCell); - this.Cells.Add(statusCell); + this.Cells.AddRange(_taskCell, _imageCell, _statusCell); } public DataGridViewRowRecover(IXenObject xenObject) : this() { XenObject = xenObject; - taskCell.Value = XenObject is VM + _taskCell.Value = XenObject is VM ? string.Format(Messages.ACTION_DR_RECOVER_VM_TITLE, XenObject.Name()) : string.Format(Messages.ACTION_DR_RECOVER_APPLIANCE_TITLE, XenObject.Name()); UpdateStatus(RecoverState.NotRecovered, Messages.DR_WIZARD_RECOVERPAGE_STATUS_PENDING); @@ -507,34 +500,29 @@ namespace XenAdmin.Wizards.DRWizards public DataGridViewRowRecover(string title) : this() { - taskCell.Value = title; + _taskCell.Value = title; UpdateStatus(RecoverState.NotRecovered, Messages.DR_WIZARD_RECOVERPAGE_STATUS_PENDING); } - public void UpdateStatus(RecoverState state, string value) - { - UpdateStatus(state, value, ""); - } - - public void UpdateStatus(RecoverState state, string value, string toolTipText) + public void UpdateStatus(RecoverState state, string value, string toolTipText = "") { switch (state) { case RecoverState.Recovered: - imageCell.Value = Images.StaticImages._000_Tick_h32bit_16; + _imageCell.Value = Images.StaticImages._000_Tick_h32bit_16; break; case RecoverState.Recovering: - imageCell.Value = animatedImage; + _imageCell.Value = animatedImage; break; case RecoverState.Error: - imageCell.Value = Images.StaticImages._000_Abort_h32bit_16; + _imageCell.Value = Images.StaticImages._000_Abort_h32bit_16; break; case RecoverState.NotRecovered: - imageCell.Value = new Bitmap(1, 1); + _imageCell.Value = new Bitmap(1, 1); break; } - statusCell.Value = value; - statusCell.ToolTipText = toolTipText; + _statusCell.Value = value; + _statusCell.ToolTipText = toolTipText; } }