CA-67866: Step 2 - moved code common to XenServerPatchAlert and XenServerVersionAlert

to a base class XenServerUpdateAlert.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2014-01-03 08:51:14 +00:00
parent 0eaf776399
commit cc78711c56
4 changed files with 96 additions and 95 deletions

View File

@ -40,10 +40,8 @@ using XenAPI;
namespace XenAdmin.Alerts
{
public class XenServerPatchAlert : Alert
public class XenServerPatchAlert : XenServerUpdateAlert
{
private readonly List<IXenConnection> connections = new List<IXenConnection>();
private readonly List<Host> hosts = new List<Host>();
public List<Host> Hosts
{
get
@ -60,10 +58,6 @@ namespace XenAdmin.Alerts
}
}
private bool canIgnore;
public bool CanIgnore
{ get { return canIgnore; } }
public XenServerPatch Patch;
/// <summary>
@ -110,29 +104,6 @@ namespace XenAdmin.Alerts
_timestamp = Patch.TimeStamp;
canIgnore = true;
}
public void IncludeConnection(IXenConnection newConnection)
{
connections.Add(newConnection);
if (connections.Count > 0)
canIgnore = false;
}
public void IncludeHosts(IEnumerable<Host> newHosts)
{
hosts.AddRange(newHosts);
if (hosts.Count > 0)
canIgnore = false;
}
public void CopyConnectionsAndHosts(XenServerPatchAlert alert)
{
connections.Clear();
connections.AddRange(alert.connections);
hosts.Clear();
hosts.AddRange(alert.hosts);
canIgnore = connections.Count == 0 && hosts.Count == 0;
}
public override string WebPageLabel
{
@ -154,22 +125,6 @@ namespace XenAdmin.Alerts
}
}
public override string AppliesTo
{
get
{
List<string> names = new List<string>();
foreach (Host host in hosts)
names.Add(host.Name);
foreach (IXenConnection connection in connections)
names.Add(Helpers.GetName(connection));
return string.Join(", ", names.ToArray());
}
}
public override string Description
{
get { return Patch.Description; }
@ -218,9 +173,7 @@ namespace XenAdmin.Alerts
{
base.Dismiss();
foreach (IXenConnection connection in connections)
{
new IgnorePatchAction(connection, Patch).RunAsync();
}
}
public override bool Equals(Alert other)

View File

@ -0,0 +1,93 @@
/* Copyright (c) Citrix Systems Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms,
* with or without modification, are permitted provided
* that the following conditions are met:
*
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
using System;
using System.Collections.Generic;
using System.Linq;
using XenAdmin.Network;
using XenAdmin.Actions;
using XenAdmin.Core;
using XenAPI;
namespace XenAdmin.Alerts
{
public abstract class XenServerUpdateAlert : Alert
{
protected readonly List<IXenConnection> connections = new List<IXenConnection>();
protected readonly List<Host> hosts = new List<Host>();
protected bool canIgnore;
public bool CanIgnore
{
get { return canIgnore; }
}
public void IncludeConnection(IXenConnection newConnection)
{
connections.Add(newConnection);
if (connections.Count > 0)
canIgnore = false;
}
public void IncludeHosts(IEnumerable<Host> newHosts)
{
hosts.AddRange(newHosts);
if (hosts.Count > 0)
canIgnore = false;
}
public void CopyConnectionsAndHosts(XenServerUpdateAlert alert)
{
connections.Clear();
connections.AddRange(alert.connections);
hosts.Clear();
hosts.AddRange(alert.hosts);
canIgnore = connections.Count == 0 && hosts.Count == 0;
}
public override string AppliesTo
{
get
{
List<string> names = new List<string>();
foreach (Host host in hosts)
names.Add(host.Name);
foreach (IXenConnection connection in connections)
names.Add(Helpers.GetName(connection));
return string.Join(", ", names.ToArray());
}
}
}
}

View File

@ -40,15 +40,8 @@ using XenAPI;
namespace XenAdmin.Alerts
{
public class XenServerVersionAlert : Alert
public class XenServerVersionAlert : XenServerUpdateAlert
{
private readonly List<IXenConnection> connections = new List<IXenConnection>();
private readonly List<Host> hosts = new List<Host>();
private bool canIgnore;
public bool CanIgnore
{ get { return canIgnore; } }
public XenServerVersion Version;
public XenServerVersionAlert(XenServerVersion version)
@ -57,29 +50,6 @@ namespace XenAdmin.Alerts
_timestamp = version.TimeStamp;
canIgnore = true;
}
public void IncludeConnection(IXenConnection newConnection)
{
connections.Add(newConnection);
if (connections.Count > 0)
canIgnore = false;
}
public void IncludeHosts(IEnumerable<Host> newHosts)
{
hosts.AddRange(newHosts);
if (hosts.Count > 0)
canIgnore = false;
}
public void CopyConnectionsAndHosts(XenServerVersionAlert alert)
{
connections.Clear();
connections.AddRange(alert.connections);
hosts.Clear();
hosts.AddRange(alert.hosts);
canIgnore = connections.Count == 0 && hosts.Count == 0;
}
public override string WebPageLabel
{
@ -111,22 +81,6 @@ namespace XenAdmin.Alerts
}
}
public override string AppliesTo
{
get
{
List<string> names = new List<string>();
foreach (Host host in hosts)
names.Add(host.Name);
foreach (IXenConnection connection in connections)
names.Add(Helpers.GetName(connection));
return string.Join(", ", names.ToArray());
}
}
public override string FixLinkText
{
get

View File

@ -113,6 +113,7 @@
<Compile Include="Actions\GUIActions\SaveDataSourceStateAction.cs" />
<Compile Include="Actions\GUIActions\SearchAction.cs" />
<Compile Include="Alerts\Types\AlarmMessageAlert.cs" />
<Compile Include="Alerts\Types\XenServerUpdateAlert.cs" />
<Compile Include="Alerts\Types\DuplicateIqnAlert.cs" />
<Compile Include="Alerts\Types\MissingIqnAlert.cs" />
<Compile Include="Alerts\Types\GuiOldAlert.cs" />