Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small corrections to repo syncing and the behaviour of some gridview rows #3252

Merged
merged 3 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions XenAdmin/Alerts/Types/OutOfSyncWithCdnAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ public override Action FixLinkAction
{
return () =>
{
var syncAction = new SyncWithCdnAction(_pool);
syncAction.Completed += a => Updates.CheckForCdnUpdates(a.Connection);
var syncAction = Updates.CreateSyncWithCdnAction(_pool);
syncAction.RunAsync();
};
}
Expand Down
3 changes: 1 addition & 2 deletions XenAdmin/Commands/PoolUpdatesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ protected override void RunCore(SelectedItemCollection selection)

foreach (var pool in pools)
{
var syncAction = new SyncWithCdnAction(pool);
syncAction.Completed += a => Updates.CheckForCdnUpdates(a.Connection);
var syncAction = Updates.CreateSyncWithCdnAction(pool);
syncAction.RunAsync();
}
}
Expand Down
25 changes: 7 additions & 18 deletions XenAdmin/Controls/DataGridViewEx/DataGridViewExRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,27 @@ namespace XenAdmin.Controls.DataGridViewEx
{
public class DataGridViewExRow : DataGridViewRow, IComparable<DataGridViewExRow>
{
public DataGridViewExRow()
: this(true)
{
private bool _enabled = true;

}

public DataGridViewExRow(bool enabled)
public DataGridViewExRow()
{
Enabled = enabled;
UpdateDefaultCellStyle();
}

private bool enabled;

public virtual bool Enabled
{
get
{
return enabled;
}
get => _enabled;
set
{
enabled = value;

_enabled = value;
UpdateDefaultCellStyle();
}
}

public void UpdateDefaultCellStyle()
{
DataGridViewEx dgv = this.DataGridView as DataGridViewEx;
if (dgv != null)
DefaultCellStyle = dgv.GetRowCellStyle(enabled, DataGridView != null ? DataGridView.Enabled : true);
if (DataGridView is DataGridViewEx dgv)
DefaultCellStyle = dgv.GetRowCellStyle(_enabled, DataGridView?.Enabled ?? true);
}

public int CompareTo(DataGridViewExRow other)
Expand Down
2 changes: 2 additions & 0 deletions XenAdmin/Controls/PDSection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ private void RunCellCommandOrAction(DataGridViewCell cell)
{
if (cell == null)
return;
if (cell.OwningRow is DataGridViewExRow row && !row.Enabled)
return;

if (cell.Tag is Command command)
command.Run();
Expand Down
11 changes: 11 additions & 0 deletions XenAdmin/Core/Updates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ public static void RemoveCdnInfoForConnection(IXenConnection connection)
CdnUpdateInfoChanged?.Invoke(connection);
}

public static SyncWithCdnAction CreateSyncWithCdnAction(Pool pool)
{
var syncAction = new SyncWithCdnAction(pool);
syncAction.Completed += a =>
{
if (a.Succeeded)
CheckForCdnUpdates(a.Connection);
};
return syncAction;
Comment on lines +125 to +131
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an instance whereby we sync and not check for updates? Since we always run CheckForCdnUpdates after SyncWithCdnAction, should we just be adding CheckForCdnUpdatesAction in SyncWithCdnAction:Run, or is that a side effect?

Usually I'd be against having one action do two things, but I don't see why we'd run sync without the check afterwards, so it sort of is the same action.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only reason is that SyncWithCdnAction has to call CheckForCdnUpdates, not CheckForCdnUpdatesAction, and the former uses concepts (the Registry) which belong to XenAdmin, not XenModel, and it is not straight forward, if feasible, to move it because it blurrs the interface between business and UI logic (which is already not very clean in some areas).

}

public static void CheckForCdnUpdates(IXenConnection connection, bool runSynchronous = false)
{
var action = new CheckForCdnUpdatesAction(connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ public CdnOutOfSyncProblem(Check check, Pool pool, int days)
protected override AsyncAction CreateAction(out bool cancelled)
{
cancelled = false;
var syncAction = new SyncWithCdnAction(Pool);
syncAction.Completed += a => Updates.CheckForCdnUpdates(a.Connection);
return syncAction;
return Updates.CreateSyncWithCdnAction(Pool);
}
}

Expand Down
3 changes: 1 addition & 2 deletions XenAdmin/Dialogs/ServerUpdates/ConfigCdnUpdatesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,7 @@ public void Save()
if (dlog.ShowDialog(this) == DialogResult.Yes)
changedRepoPools.ForEach(p =>
{
var syncAction = new SyncWithCdnAction(p);
syncAction.Completed += a => Updates.CheckForCdnUpdates(a.Connection);
var syncAction = Updates.CreateSyncWithCdnAction(p);
syncAction.RunAsync();
});
}
Expand Down
3 changes: 1 addition & 2 deletions XenAdmin/TabPages/GeneralTabPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,9 +638,8 @@ private void GenerateCdnUpdatesBox(Pool pool)
lastSyncTime, Messages.UPDATES_GENERAL_TAB_SYNC_NOW,
() =>
{
var syncAction = new SyncWithCdnAction(pool);
var syncAction = Updates.CreateSyncWithCdnAction(pool);
BuildList();
syncAction.Completed += a => Updates.CheckForCdnUpdates(a.Connection);
syncAction.RunAsync();
}, enabled);
}
Expand Down
3 changes: 1 addition & 2 deletions XenAdmin/TabPages/ManageCdnUpdatesPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,8 @@ private void CollapseRow(CdnExpandableRow row)

