diff --git a/XenAdmin/Alerts/NewVersionPriorityAlertComparer.cs b/XenAdmin/Alerts/NewVersionPriorityAlertComparer.cs new file mode 100644 index 000000000..612aedcf2 --- /dev/null +++ b/XenAdmin/Alerts/NewVersionPriorityAlertComparer.cs @@ -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 + { + 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; + } + } +} diff --git a/XenAdmin/TabPages/ManageUpdatesPage.cs b/XenAdmin/TabPages/ManageUpdatesPage.cs index ebe2dc2fc..c84221b1e 100644 --- a/XenAdmin/TabPages/ManageUpdatesPage.cs +++ b/XenAdmin/TabPages/ManageUpdatesPage.cs @@ -1009,33 +1009,6 @@ namespace XenAdmin.TabPages labelProgress.MaximumSize = new Size(tableLayoutPanel3.Width - 60, tableLayoutPanel3.Size.Height); } - public class NewVersionPriorityAlertComparer : IComparer - { - 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; - } - } } } diff --git a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectPatchPage.cs b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectPatchPage.cs index 3cea57b6a..90386760d 100644 --- a/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectPatchPage.cs +++ b/XenAdmin/Wizards/PatchingWizard/PatchingWizard_SelectPatchPage.cs @@ -62,8 +62,6 @@ namespace XenAdmin.Wizards.PatchingWizard labelWithAutomatedUpdates.Visible = automatedUpdatesOptionLabel.Visible = AutomatedUpdatesRadioButton.Visible = false; downloadUpdateRadioButton.Checked = true; - - dataGridViewPatches.Sort(ColumnDate, ListSortDirection.Descending); } private void CheckForUpdates_CheckForUpdatesStarted() @@ -255,7 +253,9 @@ namespace XenAdmin.Wizards.PatchingWizard private void PopulatePatchesBox() { dataGridViewPatches.Rows.Clear(); - var updates = new List(Updates.UpdateAlerts); + + var updates = Updates.UpdateAlerts.ToList(); + if (dataGridViewPatches.SortedColumn != null) { if (dataGridViewPatches.SortedColumn.Index == ColumnUpdate.Index) @@ -268,16 +268,29 @@ namespace XenAdmin.Wizards.PatchingWizard if (dataGridViewPatches.SortOrder == SortOrder.Descending) updates.Reverse(); } - foreach (Alert alert in updates) - { - if (alert is XenServerPatchAlert) - { - PatchGridViewRow row = new PatchGridViewRow(alert); - if (!dataGridViewPatches.Rows.Contains(row)) - { - dataGridViewPatches.Rows.Add(row); - } - } + else + { + updates.Sort(new NewVersionPriorityAlertComparer()); + } + + foreach (Alert alert in updates) + { + 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 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 diff --git a/XenAdmin/XenAdmin.csproj b/XenAdmin/XenAdmin.csproj index fdeac1d70..4833fe9a5 100644 --- a/XenAdmin/XenAdmin.csproj +++ b/XenAdmin/XenAdmin.csproj @@ -103,6 +103,7 @@ +