CP-36392: Refactored to avoid having unused object instantiations of the ActionBase class.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2022-04-05 23:15:38 +01:00
parent d2548ae4c0
commit 04ac8249a6
5 changed files with 19 additions and 15 deletions

View File

@ -139,9 +139,9 @@ namespace XenAdmin.Commands
private void DoDisconnect(IXenConnection connection)
{
string msg = string.Format(Messages.CONNECTION_CLOSED_NOTICE_TEXT, connection.Hostname);
ActionBase notice = new ActionBase(msg, msg, false, true);
notice.Pool = Helpers.GetPoolOfOne(connection);
notice.Host = Helpers.GetCoordinator(connection);
var action = ActionBase.CreateDummyAction(msg, msg);
action.Pool = Helpers.GetPoolOfOne(connection);
action.Host = Helpers.GetCoordinator(connection);
log.Warn($"Connection to {connection.Hostname} closed.");
MainWindowCommandInterface.CloseActiveWizards(connection);

View File

@ -70,7 +70,7 @@ namespace XenAdmin.Commands
{
string msg = string.Format(Messages.MAINWINDOW_LOG_REMOVECONNECTION, host.Connection.Hostname);
log.Info($"Removed connection to {host.Connection.Hostname}");
new ActionBase(msg, msg, false, true);
ActionBase.CreateDummyAction(msg, msg);
MainWindowCommandInterface.CloseActiveWizards(host.Connection);
host.Connection.EndConnect();
MainWindowCommandInterface.RemoveConnection(host.Connection);

View File

@ -918,7 +918,7 @@ namespace XenAdmin
Program.Invoke(Program.MainWindow, delegate
{
var title = string.Format(Messages.CONNECTION_REFUSED_TITLE, Helpers.GetName(coordinator).Ellipsise(80));
new ActionBase(title, "", false, true, string.Format(Messages.INCOMPATIBLE_PRODUCTS, BrandManager.BrandConsole));
ActionBase.CreateDummyAction(title, "", error: string.Format(Messages.INCOMPATIBLE_PRODUCTS, BrandManager.BrandConsole));
using (var dlog = new ErrorDialog(string.Format(Messages.INCOMPATIBLE_PRODUCTS, BrandManager.BrandConsole))
{WindowTitle = title})
@ -944,7 +944,7 @@ namespace XenAdmin
var title = string.Format(Messages.CONNECTION_REFUSED_TITLE, Helpers.GetName(coordinator).Ellipsise(80));
var msg = string.Format(Messages.SUPPORTER_TOO_OLD, BrandManager.ProductBrand, BrandManager.ProductVersion70, BrandManager.BrandConsole);
new ActionBase(title, "", false, true, msg);
ActionBase.CreateDummyAction(title, "", error: msg);
using (var dlg = new ErrorDialog(msg, ThreeButtonDialog.ButtonOK)
{WindowTitle = Messages.CONNECT_TO_SERVER})
@ -983,7 +983,7 @@ namespace XenAdmin
var title = string.Format(Messages.CONNECTION_REFUSED_TITLE, Helpers.GetName(coordinator).Ellipsise(80));
var error = $"{msg}\n{url}";
new ActionBase(title, "", false, true, error);
ActionBase.CreateDummyAction(title, "", error: error);
using (var dlog = new ErrorDialog(msg)
{
@ -1012,7 +1012,7 @@ namespace XenAdmin
var title = string.Format(Messages.CONNECTION_REFUSED_TITLE, Helpers.GetName(coordinator).Ellipsise(80));
var error = $"{msg}\n{url}";
new ActionBase(title, "", false, true, error);
ActionBase.CreateDummyAction(title, "", error: error);
using (var dlog = new ErrorDialog(msg)
{

View File

@ -230,8 +230,7 @@ namespace XenAdmin.Actions
public bool ShowProgress { get; protected set; } = true;
public ActionBase(string title, string description, bool suppressHistory, bool completeImmediately = false, string error = null)
protected ActionBase(string title, string description, bool suppressHistory, bool completeImmediately = false, string error = null)
{
Title = title;
_description = description;
@ -250,6 +249,11 @@ namespace XenAdmin.Actions
NewAction?.Invoke(this);
}
public static ActionBase CreateDummyAction(string title, string description, bool completeImmediately = true, string error = null)
{
return new ActionBase(title, description, false, completeImmediately, error);
}
/// <remarks>
/// If you want to set the PercentComplete and the Description at the
/// same time, use Tick() in order to avoid firing OnChanged() twice
@ -310,7 +314,7 @@ namespace XenAdmin.Actions
protected bool SuppressProgressReport { get; set; }
public void Tick(int percent, string description)
protected void Tick(int percent, string description)
{
if (_percentComplete != percent || _description != description)
{

View File

@ -953,7 +953,7 @@ namespace XenAdmin.Network
string msg = string.Format(Messages.CONNECTING_NOTICE_TEXT, name);
log.Info($"Connecting to {name} in progress.");
ConnectAction = new ActionBase(title, msg, false);
ConnectAction = ActionBase.CreateDummyAction(title, msg, false);
ExpectPasswordIsCorrect = true;
OnConnectionResult(true, null, null);
@ -1447,7 +1447,7 @@ namespace XenAdmin.Network
{
// Create a new log message to say the connection attempt failed
string title = string.Format(Messages.CONNECTION_FAILED_TITLE, HostnameWithPort);
ActionBase n = new ActionBase(title, reason, false, true, reason);
ActionBase n = ActionBase.CreateDummyAction(title, reason, error:reason);
SetPoolAndHostInAction(n, pool, PoolOpaqueRef);
}
@ -1598,7 +1598,7 @@ namespace XenAdmin.Network
string title = string.Format(Messages.CONNECTION_LOST_NOTICE_TITLE,
LastConnectionFullName);
ActionBase n = new ActionBase(title, description, false, true, description);
ActionBase n = ActionBase.CreateDummyAction(title, description, error: description);
SetPoolAndHostInAction(n, pool, poolopaqueref);
OnConnectionLost();
}
@ -1740,7 +1740,7 @@ namespace XenAdmin.Network
// Add an informational entry to the log
string title = string.Format(Messages.CONNECTION_FINDING_COORDINATOR_TITLE, LastConnectionFullName);
string descr = string.Format(Messages.CONNECTION_FINDING_COORDINATOR_DESCRIPTION, LastConnectionFullName, Hostname);
ActionBase action = new ActionBase(title, descr, false, true);
ActionBase action = ActionBase.CreateDummyAction(title, descr);
SetPoolAndHostInAction(action, null, PoolOpaqueRef);
log.DebugFormat("Looking for coordinator for {0} on {1}...", LastConnectionFullName, Hostname);