xenadmin/XenAdmin/Wizards/DRWizards/DRFailoverWizardPrecheckPage.cs
Danilo Del Busso 4b0b83245f
CP-34231: Remove language with negative connotations (#2860)
* CA-34231: Replace negative language with `block list` in code and references

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `stop` in code and references

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `freezing` in code

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run/ran` in code comments

Some paramater mentions have been renamed, as they will be renamed in future commits.
Excluded mentions in XenAPI/Host.cs and XenAPI/VM.cs since code is autogenerated.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	CFUValidator/CommandLineOptions/CFUCommandLineOptionManager.cs
#	XenAdmin/Controls/Wlb/WlbOptModeScheduler.cs
#	XenAdmin/Dialogs/Wlb/WorkloadReports.cs

* CA-34231: Replace negative language with `run` in Command.cs Run method

Used Resharper renaming utility
Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/TabPages/GeneralTabPage.cs

* CA-34231: Replace negative language with `run` in Command.cs CanRun method

Used Resharper rename utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in Command.cs CanRunCore method

Used ReSharper rename utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/DRConfigureCommand.cs
#	XenAdmin/Commands/DRDryrunCommand.cs
#	XenAdmin/Commands/DRFailbackCommand.cs
#	XenAdmin/Commands/DRFailoverCommand.cs
#	XenAdmin/Commands/DisasterRecoveryCommand.cs
#	XenAdmin/Commands/VMGroupCommand.cs

* CA-34231: Replace negative language with `run` in Command.cs RunCore method

Used ReSharper rename utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in Command.cs GetCantExecuteReasonCore method

Used ReSharper rename utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in Command.cs GetCantRunReasons method

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative language with `run` in Command.cs

Also applied to related symbols. Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in methods named CanRun

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in methods in CrossPoolMigrateCommand.cs

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/CrossPoolMigrateCommand.cs

* CA-34231: Replace negative language with `run` in remaining Run methods

Also updated negative language in `DeleteVMCommand`
Also updated in comment in `CrossPoolMigrateCommand`
Also renamed missed instances of `CanRun`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `run` in `CanRunCore` and `RunCore`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative language with `run` in Commands folder

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative language with `run` in XenAdmin/Controls folder

Used ReSharper renaming utility. Had to rename `WlbReportView.xs:RunReport()` to `WlbReportView.xs:StartRunReport()` to resolve conflict with change from `WlbReportView:ExecuteReport()` to `WlbReportView:RunReport()`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Controls/Wlb/WlbOptModeScheduler.cs
#	XenAdmin/Dialogs/Wlb/WorkloadReports.cs
#	XenAdminTests/UnitTests/WlbTests/WlbScheduledTaskTests.cs

* CA-34231: Replace all remaining negative language with `run` in code

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/Controls/WlbRecommendations.cs
#	XenAdminTests/UnitTests/WlbTests/WlbScheduledTaskTests.cs
#	XenModel/WLB/WlbScheduledTask.cs

* CA-34231: Replace negative language with `supporter` or `bond member` in code strings

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `supporter` or `bond member` in Messages string

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/MainWindow.cs
#	XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs
#	XenModel/Messages.Designer.cs
#	XenModel/Messages.resx

* CA-34231: Replace remaining negative language with `supporter` in .resx files

Used ReSharper renaming utility. FriendlyErrorNames.resx has been excluded.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `supporter` or `bond member` in XenAdmin code

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/NewPoolDialog.cs

* CA-34231: Replace negative language with `supporter` or `bond member` in XenModel code

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in CFUValidator code

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	CFUValidator/CFUValidator.cs

* CA-34231: Replace negative language with `coordinator` in solution's comments and hardcoded strings

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `Helpers:GetCoordinator` method

Used ReSharper renaming utility.
also renamed similarly named method in `ObjectChange.cs`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Alerts/Types/HotfixEligibilityAlert.cs
#	XenAdmin/Controls/CustomDataGraph/ArchiveMaintainer.cs

* CA-34231: Replace negative language with `coordinator` in `EvacuateHostDialog.resx`

Used ReSharper renaming utility. Excluded jp and zh resources

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/EvacuateHostDialog.resx

* CA-34231: Replace negative language with `coordinator` in `EvacuateHostDialog.resx`

Used ReSharper renaming utility. Excluded jp and zh resource files.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/NewPoolDialog.resx

* CA-34231: Rename missing language references for change to `coordinator`

Misc files were not saved before last commits.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `Messages.resx`'s code

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/HACommand.cs
#	XenAdmin/TabPages/AdPage.cs
#	XenModel/Actions/Network/CreateBondAction.cs
#	XenModel/Actions/Network/NetworkAction.cs
#	XenModel/Messages.Designer.cs
#	XenModel/Messages.resx

* CA-34231: Replace negative language with `coordinator` in `ExternalPluginAction.cs`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `XenAdmin/Commands`

Used ReSharper renaming utility. Also replace negative language in missed comment in `ExternalPluginAction.cs`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/AddHostToPoolCommand.cs
#	XenAdmin/Commands/HACommand.cs

* CA-34231: Replace negative language with `coordinator` in `Helpers.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `NetworkingHelper.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `PoolJoinRules.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/NewPoolDialog.cs

* CA-34231: Replace negative language with `coordinator` in `XenAdmin/Commands`, `Controls`, and `Core`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Commands/AddHostToPoolCommand.cs

* CA-34231: Replace negative language with `coordinator` in `XenAdmin/Diagnostics`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `coordinator` in `XenAdmin/Dialogs`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/NewPoolDialog.cs

* CA-34231: Replace remaining negative language with `coordinator` in `XenAdmin`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/MainWindow.cs
#	XenAdmin/TabPages/GeneralTabPage.cs
#	XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs
#	XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeExtrasPage.cs
#	XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizard.cs
#	XenAdmin/Wizards/RollingUpgradeWizard/RollingUpgradeWizardPrecheckPage.cs
#	XenAdmin/XenSearch/Columns.cs

* CA-34231: Replace remaining negative language with `coordinator` in `XenModel\Actions`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenModel/Actions/Network/CreateBondAction.cs

* CA-34231: Replace remaining negative language with `coordinator` in `XenModel`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative strings with `main` in `Messages.resx`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenModel/Messages.Designer.cs
#	XenModel/Messages.resx

* CA-34231: Replace remaining negative string names with `main` in `Messages.resx`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/OptionsPages/SaveAndRestoreOptionsPage.cs
#	XenModel/Messages.resx

* CA-34231: Rename dialogs to replace negative connotations with `main`

Used ReSharper renaming utility

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `main` in `SaveAndResoreOptionsPage.cs`

Also updated its resx file. Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

# Conflicts:
#	XenAdmin/Dialogs/OptionsPages/SaveAndRestoreOptionsPage.cs

* CA-34231: Fix invalid reference in `SaveAndRestoreOptionsPage.Designer.cs` after renaming

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `main` in `EnterMainPasswordDialog.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `main` in `ChangeMainPasswordDialog.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Fix invalid reference not changed after renaming `EnterMainPasswordDialog.cs`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative language with `main` in `XenAdmin/Dialogs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Update class names in HelpManager.resx

Following renaming of main password dialog. Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace negative language with `main` in `Metadata.cs`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Remove remaning negative language with `coordinator` from `Messages.resx`

Used ReSharper renaming

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Remove remaning negative language with `other pool member` from `Messages.resx`

Used ReSharper

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CA-34231: Replace remaining negative language in solution

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Remove commented out code in VNCGraphicsClient.cs

Code has only been improved partially as it's not strictly relevant to the PR

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Amend negative word replacement in XSVNCScreen.cs

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Simplify debug call formatting in NewPoolDialog.cs

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Add code mistakenly removed in MainWindow.cs

Removed as part of `f155f9c8`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Revert renaming of constant related to Windows' API

Considered external to CH Center

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Amend hotkey for Coordinator field in `NewPoolDialog`

Previous ALT+<key> hotkey was conflicting with CreatePool

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Remove unecessary whitespace in EvacuateHostDialog.cs

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Update if block to exclude unecessary else in DRFailoverWizard.cs

Not relevant to the PR, but the change is small enought to no need extra testing

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Amend typo in PoolJoinRules.cs

supporer -> supporter

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Replace missing negative language with `coordinator` in `XenAPI-Extensions/Pool.cs`

Variables and methods XenAPI-Extensions were mistakenly skipped

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Replace negative language in `XenApi-Extensions` with `coordinator/interface`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Replace negative language in `XenApi-Extensions` with `supporter/member`

Used ReSharper renaming utility.

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Replace remaining negative language in `XenServerHealthCheckBugTool.cs`

This is only used to format the string

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Change line-endings to CRLF in `Page_CloudConfigParamters.cs`

Done in order to fix merge conflict into master

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>

* CP-34231: Amend misc negative language renaming typos

`XenServerHealthCheckBugTool` and `XenServerHealthCheckService`

Signed-off-by: Danilo Del Busso <Danilo.Del.Busso@citrix.com>
2021-08-31 11:31:16 +01:00

673 lines
26 KiB
C#

/* 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.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
using XenAdmin.Actions;
using XenAdmin.Controls;
using XenAdmin.Core;
using XenAdmin.Diagnostics.Checks;
using XenAdmin.Diagnostics.Checks.DR;
using XenAdmin.Diagnostics.Problems;
using XenAdmin.Dialogs;
using XenAPI;
using XenAdmin.Actions.DR;
namespace XenAdmin.Wizards.DRWizards
{
public partial class DRFailoverWizardPrecheckPage : XenTabPage
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public event Action<string> NewDrTaskIntroduced;
public event Action<XenRef<SR>> SrIntroduced;
private Pool _pool;
public Pool Pool { set { _pool = value; } }
private Dictionary<XenRef<VDI>, PoolMetadata> selectedPoolMetadata;
public Dictionary<XenRef<VDI>, PoolMetadata> SelectedPoolMetadata {set { selectedPoolMetadata = value; }}
public List<AsyncAction> RevertActions = new List<AsyncAction>();
private string _nextButtonText = Messages.WIZARD_BUTTON_NEXT;
public override string NextText(bool isLastPage)
{
return _nextButtonText;
}
public DRFailoverWizardPrecheckPage()
{
InitializeComponent();
dataGridView1.BackgroundColor = dataGridView1.DefaultCellStyle.BackColor;
}
public override string PageTitle
{
get
{
switch (WizardType)
{
case DRWizardType.Failback:
return Messages.DR_WIZARD_PRECHECKPAGE_TITLE_FAILBACK;
default:
return Messages.DR_WIZARD_PRECHECKPAGE_TITLE_FAILOVER;
}
}
}
public override string Text
{
get
{
return Messages.DR_WIZARD_PRECHECKPAGE_TEXT;
}
}
public override string HelpID
{
get
{
switch (WizardType)
{
case DRWizardType.Failback:
return "Failback_Prechecks";
case DRWizardType.Dryrun:
return "Dryrun_Prechecks";
default:
return "Failover_Prechecks";
}
}
}
public override bool EnablePrevious()
{
return _worker != null && !_worker.IsBusy;
}
private int PercentageSelectedObjects(int i)
{
int count = 0;
foreach (var poolMetadata in selectedPoolMetadata.Values)
{
count += (poolMetadata.VmAppliances.Count + poolMetadata.Vms.Count);
}
return (int)(((float)i / (float)(count)) * 100);
}
private BackgroundWorker _worker = null;
protected override void PageLoadedCore(PageLoadedDirection direction)
{
SetupLabels();
try
{
if (direction == PageLoadedDirection.Back)
return;
RefreshRechecks();
}
catch (Exception e)
{
log.Error(e, e);
throw;//better throw an exception rather than closing the wizard suddenly and silently
}
}
public DRWizardType WizardType { private get; set; }
private void SetupLabels()
{
switch (WizardType)
{
case DRWizardType.Failback:
labelContinue.Text = Messages.DR_WIZARD_PRECHECKPAGE_CONTINUE_FAILBACK;
_nextButtonText = Messages.DR_WIZARD_PRECHECKPAGE_NEXT_FAILBACK;
break;
case DRWizardType.Dryrun:
labelContinue.Text = Messages.DR_WIZARD_PRECHECKPAGE_CONTINUE_DRYRUN;
_nextButtonText = Messages.DR_WIZARD_PRECHECKPAGE_NEXT_FAILOVER;
break;
default:
labelContinue.Text = Messages.DR_WIZARD_PRECHECKPAGE_CONTINUE_FAILOVER;
_nextButtonText = Messages.DR_WIZARD_PRECHECKPAGE_NEXT_FAILOVER;
break;
}
}
protected void RefreshRechecks()
{
buttonResolveAll.Enabled = buttonReCheckProblems.Enabled = false;
_worker = null;
_worker = new BackgroundWorker();
_worker.DoWork += new DoWorkEventHandler(worker_DoWork);
_worker.WorkerReportsProgress = true;
_worker.WorkerSupportsCancellation = true;
_worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(_worker_RunWorkerCompleted);
_worker.RunWorkerAsync();
}
void _worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (!e.Cancelled)
OnPageUpdated();
progressBar1.Value = 100;
bool problemsFound = false;
foreach (PreCheckGridRow row in dataGridView1.Rows)
{
PreCheckItemRow preCheckRow = row as PreCheckItemRow;
if (preCheckRow != null && preCheckRow.Problem != null)
{
problemsFound = true;
break;
}
}
buttonResolveAll.Enabled = problemsFound;
buttonReCheckProblems.Enabled = true;
}
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
try
{
var row = e.UserState as DataGridViewRow;
if (row != null && !dataGridView1.Rows.Contains(row))
{
PreCheckItemRow preCheckRow = row as PreCheckItemRow;
if (preCheckRow != null && preCheckRow.IsProblem)
preCheckRow.Visible = true;
else
row.Visible = !checkBoxViewPrecheckFailuresOnly.Checked;
dataGridView1.Rows.Add(row);
}
int step = (int)((1.0 / ((float)_numberChecks)) * e.ProgressPercentage);
progressBar1.Value += (step + progressBar1.Value) > 100 ? 0 : step;
}
catch (Exception) { }
}
private DataGridViewRow RunCheck(Check check)
{
var problems = check.RunAllChecks();
if (problems.Count != 0)
{
// None of the checks used in the DR wizard returns more than one problem, so we just take the first.
// (Even if they did, we would only suffer the usability problem described in CA-77990).
return new PreCheckItemRow(problems[0]);
}
return new PreCheckItemRow(check);
}
private int _numberChecks = 0;
private readonly object _lock = new object();
void worker_DoWork(object sender, DoWorkEventArgs e)
{
lock (_lock)
{
Program.Invoke(this, () =>
{
dataGridView1.Rows.Clear();
progressBar1.Value = 0;
});
RevertActions.Clear();
List<KeyValuePair<string, List<Check>>> checks = GenerateChecks();
_numberChecks = checks.Count;
for (int i = 0; i < checks.Count; i++)
{
List<Check> checkGroup = checks[i].Value;
DataGridViewRow row =
new PreCheckHeaderRow(string.Format(Messages.DR_WIZARD_PRECHECKPAGE_HEADER, i + 1,
checks.Count, checks[i].Key));
_worker.ReportProgress(5, row);
Session metadataSession = null;
// run checks
for (int j = 0; j < checkGroup.Count; j++)
{
if (_worker.CancellationPending)
{
e.Cancel = true;
return;
}
Check check = checkGroup[j];
// special case - AssertCanBeRecoveredCheck - we need to open the metadata database
if (check is AssertCanBeRecoveredCheck)
{
AssertCanBeRecoveredCheck thisCheck = check as AssertCanBeRecoveredCheck;
AssertCanBeRecoveredCheck prevCheck = j > 0
? checkGroup[j - 1] as
AssertCanBeRecoveredCheck
: null;
if (prevCheck == null || prevCheck.Vdi.uuid != thisCheck.Vdi.uuid)
{
// close previous metadata session
if (metadataSession != null)
metadataSession.logout();
// open metadata database
VdiOpenDatabaseAction action = new VdiOpenDatabaseAction(Connection,
((AssertCanBeRecoveredCheck
)checkGroup[0]).Vdi);
action.RunExternal(action.Session);
if (action.Succeeded && action.MetadataSession != null)
metadataSession = action.MetadataSession;
}
// run check
if (metadataSession != null)
{
thisCheck.MetadataSession = metadataSession;
row = RunCheck(thisCheck);
_worker.ReportProgress(PercentageSelectedObjects(j + 1), row);
// close metadata session if this is the last check
if (j == checkGroup.Count - 1)
metadataSession.logout();
}
}
else
{
row = RunCheck(check);
_worker.ReportProgress(PercentageSelectedObjects(j + 1), row);
}
}
}
}
}
private List<KeyValuePair<string, List<Check>>> GenerateChecks()
{
List<KeyValuePair<string, List<Check>>> checks = new List<KeyValuePair<string, List<Check>>>();
List<Check> checkGroup;
//HA checks
if (WizardType == DRWizardType.Dryrun)
{
checks.Add(new KeyValuePair<string, List<Check>>(Messages.DR_WIZARD_CHECKING_HA_STATUS,
new List<Check>()));
checkGroup = checks[checks.Count - 1].Value;
checkGroup.Add(new DrHAEnabledCheck(_pool));
}
// check if selected VMs and appliances are still running in the source pool
if (WizardType != DRWizardType.Dryrun)
{
checkGroup = new List<Check>();
foreach (PoolMetadata poolMetadata in selectedPoolMetadata.Values)
{
// is source pool connected?
PoolMetadata metadata = poolMetadata;
Pool sourcePool = ConnectionsManager.XenConnectionsCopy.Select
(connection => Helpers.GetPoolOfOne(connection)).FirstOrDefault
(pool => pool != null && pool.uuid == metadata.Pool.uuid);
if (sourcePool != null)
{
foreach (VM_appliance vmAppliance in poolMetadata.VmAppliances.Values)
{
checkGroup.Add(new RunningVmApplianceCheck(vmAppliance, sourcePool));
}
foreach (VM vm in poolMetadata.Vms.Values)
{
if (vm.IsAssignedToVapp())
{
//VM included in an appliance
continue;
}
checkGroup.Add(new RunningVmCheck(vm, sourcePool));
}
}
}
if (checkGroup.Count > 0)
checks.Add(
new KeyValuePair<string, List<Check>>(
Messages.DR_WIZARD_CHECKING_POWER_STATE_IN_SOURCE_POOLS, checkGroup));
}
//Existing VMs and appliances checks
checkGroup = new List<Check>();
foreach (PoolMetadata poolMetadata in selectedPoolMetadata.Values)
{
foreach (VM_appliance vmAppliance in poolMetadata.VmAppliances.Values)
{
PoolMetadata metadata = poolMetadata;
List<VM> vms = (from vmRef in vmAppliance.VMs
where metadata.Vms.ContainsKey(vmRef)
select metadata.Vms[vmRef]).ToList();
checkGroup.Add(new ExistingVmApplianceCheck(vmAppliance, vms, _pool));
}
foreach (VM vm in poolMetadata.Vms.Values)
{
if (vm.IsAssignedToVapp())
{
//VM included in an appliance
continue;
}
checkGroup.Add(new ExistingVmCheck(vm, _pool));
}
}
if (checkGroup.Count > 0)
checks.Add(new KeyValuePair<string, List<Check>>(String.Format(Messages.DR_WIZARD_CHECKING_EXISTING_APPLIANCES_AND_VMS, _pool.Name()), checkGroup));
//VM and appliance can be recovered checks
checks.Add(new KeyValuePair<string, List<Check>>(String.Format(Messages.DR_WIZARD_CHECKING_VMS_CAN_BE_RECOVERED, _pool.Name()), new List<Check>()));
checkGroup = checks[checks.Count - 1].Value;
foreach (PoolMetadata poolMetadata in selectedPoolMetadata.Values)
{
foreach (VM_appliance vmAppliance in poolMetadata.VmAppliances.Values)
{
checkGroup.Add(new AssertCanBeRecoveredCheck(vmAppliance, _pool, poolMetadata.Vdi));
}
foreach (VM vm in poolMetadata.Vms.Values)
{
if (vm.IsAssignedToVapp())
{
//VM included in an appliance
continue;
}
checkGroup.Add(new AssertCanBeRecoveredCheck(vm, _pool, poolMetadata.Vdi));
}
}
return checks;
}
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
if (direction == PageLoadedDirection.Back)
{
_worker.CancelAsync();
_worker = null;
}
}
public override bool EnableNext()
{
int problemsCount = 0;
foreach (DataGridViewRow row in dataGridView1.Rows)
{
PreCheckItemRow preCheckRow = row as PreCheckItemRow;
if (preCheckRow != null && preCheckRow.IsProblem)
{
problemsCount++;
}
}
if (_worker != null && _worker.IsBusy)
labelPrecheckStatus.Text = Messages.DR_WIZARD_PRECHECKPAGE_STATUS_RUNNING;
else
{
labelPrecheckStatus.Text = problemsCount > 0
? string.Format(Messages.DR_WIZARD_PRECHECKPAGE_STATUS_FAILURE, problemsCount)
: Messages.DR_WIZARD_PRECHECKPAGE_STATUS_SUCCESS;
}
bool result = _worker != null && !_worker.IsBusy && problemsCount==0;
panelErrorsFound.Visible = !result;
labelContinue.Visible = result;
return result;
}
public override void PageCancelled(ref bool cancel)
{
if (_worker != null)
_worker.CancelAsync();
}
internal List<string> GetWarnings()
{
var warnings = new List<string>();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
var preCheckRow = row as PreCheckItemRow;
if (preCheckRow != null && preCheckRow.IsWarning)
{
warnings.Add(preCheckRow.Description);
}
}
return warnings;
}
private void RunSolution(PreCheckItemRow preCheckRow)
{
bool cancelled;
AsyncAction action = preCheckRow.Problem.GetSolutionAction(out cancelled);
if (action != null)
{
action.Completed += action_Completed;
using (var progressDialog = new ActionProgressDialog(action, ProgressBarStyle.Blocks))
progressDialog.ShowDialog(this);
if (action.Succeeded)
{
var revertAction = preCheckRow.Problem.CreateUnwindChangesAction();
if (revertAction != null)
RevertActions.Add(revertAction);
}
}
}
private void action_Completed(ActionBase sender)
{
Thread.Sleep(1000);
Program.Invoke(Program.MainWindow, RefreshRechecks);
var drTaskCreateAction = sender as DrTaskCreateAction;
if (drTaskCreateAction != null && drTaskCreateAction.Succeeded)
{
if (NewDrTaskIntroduced != null)
NewDrTaskIntroduced(drTaskCreateAction.Result);
return;
}
var srIntroduceAction = sender as SrIntroduceAction;
if (srIntroduceAction != null && srIntroduceAction.Succeeded)
{
if (SrIntroduced != null)
SrIntroduced(new XenRef<SR>(srIntroduceAction.Result));
}
}
private void buttonReCheckProblems_Click(object sender, EventArgs e)
{
RefreshRechecks();
}
private void buttonResolveAll_Click(object sender, EventArgs e)
{
Dictionary<AsyncAction, AsyncAction> actions = new Dictionary<AsyncAction, AsyncAction>();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
PreCheckItemRow preCheckRow = row as PreCheckItemRow;
if (preCheckRow != null && preCheckRow.Problem != null)
{
bool cancelled;
AsyncAction action = preCheckRow.Problem.GetSolutionAction(out cancelled);
if (action != null)
{
actions.Add(action, preCheckRow.Problem.CreateUnwindChangesAction());
}
}
}
foreach (var asyncAction in actions.Keys)
{
using (var progressDialog = new ActionProgressDialog(asyncAction, ProgressBarStyle.Blocks))
progressDialog.ShowDialog(this);
if (asyncAction.Succeeded && actions[asyncAction] != null)
RevertActions.Add(actions[asyncAction]);
Program.Invoke(Program.MainWindow, RefreshRechecks);
}
Program.Invoke(Program.MainWindow, RefreshRechecks);
}
private void checkBoxViewPrecheckFailuresOnly_CheckedChanged(object sender, EventArgs e)
{
//RefreshRechecks();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
var preCheckRow = row as PreCheckItemRow;
if (preCheckRow != null && preCheckRow.IsProblem)
preCheckRow.Visible = true;
else
row.Visible = !checkBoxViewPrecheckFailuresOnly.Checked;
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
PreCheckItemRow preChecRow = dataGridView1.Rows[e.RowIndex] as PreCheckItemRow;
if (preChecRow != null && e.ColumnIndex == 2)
{
RunSolution(preChecRow);
return;
}
}
#region PreCheckGridRow
private abstract class PreCheckGridRow : DataGridViewRow
{
protected DataGridViewImageCell _iconCell = new DataGridViewImageCell();
protected DataGridViewTextBoxCell _descriptionCell = new DataGridViewTextBoxCell();
protected DataGridViewCell _solutionCell = new DataGridViewLinkCell();
protected PreCheckGridRow()
{
Cells.Add(_iconCell);
Cells.Add(_descriptionCell);
Cells.Add(_solutionCell);
}
}
private class PreCheckHeaderRow : PreCheckGridRow
{
public PreCheckHeaderRow(string text)
{
_iconCell.Value = new Bitmap(1, 1);
_descriptionCell.Value = text;
_descriptionCell.Style.Font = new Font(Program.DefaultFont, FontStyle.Bold);
}
}
private class PreCheckItemRow : PreCheckGridRow
{
private Problem _problem = null;
private Check _check = null;
public PreCheckItemRow(Problem problem)
{
_problem = problem;
_check = problem.Check;
UpdateRowFields();
}
public PreCheckItemRow(Check check)
{
_check = check;
UpdateRowFields();
}
private void UpdateRowFields()
{
_iconCell.Value = Problem == null
? Images.GetImage16For(Icons.Ok)
: Problem.Image;
if (Problem != null)
_descriptionCell.Value = String.Format(Messages.DR_WIZARD_PRECHECKPAGE_PROBLEM, _check.Description, Problem.Description);
else if (_check != null)
{
_descriptionCell.Value = String.Format(Messages.DR_WIZARD_PRECHECKPAGE_OK, _check.Description);
}
_solutionCell.Value = Problem == null ? string.Empty : Problem.HelpMessage;
}
public Problem Problem
{
get
{
return _problem;
}
}
public string Description
{
get
{
return _descriptionCell.Value as string;
}
}
public bool IsProblem
{
get { return _problem != null && !(_problem is Warning); }
}
public bool IsWarning
{
get { return _problem != null && _problem is Warning; }
}
public override bool Equals(object obj)
{
PreCheckItemRow other = obj as PreCheckItemRow;
if (other != null && other.Problem != null && _problem != null)
return _problem.CompareTo(other.Problem) == 0;
return false;
}
public override int GetHashCode()
{
return (_problem != null ? _problem.GetHashCode() : 0);
}
}
#endregion
}
}