Merge pull request #1509 from GaborApatiNagy/REQ-411_2

CP-21500: Updates wizard: Show new versions that are available as updates
This commit is contained in:
Mihaela Stoica 2017-03-24 12:01:04 +00:00 committed by GitHub
commit 776de3ce78
4 changed files with 108 additions and 40 deletions

View File

@ -0,0 +1,68 @@
/* 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 System.Text;
using System.Threading.Tasks;
namespace XenAdmin.Alerts
{
public class NewVersionPriorityAlertComparer : IComparer<Alert>
{
public int Compare(Alert alert1, Alert alert2)
{
if (alert1 == null || alert2 == null)
return 0;
int sortResult = 0;
if (IsVersionOrVersionUpdateAlert(alert1) && !IsVersionOrVersionUpdateAlert(alert2))
sortResult = 1;
if (!IsVersionOrVersionUpdateAlert(alert1) && IsVersionOrVersionUpdateAlert(alert2))
sortResult = -1;
if (sortResult == 0)
sortResult = Alert.CompareOnDate(alert1, alert2);
return -sortResult;
}
private bool IsVersionOrVersionUpdateAlert(Alert alert)
{
return alert is XenServerPatchAlert && (alert as XenServerPatchAlert).NewServerVersion != null
|| alert is XenServerVersionAlert
|| alert is XenCenterUpdateAlert;
}
}
}

View File

@ -1009,33 +1009,6 @@ namespace XenAdmin.TabPages
labelProgress.MaximumSize = new Size(tableLayoutPanel3.Width - 60, tableLayoutPanel3.Size.Height); labelProgress.MaximumSize = new Size(tableLayoutPanel3.Width - 60, tableLayoutPanel3.Size.Height);
} }
public class NewVersionPriorityAlertComparer : IComparer<Alert>
{
public int Compare(Alert alert1, Alert alert2)
{
if (alert1 == null || alert2 == null)
return 0;
int sortResult = 0;
if (IsVersionOrVersionUpdateAlert(alert1) && !IsVersionOrVersionUpdateAlert(alert2))
sortResult = 1;
if (!IsVersionOrVersionUpdateAlert(alert1) && IsVersionOrVersionUpdateAlert(alert2))
sortResult = -1;
if (sortResult == 0)
sortResult = Alert.CompareOnDate(alert1, alert2);
return -sortResult;
}
private bool IsVersionOrVersionUpdateAlert(Alert alert)
{
return alert is XenServerPatchAlert && (alert as XenServerPatchAlert).NewServerVersion != null
|| alert is XenServerVersionAlert
|| alert is XenCenterUpdateAlert;
}
}
} }
} }

View File

@ -62,8 +62,6 @@ namespace XenAdmin.Wizards.PatchingWizard
labelWithAutomatedUpdates.Visible = automatedUpdatesOptionLabel.Visible = AutomatedUpdatesRadioButton.Visible = false; labelWithAutomatedUpdates.Visible = automatedUpdatesOptionLabel.Visible = AutomatedUpdatesRadioButton.Visible = false;
downloadUpdateRadioButton.Checked = true; downloadUpdateRadioButton.Checked = true;
dataGridViewPatches.Sort(ColumnDate, ListSortDirection.Descending);
} }
private void CheckForUpdates_CheckForUpdatesStarted() private void CheckForUpdates_CheckForUpdatesStarted()
@ -255,7 +253,9 @@ namespace XenAdmin.Wizards.PatchingWizard
private void PopulatePatchesBox() private void PopulatePatchesBox()
{ {
dataGridViewPatches.Rows.Clear(); dataGridViewPatches.Rows.Clear();
var updates = new List<Alert>(Updates.UpdateAlerts);
var updates = Updates.UpdateAlerts.ToList();
if (dataGridViewPatches.SortedColumn != null) if (dataGridViewPatches.SortedColumn != null)
{ {
if (dataGridViewPatches.SortedColumn.Index == ColumnUpdate.Index) if (dataGridViewPatches.SortedColumn.Index == ColumnUpdate.Index)
@ -268,16 +268,29 @@ namespace XenAdmin.Wizards.PatchingWizard
if (dataGridViewPatches.SortOrder == SortOrder.Descending) if (dataGridViewPatches.SortOrder == SortOrder.Descending)
updates.Reverse(); updates.Reverse();
} }
foreach (Alert alert in updates) else
{ {
if (alert is XenServerPatchAlert) updates.Sort(new NewVersionPriorityAlertComparer());
{ }
PatchGridViewRow row = new PatchGridViewRow(alert);
if (!dataGridViewPatches.Rows.Contains(row)) foreach (Alert alert in updates)
{ {
dataGridViewPatches.Rows.Add(row); var patchAlert = alert as XenServerPatchAlert;
}
} if (patchAlert != null)
{
PatchGridViewRow row = new PatchGridViewRow(patchAlert);
if (!dataGridViewPatches.Rows.Contains(row))
{
dataGridViewPatches.Rows.Add(row);
if (patchAlert.RequiredXenCenterVersion != null)
{
row.Enabled = false;
row.SetToolTip(string.Format(Messages.UPDATES_WIZARD_NEWER_XENCENTER_REQUIRED, patchAlert.RequiredXenCenterVersion.Version));
}
}
}
} }
} }
@ -592,6 +605,19 @@ namespace XenAdmin.Wizards.PatchingWizard
return this.Equals((PatchGridViewRow)obj); return this.Equals((PatchGridViewRow)obj);
return false; return false;
} }
public void SetToolTip(string toolTip)
{
foreach (var c in Cells)
{
if (c is DataGridViewLinkCell)
continue;
var cell = c as DataGridViewCell;
if (c != null)
((DataGridViewCell)c).ToolTipText = toolTip;
}
}
} }
#endregion #endregion

View File

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