2013-06-24 13:41:48 +02:00
|
|
|
|
/* 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.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
using System.Text;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using System.Windows.Forms;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
|
|
|
|
using XenAdmin.Actions;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Alerts;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
using XenAdmin.Controls;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Core;
|
2013-08-30 16:19:59 +02:00
|
|
|
|
using XenAdmin.Dialogs;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
using XenAdmin.Wizards.PatchingWizard;
|
|
|
|
|
using Timer = System.Windows.Forms.Timer;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-08-30 16:19:59 +02:00
|
|
|
|
namespace XenAdmin.TabPages
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-08-30 16:19:59 +02:00
|
|
|
|
public partial class ManageUpdatesPage : UserControl
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
|
|
|
|
private int currentSpinningFrame;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
private Timer spinningTimer = new Timer();
|
|
|
|
|
private ImageList imageList = new ImageList();
|
|
|
|
|
|
2013-07-11 20:09:29 +02:00
|
|
|
|
Dictionary<string, bool> expandedState = new Dictionary<string, bool>();
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private List<string> selectedUpdates = new List<string>();
|
|
|
|
|
private int checksQueue;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-08-30 16:19:59 +02:00
|
|
|
|
public ManageUpdatesPage()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
InitializeProgressControls();
|
2013-11-23 15:04:15 +01:00
|
|
|
|
tableLayoutPanel1.Visible = false;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
UpdateButtonEnablement();
|
|
|
|
|
dataGridViewUpdates.Sort(ColumnDate, ListSortDirection.Descending);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
informationLabel.Click += informationLabel_Click;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
Updates.RegisterCollectionChanged(UpdatesCollectionChanged);
|
|
|
|
|
Updates.CheckForUpdatesStarted += CheckForUpdates_CheckForUpdatesStarted;
|
2013-11-21 15:27:34 +01:00
|
|
|
|
Updates.CheckForUpdatesCompleted += CheckForUpdates_CheckForUpdatesCompleted;
|
2013-08-30 16:19:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
public void RefreshUpdateList()
|
2013-08-30 16:19:59 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
toolStripDropDownButtonServerFilter.InitializeHostList();
|
|
|
|
|
toolStripDropDownButtonServerFilter.BuildFilterList();
|
|
|
|
|
Rebuild();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void UpdatesCollectionChanged(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
|
|
|
|
Program.Invoke(this, Rebuild);
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void CheckForUpdates_CheckForUpdatesStarted()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
Program.Invoke(this, () =>
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
checksQueue++;
|
|
|
|
|
if (checksQueue > 1)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
toolStripButtonRefresh.Enabled = false;
|
|
|
|
|
StoreSelectedUpdates();
|
|
|
|
|
dataGridViewUpdates.Rows.Clear();
|
|
|
|
|
spinningTimer.Start();
|
|
|
|
|
panelProgress.Visible = true;
|
|
|
|
|
labelProgress.Text = Messages.AVAILABLE_UPDATES_SEARCHING;
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void CheckForUpdates_CheckForUpdatesCompleted(bool succeeded, string errorMessage)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
Program.Invoke(this, delegate
|
|
|
|
|
{
|
|
|
|
|
checksQueue--;
|
|
|
|
|
toolStripButtonRefresh.Enabled = true;
|
|
|
|
|
spinningTimer.Stop();
|
2013-11-21 09:30:24 +01:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
if (succeeded)
|
|
|
|
|
{
|
|
|
|
|
int alertCount = Updates.UpdateAlertsCount;
|
2013-11-21 09:30:24 +01:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
if (alertCount > 0)
|
|
|
|
|
panelProgress.Visible = false;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pictureBoxProgress.Image = SystemIcons.Information.ToBitmap();
|
|
|
|
|
labelProgress.Text = Messages.AVAILABLE_UPDATES_NOT_FOUND;
|
|
|
|
|
}
|
2013-11-21 09:30:24 +01:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
Rebuild();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pictureBoxProgress.Image = SystemIcons.Error.ToBitmap();
|
|
|
|
|
labelProgress.Text = string.IsNullOrEmpty(errorMessage)
|
|
|
|
|
? Messages.AVAILABLE_UPDATES_NOT_FOUND
|
|
|
|
|
: errorMessage;
|
|
|
|
|
}
|
|
|
|
|
});
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void InitializeProgressControls()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
imageList.ColorDepth = ColorDepth.Depth32Bit;
|
|
|
|
|
imageList.ImageSize = new Size(32, 32);
|
|
|
|
|
imageList.Images.AddRange(new Image[]
|
|
|
|
|
{
|
|
|
|
|
Properties.Resources.SpinningFrame0,
|
|
|
|
|
Properties.Resources.SpinningFrame1,
|
|
|
|
|
Properties.Resources.SpinningFrame2,
|
|
|
|
|
Properties.Resources.SpinningFrame3,
|
|
|
|
|
Properties.Resources.SpinningFrame4,
|
|
|
|
|
Properties.Resources.SpinningFrame5,
|
|
|
|
|
Properties.Resources.SpinningFrame6,
|
|
|
|
|
Properties.Resources.SpinningFrame7
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
spinningTimer.Tick += timer_Tick;
|
|
|
|
|
spinningTimer.Interval = 150;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void timer_Tick(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
int imageIndex = ++currentSpinningFrame <= 7 ? currentSpinningFrame : currentSpinningFrame = 0;
|
|
|
|
|
pictureBoxProgress.Image = imageList.Images[imageIndex];
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void SetFilterLabel()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
toolStripLabelFiltersOnOff.Text = FilterIsOn
|
|
|
|
|
? Messages.FILTERS_ON
|
|
|
|
|
: Messages.FILTERS_OFF;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool FilterIsOn
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return toolStripDropDownButtonDateFilter.FilterIsOn ||
|
|
|
|
|
toolStripDropDownButtonServerFilter.FilterIsOn;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Rebuild()
|
|
|
|
|
{
|
|
|
|
|
Program.AssertOnEventThread();
|
|
|
|
|
|
2014-04-28 16:04:23 +02:00
|
|
|
|
if (!Visible)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
if (checksQueue > 0)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
SetFilterLabel();
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
dataGridViewUpdates.SuspendLayout();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
if (dataGridViewUpdates.RowCount > 0)
|
|
|
|
|
{
|
|
|
|
|
StoreSelectedUpdates();
|
|
|
|
|
dataGridViewUpdates.Rows.Clear();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
var updates = new List<Alert>(Updates.UpdateAlerts);
|
|
|
|
|
|
|
|
|
|
if (updates.Count == 0)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-11-21 09:30:24 +01:00
|
|
|
|
panelProgress.Visible = true;
|
|
|
|
|
pictureBoxProgress.Image = SystemIcons.Information.ToBitmap();
|
|
|
|
|
labelProgress.Text = Messages.AVAILABLE_UPDATES_NOT_FOUND;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
updates.RemoveAll(FilterAlert);
|
2013-11-21 09:30:24 +01:00
|
|
|
|
panelProgress.Visible = false;
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
if (dataGridViewUpdates.SortedColumn != null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
if (dataGridViewUpdates.SortedColumn.Index == ColumnMessage.Index)
|
|
|
|
|
updates.Sort(Alert.CompareOnTitle);
|
|
|
|
|
else if (dataGridViewUpdates.SortedColumn.Index == ColumnDate.Index)
|
|
|
|
|
updates.Sort(Alert.CompareOnDate);
|
|
|
|
|
else if (dataGridViewUpdates.SortedColumn.Index == ColumnLocation.Index)
|
|
|
|
|
updates.Sort(Alert.CompareOnAppliesTo);
|
|
|
|
|
|
|
|
|
|
if (dataGridViewUpdates.SortOrder == SortOrder.Descending)
|
|
|
|
|
updates.Reverse();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
var rowList = new List<DataGridViewRow>();
|
|
|
|
|
|
|
|
|
|
foreach (var myAlert in updates)
|
|
|
|
|
rowList.Add(NewUpdateRow(myAlert));
|
|
|
|
|
|
|
|
|
|
dataGridViewUpdates.Rows.AddRange(rowList.ToArray());
|
|
|
|
|
|
|
|
|
|
foreach (DataGridViewRow row in dataGridViewUpdates.Rows)
|
|
|
|
|
row.Selected = selectedUpdates.Contains(((Alert)row.Tag).uuid);
|
|
|
|
|
|
|
|
|
|
if (dataGridViewUpdates.SelectedRows.Count == 0 && dataGridViewUpdates.Rows.Count > 0)
|
|
|
|
|
dataGridViewUpdates.Rows[0].Selected = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
dataGridViewUpdates.ResumeLayout();
|
2013-12-05 13:46:39 +01:00
|
|
|
|
UpdateButtonEnablement();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2013-12-05 13:46:39 +01:00
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Runs all the current filters on the alert to determine if it should be shown in the list or not.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="alert"></param>
|
|
|
|
|
private bool FilterAlert(Alert alert)
|
|
|
|
|
{
|
2014-01-03 12:27:11 +01:00
|
|
|
|
var hosts = new List<string>();
|
|
|
|
|
var serverUpdate = alert as XenServerUpdateAlert;
|
|
|
|
|
if (serverUpdate != null)
|
|
|
|
|
hosts = serverUpdate.DistinctHosts.Select(h => h.uuid).ToList();
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
bool hide = false;
|
|
|
|
|
Program.Invoke(this, () =>
|
|
|
|
|
hide = toolStripDropDownButtonDateFilter.HideByDate(alert.Timestamp.ToLocalTime())
|
2014-01-03 12:27:11 +01:00
|
|
|
|
|| toolStripDropDownButtonServerFilter.HideByLocation(hosts));
|
2013-12-05 13:46:39 +01:00
|
|
|
|
return hide;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void StoreSelectedUpdates()
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
selectedUpdates = (dataGridViewUpdates.SelectedRows.Cast<DataGridViewRow>().Select(
|
|
|
|
|
selectedRow => ((Alert)selectedRow.Tag).uuid)).ToList();
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void UpdateButtonEnablement()
|
|
|
|
|
{
|
2014-07-31 10:39:16 +02:00
|
|
|
|
toolStripButtonExportAll.Enabled = Updates.UpdateAlertsCount > 0;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-23 15:04:15 +01:00
|
|
|
|
private void ShowInformationHelper(string reason)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-11-23 15:04:15 +01:00
|
|
|
|
if (string.IsNullOrEmpty(reason))
|
|
|
|
|
{
|
|
|
|
|
tableLayoutPanel1.Visible = false;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2013-11-23 15:04:15 +01:00
|
|
|
|
else
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-11-23 15:04:15 +01:00
|
|
|
|
informationLabel.Text = reason;
|
|
|
|
|
tableLayoutPanel1.Visible = true;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DataGridViewRow NewUpdateRow(Alert alert)
|
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
var expanderCell = new DataGridViewImageCell();
|
|
|
|
|
var appliesCell = new DataGridViewTextBoxCell();
|
|
|
|
|
var detailCell = new DataGridViewTextBoxCell();
|
|
|
|
|
var dateCell = new DataGridViewTextBoxCell();
|
|
|
|
|
|
|
|
|
|
var actionItems = GetAlertActionItems(alert);
|
|
|
|
|
var actionCell = new DataGridViewDropDownSplitButtonCell(actionItems.ToArray());
|
|
|
|
|
var newRow = new DataGridViewRow { Tag = alert, MinimumHeight = DataGridViewDropDownSplitButtonCell.MIN_ROW_HEIGHT };
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-07-11 20:09:29 +02:00
|
|
|
|
// Set the detail cell content and expanding arrow
|
|
|
|
|
if (expandedState.ContainsKey(alert.uuid))
|
|
|
|
|
{
|
|
|
|
|
// show the expanded arrow and the body detail
|
|
|
|
|
expanderCell.Value = Properties.Resources.expanded_triangle;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
detailCell.Value = String.Format("{0}\n\n{1}", alert.Title, alert.Description);
|
2013-07-11 20:09:29 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// show the expand arrow and just the title
|
|
|
|
|
expanderCell.Value = Properties.Resources.contracted_triangle;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
detailCell.Value = alert.Title;
|
2013-07-11 20:09:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
appliesCell.Value = alert.AppliesTo;
|
|
|
|
|
dateCell.Value = HelpersGUI.DateTimeToString(alert.Timestamp.ToLocalTime(), Messages.DATEFORMAT_DMY_HM, true);
|
|
|
|
|
newRow.Cells.AddRange(expanderCell, detailCell, appliesCell, dateCell, actionCell);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
return newRow;
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private List<ToolStripItem> GetAlertActionItems(Alert alert)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
var items = new List<ToolStripItem>();
|
2013-07-11 20:09:29 +02:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
var patchAlert = alert as XenServerPatchAlert;
|
|
|
|
|
|
|
|
|
|
if (patchAlert != null && patchAlert.CanApply && !string.IsNullOrEmpty(patchAlert.Patch.PatchUrl))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
var download = new ToolStripMenuItem(Messages.UPDATES_DOWNLOAD_AND_INSTALL);
|
|
|
|
|
download.Click += ToolStripMenuItemDownload_Click;
|
|
|
|
|
items.Add(download);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(alert.WebPageLabel))
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
var fix = new ToolStripMenuItem(alert.FixLinkText);
|
|
|
|
|
fix.Click += ToolStripMenuItemGoToWebPage_Click;
|
|
|
|
|
items.Add(fix);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
if (items.Count > 0)
|
|
|
|
|
items.Add(new ToolStripSeparator());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
var copy = new ToolStripMenuItem(Messages.COPY);
|
|
|
|
|
copy.Click += ToolStripMenuItemCopy_Click;
|
|
|
|
|
items.Add(copy);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
return items;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
#region Actions DropDown event handlers
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2014-06-30 15:49:16 +02:00
|
|
|
|
private DataGridViewRow FindAlertRow(ToolStripMenuItem toolStripMenuItem)
|
|
|
|
|
{
|
|
|
|
|
if (toolStripMenuItem == null)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
return (from DataGridViewRow row in dataGridViewUpdates.Rows
|
|
|
|
|
where row.Cells.Count > 0
|
|
|
|
|
let actionCell = row.Cells[row.Cells.Count - 1] as DataGridViewDropDownSplitButtonCell
|
|
|
|
|
where actionCell != null && actionCell.ContextMenu.Items.Cast<object>().Any(item => item is ToolStripMenuItem && item == toolStripMenuItem)
|
|
|
|
|
select row).FirstOrDefault();
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void ToolStripMenuItemGoToWebPage_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2014-06-30 15:49:16 +02:00
|
|
|
|
DataGridViewRow clickedRow = FindAlertRow(sender as ToolStripMenuItem);
|
|
|
|
|
if (clickedRow == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Alert alert = (Alert) clickedRow.Tag;
|
|
|
|
|
if (alert != null && alert.FixLinkAction != null)
|
|
|
|
|
alert.FixLinkAction.Invoke();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void ToolStripMenuItemDownload_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2014-06-30 15:49:16 +02:00
|
|
|
|
DataGridViewRow clickedRow = FindAlertRow(sender as ToolStripMenuItem);
|
|
|
|
|
if (clickedRow == null)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2014-06-30 15:49:16 +02:00
|
|
|
|
XenServerPatchAlert patchAlert = (XenServerPatchAlert) clickedRow.Tag;
|
|
|
|
|
|
2013-06-24 13:41:48 +02:00
|
|
|
|
if (patchAlert == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
string patchUri = patchAlert.Patch.PatchUrl;
|
|
|
|
|
if (string.IsNullOrEmpty(patchUri))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Uri address = new Uri(patchUri);
|
|
|
|
|
string tempFile = Path.GetTempFileName();
|
|
|
|
|
|
2013-07-03 12:28:10 +02:00
|
|
|
|
var action = new DownloadAndUnzipXenServerPatchAction(patchAlert.Description, address, tempFile);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
ActionProgressDialog dialog = new ActionProgressDialog(action, ProgressBarStyle.Continuous, false) { ShowCancel = true };
|
|
|
|
|
dialog.ShowDialog(this);
|
|
|
|
|
|
|
|
|
|
if (action.Succeeded)
|
|
|
|
|
{
|
|
|
|
|
var wizard = new PatchingWizard();
|
|
|
|
|
wizard.Show();
|
|
|
|
|
wizard.NextStep();
|
|
|
|
|
wizard.AddFile(action.PatchPath);
|
|
|
|
|
wizard.NextStep();
|
2014-01-03 12:27:11 +01:00
|
|
|
|
|
|
|
|
|
var hosts = patchAlert.DistinctHosts;
|
|
|
|
|
if (hosts.Count > 0)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2014-01-03 12:27:11 +01:00
|
|
|
|
wizard.SelectServers(hosts);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2014-06-30 15:49:16 +02:00
|
|
|
|
string disconnectedServerNames = clickedRow.Cells[ColumnLocation.Index].Value.ToString();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
new ThreeButtonDialog(
|
|
|
|
|
new ThreeButtonDialog.Details(SystemIcons.Warning,
|
|
|
|
|
string.Format(Messages.UPDATES_WIZARD_DISCONNECTED_SERVER,
|
|
|
|
|
disconnectedServerNames),
|
|
|
|
|
Messages.UPDATES_WIZARD)).ShowDialog(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void ToolStripMenuItemCopy_Click(object sender, EventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2014-06-30 15:49:16 +02:00
|
|
|
|
DataGridViewRow clickedRow = FindAlertRow(sender as ToolStripMenuItem);
|
|
|
|
|
if (clickedRow == null)
|
2013-12-05 13:46:39 +01:00
|
|
|
|
return;
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2014-06-30 15:49:16 +02:00
|
|
|
|
|
|
|
|
|
if (dataGridViewUpdates.SelectedRows.Count > 1 && dataGridViewUpdates.SelectedRows.Contains(clickedRow))
|
|
|
|
|
{
|
|
|
|
|
foreach (DataGridViewRow r in dataGridViewUpdates.SelectedRows)
|
|
|
|
|
{
|
|
|
|
|
Alert alert = (Alert) r.Tag;
|
|
|
|
|
sb.AppendLine(alert.GetUpdateDetailsCSVQuotes());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2014-06-30 15:49:16 +02:00
|
|
|
|
Alert alert = (Alert) clickedRow.Tag;
|
|
|
|
|
if (alert != null)
|
|
|
|
|
sb.AppendLine(alert.GetUpdateDetailsCSVQuotes());
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
try
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
Clipboard.SetText(sb.ToString());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
log.Error("Exception while trying to set clipboard text.", ex);
|
|
|
|
|
log.Error(ex, ex);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
#endregion
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
#region DataGridView event handlers
|
2013-06-24 13:41:48 +02:00
|
|
|
|
|
|
|
|
|
private void dataGridViewUpdates_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
string reason = null;
|
|
|
|
|
|
|
|
|
|
if (dataGridViewUpdates.SelectedRows.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var alert = dataGridViewUpdates.SelectedRows[0].Tag as XenServerPatchAlert;
|
|
|
|
|
|
|
|
|
|
if (alert != null)
|
|
|
|
|
reason = alert.CannotApplyReason;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ShowInformationHelper(reason);
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void dataGridViewUpdates_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
if (dataGridViewUpdates.Columns[e.ColumnIndex].SortMode == DataGridViewColumnSortMode.Automatic)
|
|
|
|
|
Rebuild();
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handles the automatic sorting of the AlertsGridView for the non-string columns
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void dataGridViewUpdates_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
|
2013-06-24 13:41:48 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
Alert alert1 = (Alert)dataGridViewUpdates.Rows[e.RowIndex1].Tag;
|
|
|
|
|
Alert alert2 = (Alert)dataGridViewUpdates.Rows[e.RowIndex2].Tag;
|
|
|
|
|
|
|
|
|
|
if (e.Column.Index == ColumnDate.Index)
|
|
|
|
|
{
|
|
|
|
|
int sortResult = DateTime.Compare(alert1.Timestamp, alert2.Timestamp);
|
|
|
|
|
e.SortResult = (dataGridViewUpdates.SortOrder == SortOrder.Descending) ? sortResult *= -1 : sortResult;
|
|
|
|
|
e.Handled = true;
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
2013-07-11 20:09:29 +02:00
|
|
|
|
|
|
|
|
|
private void dataGridViewUpdates_CellClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// If you click on the headers you can get -1 as the index.
|
2013-07-12 12:07:10 +02:00
|
|
|
|
if (e.ColumnIndex < 0 || e.RowIndex < 0 || e.ColumnIndex != ColumnExpand.Index)
|
2013-07-11 20:09:29 +02:00
|
|
|
|
return;
|
|
|
|
|
|
2013-12-05 13:46:39 +01:00
|
|
|
|
ToggleExpandedState(e.RowIndex);
|
2013-07-11 20:09:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataGridViewUpdates_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
// If you click on the headers you can get -1 as the index.
|
|
|
|
|
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
|
|
|
|
return;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
|
|
|
|
ToggleExpandedState(e.RowIndex);
|
2013-07-11 20:09:29 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void dataGridViewUpdates_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.KeyCode == Keys.Right) // expand all selected rows
|
|
|
|
|
{
|
|
|
|
|
foreach (DataGridViewBand row in dataGridViewUpdates.SelectedRows)
|
|
|
|
|
{
|
|
|
|
|
Alert alert = (Alert)dataGridViewUpdates.Rows[row.Index].Tag;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2013-07-11 20:09:29 +02:00
|
|
|
|
if (!expandedState.ContainsKey(alert.uuid))
|
2013-12-05 13:46:39 +01:00
|
|
|
|
ToggleExpandedState(row.Index);
|
2013-07-11 20:09:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (e.KeyCode == Keys.Left) // collapse all selected rows
|
|
|
|
|
{
|
|
|
|
|
foreach (DataGridViewBand row in dataGridViewUpdates.SelectedRows)
|
|
|
|
|
{
|
|
|
|
|
Alert alert = (Alert)dataGridViewUpdates.Rows[row.Index].Tag;
|
2013-12-05 13:46:39 +01:00
|
|
|
|
|
2013-07-11 20:09:29 +02:00
|
|
|
|
if (expandedState.ContainsKey(alert.uuid))
|
2013-12-05 13:46:39 +01:00
|
|
|
|
ToggleExpandedState(row.Index);
|
2013-07-11 20:09:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (e.KeyCode == Keys.Enter) // toggle expanded state for all selected rows
|
|
|
|
|
{
|
|
|
|
|
foreach (DataGridViewBand row in dataGridViewUpdates.SelectedRows)
|
2013-12-05 13:46:39 +01:00
|
|
|
|
ToggleExpandedState(row.Index);
|
2013-07-11 20:09:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Toggles the row specified between the expanded and contracted state
|
|
|
|
|
/// </summary>
|
2013-12-05 13:46:39 +01:00
|
|
|
|
private void ToggleExpandedState(int rowIndex)
|
2013-07-11 20:09:29 +02:00
|
|
|
|
{
|
2013-12-05 13:46:39 +01:00
|
|
|
|
Alert alert = (Alert)dataGridViewUpdates.Rows[rowIndex].Tag;
|
2013-07-11 20:09:29 +02:00
|
|
|
|
|
|
|
|
|
if (expandedState.ContainsKey(alert.uuid))
|
|
|
|
|
{
|
|
|
|
|
expandedState.Remove(alert.uuid);
|
2013-12-05 13:46:39 +01:00
|
|
|
|
dataGridViewUpdates.Rows[rowIndex].Cells[ColumnMessage.Index].Value = alert.Title;
|
|
|
|
|
dataGridViewUpdates.Rows[rowIndex].Cells[ColumnExpand.Index].Value = Properties.Resources.contracted_triangle;
|
2013-07-11 20:09:29 +02:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
expandedState.Add(alert.uuid, true);
|
2013-12-05 13:46:39 +01:00
|
|
|
|
dataGridViewUpdates.Rows[rowIndex].Cells[ColumnMessage.Index].Value
|
|
|
|
|
= string.Format("{0}\n\n{1}", alert.Title, alert.Description);
|
|
|
|
|
dataGridViewUpdates.Rows[rowIndex].Cells[ColumnExpand.Index].Value = Properties.Resources.expanded_triangle;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region Top ToolStripButtons event handlers
|
|
|
|
|
|
|
|
|
|
private void toolStripDropDownButtonDateFilter_FilterChanged()
|
|
|
|
|
{
|
|
|
|
|
Rebuild();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toolStripDropDownButtonServerFilter_FilterChanged()
|
|
|
|
|
{
|
|
|
|
|
Rebuild();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toolStripButtonRefresh_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Updates.CheckForUpdates(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void toolStripButtonExportAll_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
bool exportAll = true;
|
|
|
|
|
|
|
|
|
|
if (FilterIsOn)
|
|
|
|
|
{
|
|
|
|
|
using (var dlog = new ThreeButtonDialog(
|
|
|
|
|
new ThreeButtonDialog.Details(null, Messages.UPDATE_EXPORT_ALL_OR_FILTERED),
|
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.ALERT_EXPORT_ALL_BUTTON, DialogResult.Yes),
|
|
|
|
|
new ThreeButtonDialog.TBDButton(Messages.ALERT_EXPORT_FILTERED_BUTTON, DialogResult.No, ThreeButtonDialog.ButtonType.NONE),
|
|
|
|
|
ThreeButtonDialog.ButtonCancel))
|
|
|
|
|
{
|
|
|
|
|
var result = dlog.ShowDialog(this);
|
|
|
|
|
if (result == DialogResult.No)
|
|
|
|
|
exportAll = false;
|
|
|
|
|
else if (result == DialogResult.Cancel)
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string fileName;
|
|
|
|
|
using (SaveFileDialog dialog = new SaveFileDialog
|
|
|
|
|
{
|
|
|
|
|
AddExtension = true,
|
|
|
|
|
Filter = string.Format("{0} (*.csv)|*.csv|{1} (*.*)|*.*",
|
|
|
|
|
Messages.CSV_DESCRIPTION, Messages.ALL_FILES),
|
|
|
|
|
FilterIndex = 0,
|
|
|
|
|
Title = Messages.EXPORT_ALL,
|
|
|
|
|
RestoreDirectory = true,
|
|
|
|
|
DefaultExt = "csv",
|
|
|
|
|
CheckPathExists = false,
|
|
|
|
|
OverwritePrompt = true
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
if (dialog.ShowDialog(this) != DialogResult.OK)
|
|
|
|
|
return;
|
|
|
|
|
fileName = dialog.FileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
new DelegatedAsyncAction(null,
|
|
|
|
|
string.Format(Messages.EXPORT_UPDATES, fileName),
|
|
|
|
|
string.Format(Messages.EXPORTING_UPDATES, fileName),
|
|
|
|
|
string.Format(Messages.EXPORTED_UPDATES, fileName),
|
|
|
|
|
delegate
|
|
|
|
|
{
|
|
|
|
|
using (StreamWriter stream = new StreamWriter(fileName, false, UTF8Encoding.UTF8))
|
|
|
|
|
{
|
|
|
|
|
stream.WriteLine("{0},{1},{2},{3},{4}", Messages.TITLE,
|
|
|
|
|
Messages.DESCRIPTION, Messages.APPLIES_TO,
|
|
|
|
|
Messages.TIMESTAMP, Messages.WEB_PAGE);
|
|
|
|
|
|
|
|
|
|
if (exportAll)
|
|
|
|
|
{
|
|
|
|
|
foreach (Alert a in Updates.UpdateAlerts)
|
|
|
|
|
stream.WriteLine(a.GetUpdateDetailsCSVQuotes());
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
foreach (DataGridViewRow row in dataGridViewUpdates.Rows)
|
|
|
|
|
{
|
|
|
|
|
var a = row.Tag as Alert;
|
|
|
|
|
if (a != null)
|
|
|
|
|
stream.WriteLine(a.GetUpdateDetailsCSVQuotes());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}).RunAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void informationLabel_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Process.Start(InvisibleMessages.UPSELL_SA);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception)
|
|
|
|
|
{
|
|
|
|
|
new ThreeButtonDialog(
|
|
|
|
|
new ThreeButtonDialog.Details(
|
|
|
|
|
SystemIcons.Error,
|
|
|
|
|
string.Format(Messages.LICENSE_SERVER_COULD_NOT_OPEN_LINK, InvisibleMessages.LICENSE_SERVER_DOWNLOAD_LINK),
|
|
|
|
|
Messages.XENCENTER)).ShowDialog(this);
|
2013-07-11 20:09:29 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2013-06-24 13:41:48 +02:00
|
|
|
|
}
|
|
|
|
|
}
|