CP-6093: Remove update alerts from the Alerts page, part 1/3: some code simplification

and efficiency improvements.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2013-11-21 14:11:29 +00:00
parent 361b49066c
commit fcc627113d
5 changed files with 25 additions and 56 deletions

View File

@ -69,7 +69,7 @@ namespace XenAdmin.Alerts
/// <summary>
/// Can we apply this alert. Calling this sets the CannotApplyReason where applicable
/// </summary>
public override bool CanApply
public bool CanApply
{
get
{

View File

@ -40,9 +40,7 @@ namespace XenAdmin.Core
{
class ManualCheckForUpdates
{
private static List<XenCenterVersion> XenCenterVersions = new List<XenCenterVersion>();
private static List<XenServerVersion> XenServerVersions = new List<XenServerVersion>();
private static List<XenServerPatch> XenServerPatches = new List<XenServerPatch>();
private readonly List<Alert> updateAlerts = new List<Alert>();
public event Action<bool, string> CheckForUpdatesCompleted;
@ -53,35 +51,7 @@ namespace XenAdmin.Core
public List<Alert> UpdateAlerts
{
get
{
List<Alert> updateAlerts = new List<Alert>();
XenCenterUpdateAlert xenCenterAlert = Updates.NewXenCenterVersionAlert(XenCenterVersions, false);
if (xenCenterAlert != null)
{
updateAlerts.Add(xenCenterAlert);
}
XenServerUpdateAlert xenServerUpdateAlert = Updates.NewServerVersionAlert(XenServerVersions, false);
if (xenServerUpdateAlert != null)
{
updateAlerts.Add(xenServerUpdateAlert);
}
List<XenServerPatchAlert> xenServerPatchAlerts = Updates.NewServerPatchesAlerts(XenServerVersions,
XenServerPatches,
false);
if (xenServerPatchAlerts != null)
{
foreach (var xenServerPatchAlert in xenServerPatchAlerts)
{
updateAlerts.Add(xenServerPatchAlert);
}
}
return updateAlerts;
}
get { return updateAlerts; }
}
private void actionCompleted(ActionBase sender)
@ -95,18 +65,27 @@ namespace XenAdmin.Core
if (action != null)
{
succeeded = action.Succeeded;
updateAlerts.Clear();
if (succeeded)
{
XenCenterVersions = action.XenCenterVersions;
XenServerVersions = action.XenServerVersions;
XenServerPatches = action.XenServerPatches;
var xenCenterAlert = Updates.NewXenCenterVersionAlert(action.XenCenterVersions, false);
if (xenCenterAlert != null)
updateAlerts.Add(xenCenterAlert);
var xenServerUpdateAlert = Updates.NewServerVersionAlert(action.XenServerVersions, false);
if (xenServerUpdateAlert != null)
updateAlerts.Add(xenServerUpdateAlert);
var xenServerPatchAlerts = Updates.NewServerPatchesAlerts(action.XenServerVersions, action.XenServerPatches, false);
if (xenServerPatchAlerts != null)
{
foreach (var xenServerPatchAlert in xenServerPatchAlerts)
updateAlerts.Add(xenServerPatchAlert);
}
}
else
{
XenCenterVersions.Clear();
XenServerVersions.Clear();
XenServerPatches.Clear();
if (action.Exception != null)
{
if (action.Exception is System.Net.Sockets.SocketException)

View File

@ -33,8 +33,6 @@ using System;
using System.Collections.Generic;
using System.Linq;
using XenAdmin.Actions;
using System.Windows.Forms;
using XenAdmin.Dialogs;
using XenAPI;
using XenAdmin.Alerts;
using XenAdmin.Network;
@ -349,13 +347,5 @@ namespace XenAdmin.Core
return alert;
}
/// <summary>
/// Equivalent to CheckForUpdates().
/// </summary>
internal static void Tick(object sender, EventArgs e)
{
AutomaticCheckForUpdates();
}
}
}

View File

@ -550,13 +550,18 @@ namespace XenAdmin
// start checkforupdates thread
CheckForUpdatesTimer.Interval = 1000 * 60 * 60 * 24; // 24 hours
CheckForUpdatesTimer.Tick += Updates.Tick;
CheckForUpdatesTimer.Tick += CheckForUpdatesTimer_Tick;
CheckForUpdatesTimer.Start();
Updates.AutomaticCheckForUpdates();
}
ProcessCommand(CommandLineArgType, CommandLineParam);
}
private void CheckForUpdatesTimer_Tick(object sender, EventArgs e)
{
Updates.AutomaticCheckForUpdates();
}
private void LoadTasksAsMeddlingActions(IXenConnection connection)
{
if (!connection.IsConnected || connection.Session == null)

View File

@ -48,11 +48,6 @@ namespace XenAdmin.Alerts
public bool Dismissing;
public virtual bool CanApply
{
get { return true; }
}
public string CannotApplyReason { get; set; }
public static void AddAlert(Alert a)