public static void RemoveUpdate(Alert update) { lock (updateAlertsLock) updateAlerts.Remove(update); UpdateAlertCollectionChanged?.Invoke(new CollectionChangeEventArgs(CollectionChangeAction.Remove, update)); }
public static void RefreshUpdateAlerts(UpdateType flags) { var alerts = new List <XenServerUpdateAlert>(); if (flags.HasFlag(UpdateType.ServerVersion)) { alerts.AddRange(NewXenServerVersionAlerts(XenServerVersionsForAutoCheck)); } if (flags.HasFlag(UpdateType.ServerPatches)) { alerts.AddRange(NewXenServerPatchAlerts(XenServerVersions, XenServerPatches)); } bool changed = false; try { lock (updateAlertsLock) { foreach (var alert in alerts) { var existingAlert = updateAlerts.FirstOrDefault(a => a.Equals(alert)); if (existingAlert != null && alert.CanIgnore) { updateAlerts.Remove(existingAlert); changed = true; } else if (existingAlert is XenServerUpdateAlert updAlert) { updateAlerts.Remove(updAlert); updAlert.CopyConnectionsAndHosts(alert); if (!updateAlerts.Contains(updAlert)) { updateAlerts.Add(updAlert); } changed = true; } else if (!alert.CanIgnore && !updateAlerts.Contains(alert)) { updateAlerts.Add(alert); changed = true; } } } if (changed) { UpdateAlertCollectionChanged?.Invoke(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, UpdateAlerts)); } } catch (Exception e) { log.Error("Failed to refresh the updates", e); } }
private static void actionCompleted(ActionBase sender) { Program.AssertOffEventThread(); if (!(sender is DownloadUpdatesXmlAction action)) { return; } bool succeeded = action.Succeeded; string errorMessage = string.Empty; if (succeeded) { lock (downloadedUpdatesLock) { XenCenterVersions = action.XenCenterVersions; XenServerVersionsForAutoCheck = action.XenServerVersionsForAutoCheck; XenServerVersions = action.XenServerVersions; XenServerPatches = action.XenServerPatches; } } else { if (action.Exception != null) { if (action.Exception is System.Net.Sockets.SocketException) { errorMessage = Messages.AVAILABLE_UPDATES_NETWORK_ERROR; } else { // Clean up and remove excess newlines, carriage returns, trailing nonsense string errorText = action.Exception.Message.Trim(); errorText = System.Text.RegularExpressions.Regex.Replace(errorText, @"\r\n+", ""); errorMessage = string.Format(Messages.AVAILABLE_UPDATES_ERROR, errorText); } } if (string.IsNullOrEmpty(errorMessage)) { errorMessage = Messages.AVAILABLE_UPDATES_INTERNAL_ERROR; } } lock (updateAlertsLock) { updateAlerts.Clear(); if (succeeded) { var xenCenterAlerts = NewXenCenterUpdateAlerts(XenCenterVersions, Program.Version); updateAlerts.AddRange(xenCenterAlerts.Where(a => !a.IsDismissed())); var xenServerUpdateAlerts = NewXenServerVersionAlerts(XenServerVersionsForAutoCheck); updateAlerts.AddRange(xenServerUpdateAlerts.Where(a => !a.CanIgnore)); var xenServerPatchAlerts = NewXenServerPatchAlerts(XenServerVersions, XenServerPatches); updateAlerts.AddRange(xenServerPatchAlerts.Where(a => !a.CanIgnore)); } } UpdateAlertCollectionChanged?.Invoke(new CollectionChangeEventArgs(CollectionChangeAction.Refresh, UpdateAlerts)); CheckForUpdatesCompleted?.Invoke(succeeded, errorMessage); }