CA-326341: Refresh the hotfix eligibility alerts after a check for updates is completed

Signed-off-by: Mihaela Stoica <mihaela.stoica@citrix.com>
This commit is contained in:
Mihaela Stoica 2019-09-04 13:21:57 +01:00 committed by Joey
parent 3f5125b293
commit b7c64bddb2
4 changed files with 57 additions and 0 deletions

View File

@ -980,5 +980,31 @@ namespace XenAdmin.Core
else
Alert.RefreshAlertAt(alertIndex);
}
public static void CheckHotfixEligibility()
{
var alerts = new List<HotfixEligibilityAlert>();
foreach (var connection in ConnectionsManager.XenConnectionsCopy)
{
if (!connection.IsConnected)
continue;
var master = Helpers.GetMaster(connection);
if (master == null)
continue;
var hotfixEligibility = HotfixEligibility(master, out var xenServerVersion);
if (xenServerVersion == null || hotfixEligibility == hotfix_eligibility.all ||
hotfixEligibility == hotfix_eligibility.premium && !master.IsFreeLicenseOrExpired())
continue;
alerts.Add(new HotfixEligibilityAlert(connection, xenServerVersion));
}
Alert.RemoveAlert(a => a is HotfixEligibilityAlert);
Alert.AddAlertRange(alerts);
}
}
}

View File

@ -16,6 +16,7 @@ namespace XenAdmin.TabPages
if (disposing)
{
DeregisterEventHandlers();
DeregisterCheckForUpdatesEvents();
if (components != null)
components.Dispose();

View File

@ -69,6 +69,7 @@ namespace XenAdmin.TabPages
UpdateActionEnablement();
m_alertCollectionChangedWithInvoke = Program.ProgramInvokeHandler(AlertsCollectionChanged);
RegisterCheckForUpdatesEvents();
toolStripSplitButtonDismiss.DefaultItem = tsmiDismissAll;
toolStripSplitButtonDismiss.Text = tsmiDismissAll.Text;
@ -834,5 +835,22 @@ namespace XenAdmin.TabPages
Clip.SetClipboardText(alert.GetUpdateDetailsCSVQuotes());
}
#region CheckForUpdates events
private void RegisterCheckForUpdatesEvents()
{
Updates.CheckForUpdatesCompleted += CheckForUpdatesCompleted;
}
private void DeregisterCheckForUpdatesEvents()
{
Updates.CheckForUpdatesCompleted -= CheckForUpdatesCompleted;
}
private void CheckForUpdatesCompleted(bool succeeded, string errorMessage)
{
Updates.CheckHotfixEligibility();
}
#endregion
}
}

View File

@ -61,6 +61,18 @@ namespace XenAdmin.Alerts
log.Error("Failed to add incoming alert", e);
}
}
public static void AddAlertRange(IEnumerable<Alert> collection)
{
try
{
lock (XenCenterAlertsLock)
XenCenterAlerts.AddRange(collection);
}
catch (Exception e)
{
log.Error("Failed to add incoming alerts", e);
}
}
public static void RemoveAlert(Alert a)
{