mirror of
https://github.com/xcp-ng/xenadmin.git
synced 2024-11-23 20:36:33 +01:00
Made the XenDialogBase's connection a readonly field so it's set in a uniform way throughout the application.
Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
parent
e34cf30168
commit
11cd01900b
@ -43,7 +43,7 @@ namespace XenAdmin.Controls.GPU
|
||||
{
|
||||
public partial class GpuConfiguration : XenDialogBase
|
||||
{
|
||||
private List<PGPU> PGpuList { get; set; }
|
||||
private List<PGPU> PGpuList { get; }
|
||||
|
||||
internal override string HelpName => "GpuConfigurationDialog";
|
||||
|
||||
@ -53,17 +53,11 @@ namespace XenAdmin.Controls.GPU
|
||||
}
|
||||
|
||||
public GpuConfiguration(List<PGPU> pGpuList)
|
||||
: this()
|
||||
: base(pGpuList[0].Connection)
|
||||
{
|
||||
if (pGpuList == null)
|
||||
throw new ArgumentNullException(nameof(pGpuList));
|
||||
if (pGpuList.Count == 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(pGpuList), "pGpuList list is empty");
|
||||
if (pGpuList.ElementAt(0) == null)
|
||||
throw new ArgumentOutOfRangeException(nameof(pGpuList), "First element of the pGpuList list is null");
|
||||
InitializeComponent();
|
||||
|
||||
PGpuList = pGpuList.ToList();
|
||||
connection = PGpuList[0].Connection;
|
||||
PopulateGrid(pGpuList);
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ namespace XenAdmin.Controls.GPU
|
||||
|
||||
private readonly IXenObject xenObject;
|
||||
|
||||
private Dictionary<PGPU, CheckBox> pGpus = new Dictionary<PGPU, CheckBox>();
|
||||
private readonly Dictionary<PGPU, CheckBox> pGpus = new Dictionary<PGPU, CheckBox>();
|
||||
|
||||
private readonly bool vGpuCapability;
|
||||
|
||||
@ -179,19 +179,6 @@ namespace XenAdmin.Controls.GPU
|
||||
}
|
||||
}
|
||||
|
||||
public List<PGPU> SelectedPGPUs
|
||||
{
|
||||
get
|
||||
{
|
||||
if (pGpus.Count == 0)
|
||||
return null;
|
||||
|
||||
return pGpus.Count > 1
|
||||
? (from kvp in pGpus where kvp.Value != null && kvp.Value.Checked select kvp.Key).ToList()
|
||||
: new List<PGPU> {pGpus.Keys.ElementAt(0)};
|
||||
}
|
||||
}
|
||||
|
||||
private void selectAllButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
foreach (var checkBox in pGpus.Values.Where(checkBox => checkBox != null))
|
||||
@ -210,16 +197,23 @@ namespace XenAdmin.Controls.GPU
|
||||
|
||||
private void editButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
using (var dlog = new GpuConfiguration(SelectedPGPUs))
|
||||
if (pGpus.Count == 0)
|
||||
return;
|
||||
|
||||
var selectedPGPUs = pGpus.Count > 1
|
||||
? (from kvp in pGpus where kvp.Value != null && kvp.Value.Checked select kvp.Key).ToList()
|
||||
: new List<PGPU> {pGpus.Keys.ElementAt(0)};
|
||||
|
||||
using (var dlog = new GpuConfiguration(selectedPGPUs))
|
||||
dlog.ShowDialog(Program.MainWindow);
|
||||
}
|
||||
|
||||
private void CheckedChanged(object sender, EventArgs e)
|
||||
{
|
||||
editButton.Enabled = clearAllButton.Enabled =
|
||||
(pGpus.Values.Where(checkBox => checkBox != null).Any(checkBox => checkBox.Checked));
|
||||
pGpus.Values.Any(checkBox => checkBox != null && checkBox.Checked);
|
||||
selectAllButton.Enabled =
|
||||
(pGpus.Values.Where(checkBox => checkBox != null).Any(checkBox => !checkBox.Checked));
|
||||
pGpus.Values.Any(checkBox => checkBox != null && !checkBox.Checked);
|
||||
}
|
||||
|
||||
#region Allowed vGpu types
|
||||
|
@ -51,14 +51,13 @@ namespace XenAdmin.Dialogs
|
||||
/// empty list, this dialog makes no sense otherwise.</param>
|
||||
/// <param name="Host">The host which is exiting maintenance mode</param>
|
||||
public ExitMaintenanceModeDialog(List<VM> VMsToRestore, Host Host)
|
||||
:base(VMsToRestore[0].Connection)
|
||||
{
|
||||
InitializeComponent();
|
||||
System.Diagnostics.Trace.Assert(VMsToRestore != null && VMsToRestore.Count > 0, "There are no VMs to restore");
|
||||
|
||||
this.VMsToRestore = VMsToRestore;
|
||||
TargetHost = Host;
|
||||
labelBlurb.Text = String.Format(labelBlurb.Text, Helpers.GetName(Host).Ellipsise(50));
|
||||
this.connection = VMsToRestore[0].Connection;
|
||||
|
||||
foreach (VM v in VMsToRestore)
|
||||
v.PropertyChanged += v_PropertyChanged;
|
||||
|
@ -58,9 +58,9 @@ namespace XenAdmin.Dialogs.HealthCheck
|
||||
internal override string HelpName { get { return "HealthCheckSettingsDialog"; } }
|
||||
|
||||
public HealthCheckSettingsDialog(Pool pool, bool enrollNow)
|
||||
:base(pool.Connection)
|
||||
{
|
||||
this.pool = pool;
|
||||
this.connection = pool.Connection;
|
||||
healthCheckSettings = pool.HealthCheckSettings();
|
||||
if (enrollNow)
|
||||
healthCheckSettings.Status = HealthCheckStatus.Enabled;
|
||||
|
@ -60,11 +60,12 @@ namespace XenAdmin.Dialogs
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
public NetworkingProperties(Host host,PIF selectedPIF):this()
|
||||
public NetworkingProperties(Host host, PIF selectedPIF)
|
||||
:base(host.Connection)
|
||||
{
|
||||
InitializeComponent();
|
||||
Host = host;
|
||||
Pool = null;
|
||||
connection = host.Connection;
|
||||
ObjectName = Helpers.GetName(host);
|
||||
AllowManagementOnVLAN = !Helpers.FeatureForbidden(connection, Host.RestrictManagementOnVLAN);
|
||||
|
||||
@ -75,10 +76,11 @@ namespace XenAdmin.Dialogs
|
||||
|
||||
|
||||
|
||||
public NetworkingProperties(Pool pool,PIF selectedPIF):this()
|
||||
public NetworkingProperties(Pool pool, PIF selectedPIF)
|
||||
: base(pool.Connection)
|
||||
{
|
||||
InitializeComponent();
|
||||
Pool = pool;
|
||||
connection = pool.Connection;
|
||||
ObjectName = Helpers.GetName(Pool);
|
||||
AllowManagementOnVLAN = !Helpers.FeatureForbidden(connection, Host.RestrictManagementOnVLAN);
|
||||
|
||||
|
@ -30,27 +30,18 @@
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using XenAdmin.Core;
|
||||
using XenAdmin.CustomFields;
|
||||
using XenAdmin.SettingsPanels;
|
||||
using XenAdmin.XenSearch;
|
||||
using XenAdmin.Network;
|
||||
|
||||
namespace XenAdmin.Dialogs
|
||||
{
|
||||
public partial class NewCustomFieldDialog : XenDialogBase
|
||||
{
|
||||
public NewCustomFieldDialog(IXenConnection c)
|
||||
public NewCustomFieldDialog(IXenConnection conn)
|
||||
:base(conn)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.connection = c;
|
||||
|
||||
okButton.Enabled = !string.IsNullOrEmpty(NameTextBox.Text);
|
||||
TypeComboBox.SelectedIndex = 0;
|
||||
}
|
||||
|
@ -47,11 +47,11 @@ namespace XenAdmin.Dialogs
|
||||
public partial class PvsCacheConfigurationDialog : VerticallyTabbedDialog
|
||||
{
|
||||
public PvsCacheConfigurationDialog(IXenConnection connection)
|
||||
:base(connection)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
System.Diagnostics.Trace.Assert(connection != null);
|
||||
this.connection = connection;
|
||||
System.Diagnostics.Debug.Assert(connection != null);
|
||||
|
||||
Text = string.Format(Messages.PVS_CACHE_CONFIG_DIALOG_TITLE, connection.Name);
|
||||
|
||||
|
@ -45,15 +45,15 @@ namespace XenAdmin.Dialogs
|
||||
/// </summary>
|
||||
/// <param name="site">May not be null.</param>
|
||||
public PvsSiteDialog(PVS_site site)
|
||||
: base(site?.Connection)
|
||||
{
|
||||
System.Diagnostics.Trace.Assert(site != null);
|
||||
connection = site.Connection;
|
||||
System.Diagnostics.Debug.Assert(site != null);
|
||||
pvsSite = site;
|
||||
|
||||
InitializeComponent();
|
||||
Text = string.Format(Messages.PVS_SITE_DIALOG_TITLE, pvsSite.Name().Ellipsise(50));
|
||||
|
||||
System.Diagnostics.Trace.Assert(gridView.Columns.Count > 0);
|
||||
System.Diagnostics.Debug.Assert(gridView.Columns.Count > 0);
|
||||
gridView.Columns[0].DefaultCellStyle.NullValue = null;
|
||||
|
||||
RegisterEventHandlers();
|
||||
|
@ -62,9 +62,9 @@ namespace XenAdmin.Dialogs
|
||||
/// <param name="authorizedRoles">A list of roles that are able to complete the task</param>
|
||||
/// <param name="actionTitle">A description of the current action, if null or empty will not be displayed</param>
|
||||
public RoleElevationDialog(IXenConnection connection, Session session, List<Role> authorizedRoles, string actionTitle)
|
||||
:base(connection)
|
||||
{
|
||||
InitializeComponent();
|
||||
this.connection = connection;
|
||||
UserDetails ud = session.CurrentUserDetails;
|
||||
labelCurrentUserValue.Text = ud.UserDisplayName ?? ud.UserName ?? Messages.UNKNOWN_AD_USER;
|
||||
labelCurrentRoleValue.Text = Role.FriendlyCSVRoleList(session.Roles);
|
||||
|
@ -44,17 +44,13 @@ namespace XenAdmin.Dialogs.WarningDialogs
|
||||
{
|
||||
public partial class CloseXenCenterWarningDialog : XenDialogBase
|
||||
{
|
||||
public CloseXenCenterWarningDialog()
|
||||
: this(null)
|
||||
{}
|
||||
|
||||
public CloseXenCenterWarningDialog(IXenConnection connection)
|
||||
public CloseXenCenterWarningDialog(IXenConnection connection = null)
|
||||
:base(connection)
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
if (connection != null)
|
||||
{
|
||||
this.connection = connection;
|
||||
label2.Text = String.Format(Messages.DISCONNECT_WARNING, Helpers.GetName(connection).Ellipsise(50));
|
||||
ExitButton.Text = Messages.DISCONNECT_ANYWAY;
|
||||
DontExitButton.Text = Messages.DISCONNECT_CANCEL;
|
||||
@ -64,13 +60,7 @@ namespace XenAdmin.Dialogs.WarningDialogs
|
||||
BuildList();
|
||||
}
|
||||
|
||||
internal override string HelpName
|
||||
{
|
||||
get
|
||||
{
|
||||
return connection == null ? Name : "DisconnectServerWarningDialog";
|
||||
}
|
||||
}
|
||||
internal override string HelpName => connection == null ? Name : "DisconnectServerWarningDialog";
|
||||
|
||||
private void BuildList()
|
||||
{
|
||||
|
@ -79,45 +79,35 @@ namespace XenAdmin.Dialogs
|
||||
}
|
||||
}
|
||||
|
||||
private IXenConnection _connection;
|
||||
protected IXenConnection connection
|
||||
{
|
||||
get { return _connection; }
|
||||
set
|
||||
{
|
||||
_connection = value;
|
||||
if (_connection != null)
|
||||
{
|
||||
AddInstance(_connection, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public XenDialogBase(IXenConnection connection)
|
||||
: this()
|
||||
{
|
||||
this.connection = connection;
|
||||
}
|
||||
protected readonly IXenConnection connection;
|
||||
|
||||
/// <summary>
|
||||
/// Only use this ctor if you don't want your dialog to be
|
||||
/// closed when a connection disconnects.
|
||||
/// The VS designer does not seem to understand optional parameters,
|
||||
/// it needs the parameterless constructor
|
||||
/// </summary>
|
||||
public XenDialogBase()
|
||||
protected XenDialogBase()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private bool ownerActivatedOnClosed = true;
|
||||
/// <summary>
|
||||
/// If the connection is set, the dialog becomes a per-connection dialog,
|
||||
/// which means it will close when the connection is disconnected
|
||||
/// </summary>
|
||||
protected XenDialogBase(IXenConnection conn)
|
||||
: this()
|
||||
{
|
||||
connection = conn;
|
||||
|
||||
if (connection != null)
|
||||
AddInstance(connection, this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allow the XenDialogBase.OnClosed to set Owner.Activate() - this will push the Owner
|
||||
/// to the top of the windows stack stealing focus.
|
||||
/// </summary>
|
||||
protected bool OwnerActivatedOnClosed
|
||||
{
|
||||
get { return ownerActivatedOnClosed; }
|
||||
set { ownerActivatedOnClosed = value; }
|
||||
}
|
||||
protected bool OwnerActivatedOnClosed { get; set; } = true;
|
||||
|
||||
protected override void OnClosed(EventArgs e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user