Show the product brand alongside the version. Minor code smells.

Signed-off-by: Konstantina Chremmou <Konstantina.Chremmou@cloud.com>
This commit is contained in:
Konstantina Chremmou 2023-08-10 01:21:25 +01:00
parent c7411c0bb2
commit 4b64b3a261
2 changed files with 44 additions and 71 deletions

View File

@ -1006,8 +1006,7 @@ namespace XenAdmin.Wizards.PatchingWizard
private void UpdateDetails()
{
var pool = Tag as Pool;
if (pool != null)
if (Tag is Pool pool)
{
Host coordinator = pool.Connection.Resolve(pool.master);
if (_poolCheckBoxCell.Value == null)
@ -1015,12 +1014,11 @@ namespace XenAdmin.Wizards.PatchingWizard
_expansionCell.Value = Images.StaticImages.tree_minus;
_poolIconHostCheckCell.Value = Images.GetImage16For(pool);
_nameCell.Value = pool;
_versionCell.Value = coordinator.ProductVersionTextShort();
_versionCell.Value = $"{coordinator.ProductBrand()} {coordinator.ProductVersionTextShort()}";
return;
}
var host = Tag as Host;
if (host != null)
if (Tag is Host host)
{
if (_poolCheckBoxCell.Value == null)
_poolCheckBoxCell.Value = CheckState.Unchecked;
@ -1033,7 +1031,7 @@ namespace XenAdmin.Wizards.PatchingWizard
else
_poolIconHostCheckCell.Value = Images.GetImage16For(host);
_nameCell.Value = host;
_versionCell.Value = host.ProductVersionTextShort();
_versionCell.Value = $"{host.ProductBrand()} {host.ProductVersionTextShort()}";
}
}

View File

@ -31,14 +31,14 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Forms;
using XenAdmin.Controls;
using XenAdmin.Controls.DataGridViewEx;
using XenAdmin.Core;
using XenAdmin.Network;
using System.Linq;
using XenAPI;
using XenAdmin.Dialogs;
using XenAdmin.Network;
using XenAPI;
namespace XenAdmin.Wizards.RollingUpgradeWizard
@ -48,30 +48,15 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
public RollingUpgradeWizardSelectPool()
{
InitializeComponent();
this.dataGridView1.CheckBoxClicked += DataGridRowClicked;
this.Dock = DockStyle.Fill;
dataGridView1.CheckBoxClicked += DataGridRowClicked;
Dock = DockStyle.Fill;
}
public override string Text
{
get
{
return Messages.SELECT_POOL;
}
}
public override string Text => Messages.SELECT_POOL;
public override string PageTitle
{
get
{
return Messages.SELECT_POOL;
}
}
public override string PageTitle => Messages.SELECT_POOL;
public override string HelpID
{
get { return "Selectpool"; }
}
public override string HelpID => "Selectpool";
protected override void PageLeaveCore(PageLoadedDirection direction, ref bool cancel)
{
@ -136,16 +121,15 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
List<Host> hosts = new List<Host>();
foreach (UpgradeDataGridViewRow row in dataGridView1.Rows)
{
if (row.Tag is Host)
if (row.Tag is Host host)
{
if (!row.HasPool && ((int)row.Cells[1].Value) == 1)
hosts.Add((Host)row.Tag);
if (!row.HasPool && (int)row.Cells[1].Value == 1)
hosts.Add(host);
}
else if (row.Tag is Pool && ((int)row.Cells[1].Value) == 1)
else if (row.Tag is Pool pool && (int)row.Cells[1].Value == 1)
{
Pool pool = ((Pool)(row.Tag));
Host host = pool.Connection.Resolve(pool.master);
hosts.Add(host);
Host coordinator = pool.Connection.Resolve(pool.master);
hosts.Add(coordinator);
}
}
return hosts;
@ -241,13 +225,19 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
private class UpgradeDataGridView : PoolHostDataGridViewOneCheckbox
{
public UpgradeDataGridView(){}
public UpgradeDataGridView(IContainer container) : base(container){}
public UpgradeDataGridView()
{
}
public UpgradeDataGridView(IContainer container)
: base(container)
{
}
protected override void SortColumns()
{
UpgradeDataGridViewRow firstRow = Rows[0] as UpgradeDataGridViewRow;
if (firstRow == null) return;
if (!(Rows[0] is UpgradeDataGridViewRow firstRow))
return;
if (columnToBeSortedIndex == firstRow.NameCellIndex ||
columnToBeSortedIndex == firstRow.DescriptionCellIndex ||
@ -259,14 +249,11 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
{
base.OnCellPainting(e);
if (e.RowIndex >= 0)
if (e.RowIndex >= 0 && Rows[e.RowIndex] is PoolHostDataGridViewOneCheckboxRow row &&
!row.Enabled && e.ColumnIndex == row.PoolCheckBoxCellIndex)
{
var row = (PoolHostDataGridViewOneCheckboxRow)Rows[e.RowIndex];
if (row != null && !row.Enabled && e.ColumnIndex == row.PoolCheckBoxCellIndex)
{
e.PaintBackground(e.ClipBounds, true);
e.Handled = true;
}
e.PaintBackground(e.ClipBounds, true);
e.Handled = true;
}
}
}
@ -286,25 +273,13 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
{
}
public int DescriptionCellIndex
{
get { return Cells.IndexOf(_description); }
}
public int DescriptionCellIndex => Cells.IndexOf(_description);
public int VersionCellIndex
{
get { return Cells.IndexOf(_version); }
}
public int VersionCellIndex => Cells.IndexOf(_version);
public string DescriptionText
{
get { return (string) Cells[DescriptionCellIndex].Value; }
}
public string DescriptionText => (string) Cells[DescriptionCellIndex].Value;
public string VersionText
{
get { return (string)Cells[VersionCellIndex].Value; }
}
public string VersionText => (string)Cells[VersionCellIndex].Value;
protected override void SetupAdditionalDetailsColumns()
{
@ -317,13 +292,14 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
protected override void UpdateAdditionalDetailsForPool(Pool pool, Host coordinator)
{
_description.Value = pool.Description();
_version.Value = pool.SmallerVersionHost().ProductVersionTextShort();
var host = pool.SmallerVersionHost();
_version.Value = $"{host.ProductBrand()} {host.ProductVersionTextShort()}";
}
protected override void UpdateAdditionalDetailsForHost( Host host )
{
_description.Value = host.Description();
_version.Value = host.ProductVersionTextShort();
_version.Value = $"{host.ProductBrand()} {host.ProductVersionTextShort()}";
}
}
@ -331,9 +307,8 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
{
foreach (UpgradeDataGridViewRow row in dataGridView1.Rows)
{
var checkrow = row.Cells[1] as DataGridViewCheckBoxCell;
if (row.Enabled)
checkrow.Value = 1;
if (row.Enabled && row.Cells[1] is DataGridViewCheckBoxCell checkCell)
checkCell.Value = 1;
}
OnPageUpdated();
}
@ -342,8 +317,8 @@ namespace XenAdmin.Wizards.RollingUpgradeWizard
{
foreach (DataGridViewRow row in dataGridView1.Rows)
{
var checkrow = row.Cells[1] as DataGridViewCheckBoxCell;
checkrow.Value = 0;
if (row.Cells[1] is DataGridViewCheckBoxCell checkCell)
checkCell.Value = 0;
}
OnPageUpdated();
}