private void SyncPool(Pool pool)
{
var syncAction = new SyncWithCdnAction(pool);
var syncAction = Updates.CreateSyncWithCdnAction(pool);
UpdateButtonEnablement();
syncAction.Completed += a => Updates.CheckForCdnUpdates(a.Connection);
syncAction.RunAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,11 +821,11 @@ private void UpdateRowFields()

_solutionCell.Value = Problem == null ? string.Empty : Problem.HelpMessage;

if (Problem is WarningWithInformationUrl)
_solutionCell.Value = (Problem as WarningWithInformationUrl).LinkText;
if (Problem is WarningWithInformationUrl wrn)
_solutionCell.Value = wrn.LinkText;

if (Problem is ProblemWithInformationUrl)
_solutionCell.Value = (Problem as ProblemWithInformationUrl).LinkText;
if (Problem is ProblemWithInformationUrl prb)
_solutionCell.Value = prb.LinkText;

UpdateSolutionCellStyle();
}
Expand All @@ -834,6 +834,7 @@ private void UpdateSolutionCellStyle()
{
if (_solutionCell == null)
return;

if (Enabled)
{
_solutionCell.Style.Font = new Font(Program.DefaultFont, FontStyle.Underline);
Expand Down
14 changes: 0 additions & 14 deletions XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectServers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -922,20 +922,6 @@ public PatchingHostsDataGridViewRow(Host host, bool hasPool, bool showHostCheckB

public override bool IsCheckable => !HasPool;

public override bool Enabled
{
get => base.Enabled;
set
{
base.Enabled = value;
UpdateDetails();
}
}

public int CheckValue => IsPoolOrStandaloneHost
? (int)Cells[POOL_CHECKBOX_COL].Value
: (int)Cells[POOL_ICON_HOST_CHECKBOX_COL].Value;

public bool IsSelectableHost => IsAHostRow && Enabled && (_showHostCheckBox || !HasPool);

public bool IsSelectablePool => IsAPoolRow && Enabled;
Expand Down
2 changes: 2 additions & 0 deletions XenModel/Actions/Updates/CheckForCdnUpdatesAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ protected override void Run()
else
throw;
}

Description = Messages.COMPLETED;
}
}
}
1 change: 1 addition & 0 deletions XenModel/Actions/Updates/SyncWithCdnAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected override void Run()
{
RelatedTask = Pool.async_sync_updates(Session, _pool.opaque_ref, false, "", "");
PollToCompletion();
Description = Messages.COMPLETED;
}
}
}
Loading