CP-6093: Tidying up: moved property from Alert to XenServerPatchAlert as it only

applies to the latter. Converted methods from AlertSummaryPage to one Alert and
one String extension method so they can be used more widely. Code simplification
on the Updates page.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2013-11-23 14:04:15 +00:00
parent 649f86bc1d
commit b2e0c858e3
7 changed files with 86 additions and 68 deletions

View File

@ -0,0 +1,61 @@
/* 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 XenAdmin.Core;
namespace XenAdmin.Alerts
{
public static class AlertExtensions
{
public static string GetAlertDetailsCSVQuotes(this Alert a)
{
string date = String.Empty;
string description = String.Empty;
Program.Invoke(Program.MainWindow, delegate
{
date = HelpersGUI.DateTimeToString(
a.Timestamp.ToLocalTime(),
Messages.DATEFORMAT_DMY_HM, true);
description = a.Description;
});
return String.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\"",
a.Title.EscapeQuotes(),
a.Priority.GetString().EscapeQuotes(),
description.EscapeQuotes(),
a.AppliesTo.EscapeQuotes(),
date.EscapeQuotes());
}
}
}

View File

@ -88,11 +88,13 @@ namespace XenAdmin.Alerts
}
}
CannotApplyReason = string.Empty;
CannotApplyReason = null;
return true;
}
}
public string CannotApplyReason { get; set; }
private bool IsHostLicenseRestricted(Host host)
{
if(host == null)
@ -123,15 +125,6 @@ namespace XenAdmin.Alerts
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
{
get

View File

@ -793,7 +793,7 @@ namespace XenAdmin.TabPages
if (exportAll)
{
foreach (Alert a in Alert.Alerts)
stream.WriteLine(GetAlertDetailsCSVQuotes(a));
stream.WriteLine(a.GetAlertDetailsCSVQuotes());
}
else
{
@ -801,7 +801,7 @@ namespace XenAdmin.TabPages
{
var a = row.Tag as Alert;
if (a != null)
stream.WriteLine(GetAlertDetailsCSVQuotes(a));
stream.WriteLine(a.GetAlertDetailsCSVQuotes());
}
}
}
@ -814,6 +814,8 @@ namespace XenAdmin.TabPages
toolStripSplitButtonDismiss.Text = toolStripSplitButtonDismiss.DefaultItem.Text;
}
#endregion
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
// We should only be here if one item is selected, we don't do multi-fix
@ -827,7 +829,7 @@ namespace XenAdmin.TabPages
foreach (DataGridViewRow r in GridViewAlerts.SelectedRows)
{
Alert alert = (Alert)r.Tag;
sb.AppendLine(GetAlertDetailsCSVQuotes(alert));
sb.AppendLine(alert.GetAlertDetailsCSVQuotes());
}
try
@ -840,33 +842,5 @@ namespace XenAdmin.TabPages
log.Error(ex, ex);
}
}
private string GetAlertDetailsCSVQuotes(Alert a)
{
string date = String.Empty;
string description = String.Empty;
Program.Invoke(Program.MainWindow, delegate
{
date = HelpersGUI.DateTimeToString(
a.Timestamp.ToLocalTime(),
Messages.DATEFORMAT_DMY_HM, true);
description = a.Description;
});
return String.Format("\"{0}\",\"{1}\",\"{2}\",\"{3}\",\"{4}\"",
EscapeQuotes(a.Title),
EscapeQuotes(a.Priority.GetString()),
EscapeQuotes(description),
EscapeQuotes(a.AppliesTo),
EscapeQuotes(date));
}
private string EscapeQuotes(string s)
{
return s == null ? null : s.Replace("\"", "\"\"");
}
#endregion
}
}

View File

@ -106,7 +106,7 @@ namespace XenAdmin.TabPages
{
InitializeComponent();
InitializeProgressControls();
InformationHelperVisible = false;
tableLayoutPanel1.Visible = false;
informationLabel.Click += informationLabel_Click;
Updates.CheckForUpdatesCompleted += CheckForUpdates_CheckForUpdatesCompleted;
}
@ -278,12 +278,12 @@ namespace XenAdmin.TabPages
{
if(!alert.CanApply)
{
ShowInformationHelper = alert.CannotApplyReason;
ShowInformationHelper(alert.CannotApplyReason);
downloadAndInstallButton.Enabled = false;
return;
}
ShowInformationHelper = alert.CannotApplyReason;
ShowInformationHelper(alert.CannotApplyReason);
downloadAndInstallButton.Enabled = !string.IsNullOrEmpty(alert.Patch.PatchUrl);
return;
}
@ -292,29 +292,16 @@ namespace XenAdmin.TabPages
downloadAndInstallButton.Enabled = false;
}
private string ShowInformationHelper
private void ShowInformationHelper(string reason)
{
set
{
if(String.IsNullOrEmpty(value))
{
InformationHelperVisible = false;
informationLabel.Text = value;
}
else
{
InformationHelperVisible = true;
informationLabel.Text = value;
}
}
}
private bool InformationHelperVisible
{
set
if (string.IsNullOrEmpty(reason))
{
informationLabel.Visible = value;
informationLabelIcon.Visible = value;
tableLayoutPanel1.Visible = false;
}
else
{
informationLabel.Text = reason;
tableLayoutPanel1.Visible = true;
}
}

View File

@ -2115,6 +2115,7 @@
<Content Include="AppIcon.ico" />
<Compile Include="Actions\GUIActions\MeddlingActionManager.cs" />
<Compile Include="Actions\GUIActions\MeddlingActionTaskSpecifications.cs" />
<Compile Include="Alerts\AlertExtensions.cs" />
<Compile Include="Alerts\Types\LicenseAlert.cs" />
<Compile Include="Alerts\Types\IqnAlert.cs" />
<Compile Include="Commands\ApplyLicenseEditionCommand.cs" />

View File

@ -48,8 +48,6 @@ namespace XenAdmin.Alerts
public bool Dismissing;
public string CannotApplyReason { get; set; }
public static void AddAlert(Alert a)
{
try

View File

@ -30,7 +30,6 @@
*/
using System;
using System.Drawing;
namespace XenAdmin
{
@ -95,5 +94,10 @@ namespace XenAdmin
else
return s.Replace("&", "&&");
}
public static string EscapeQuotes(this string s)
{
return s == null ? null : s.Replace("\"", "\"\"");
}
}
}