Fixed crash caused by code redundancy.

One of the PatchGridViewRow constructors was obsoleted, hence the _image and
_status cells and the row's PathPatch were always null. When a user selected a
patch, moved to the Prechecks page, back to the Select page, and the host got
disconnected, on moving to the SelectServers page and closing the warning pop-up,
XenCenter crashed because it was trying to update details of null cells. Also,
removed obsoleted toggling expanded state functionality.

Signed-off-by: Konstantina Chremmou <konstantina.chremmou@citrix.com>
This commit is contained in:
Konstantina Chremmou 2018-10-28 10:36:22 +00:00 committed by Mihaela Stoica
parent 8b107c86e8
commit e63ca825e4
2 changed files with 30 additions and 128 deletions

View File

@ -238,7 +238,6 @@ namespace XenAdmin.Wizards.PatchingWizard
this.dataGridViewPatches.RowsDefaultCellStyle = dataGridViewCellStyle7; this.dataGridViewPatches.RowsDefaultCellStyle = dataGridViewCellStyle7;
this.dataGridViewPatches.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.True; this.dataGridViewPatches.RowTemplate.Resizable = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridViewPatches.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridViewPatches_CellContentClick); this.dataGridViewPatches.CellContentClick += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridViewPatches_CellContentClick);
this.dataGridViewPatches.CellMouseClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dataGridViewPatches_CellMouseClick);
this.dataGridViewPatches.SelectionChanged += new System.EventHandler(this.dataGridViewPatches_SelectionChanged); this.dataGridViewPatches.SelectionChanged += new System.EventHandler(this.dataGridViewPatches_SelectionChanged);
this.dataGridViewPatches.SortCompare += new System.Windows.Forms.DataGridViewSortCompareEventHandler(this.dataGridViewPatches_SortCompare); this.dataGridViewPatches.SortCompare += new System.Windows.Forms.DataGridViewSortCompareEventHandler(this.dataGridViewPatches_SortCompare);
this.dataGridViewPatches.Enter += new System.EventHandler(this.dataGridViewPatches_Enter); this.dataGridViewPatches.Enter += new System.EventHandler(this.dataGridViewPatches_Enter);

View File

@ -267,13 +267,26 @@ namespace XenAdmin.Wizards.PatchingWizard
if (SelectedExistingPatch != null && !SelectedExistingPatch.Connection.IsConnected) if (SelectedExistingPatch != null && !SelectedExistingPatch.Connection.IsConnected)
{ {
cancel = true; cancel = true;
PageLeaveCancelled(string.Format(Messages.UPDATES_WIZARD_CANNOT_DOWNLOAD_PATCH,
SelectedExistingPatch.Connection.Name)); using (var dlg = new ThreeButtonDialog(
new ThreeButtonDialog.Details(SystemIcons.Warning,
string.Format(Messages.UPDATES_WIZARD_CANNOT_DOWNLOAD_PATCH, SelectedExistingPatch.Connection.Name),
Messages.UPDATES_WIZARD)))
{
dlg.ShowDialog(this);
}
} }
else if (!string.IsNullOrEmpty(SelectedNewPatch) && !File.Exists(SelectedNewPatch)) else if (!string.IsNullOrEmpty(SelectedNewPatch) && !File.Exists(SelectedNewPatch))
{ {
cancel = true; cancel = true;
PageLeaveCancelled(string.Format(Messages.UPDATES_WIZARD_FILE_NOT_FOUND, SelectedNewPatch));
using (var dlg = new ThreeButtonDialog(
new ThreeButtonDialog.Details(SystemIcons.Warning,
string.Format(Messages.UPDATES_WIZARD_FILE_NOT_FOUND, SelectedNewPatch),
Messages.UPDATES_WIZARD)))
{
dlg.ShowDialog(this);
}
} }
} }
else //In Automatic Mode else //In Automatic Mode
@ -341,17 +354,6 @@ namespace XenAdmin.Wizards.PatchingWizard
return uuid != null ? Updates.FindPatchAlertByUuid(uuid.Value) : null; return uuid != null ? Updates.FindPatchAlertByUuid(uuid.Value) : null;
} }
private void PageLeaveCancelled(string message)
{
using (var dlg = new ThreeButtonDialog(
new ThreeButtonDialog.Details(SystemIcons.Warning, message, Messages.UPDATES_WIZARD)))
{
dlg.ShowDialog(this);
}
((PatchGridViewRow) dataGridViewPatches.SelectedRows[0]).UpdateDetails();
}
private void PopulatePatchesBox() private void PopulatePatchesBox()
{ {
dataGridViewPatches.Rows.Clear(); dataGridViewPatches.Rows.Clear();
@ -441,7 +443,9 @@ namespace XenAdmin.Wizards.PatchingWizard
return !CheckForUpdatesInProgress; return !CheckForUpdatesInProgress;
} }
//list to store unzipped files to be removed later by PatchingWizard /// <summary>
/// List to store unzipped files to be removed later by PatchingWizard
/// </summary>
private List<string> unzippedFiles = new List<string>(); private List<string> unzippedFiles = new List<string>();
public List<string> UnzippedUpdateFiles public List<string> UnzippedUpdateFiles
@ -462,24 +466,17 @@ namespace XenAdmin.Wizards.PatchingWizard
public string SelectedNewPatch public string SelectedNewPatch
{ {
get get
{ {
if (downloadUpdateRadioButton.Checked) if (selectFromDiskRadioButton.Checked)
{ {
return SelectedUpdateType == UpdateType.Legacy || SelectedUpdateType == UpdateType.ISO return SelectedUpdateType == UpdateType.Legacy || SelectedUpdateType == UpdateType.ISO
? ((PatchGridViewRow) dataGridViewPatches.SelectedRows[0]).PathPatch ? WizardHelpers.IsValidFile(unzippedUpdateFilePath) && Path.GetExtension(FilePath).ToLowerInvariant().Equals(".zip")
: null;
}
else if (selectFromDiskRadioButton.Checked)
{
return SelectedUpdateType == UpdateType.Legacy || SelectedUpdateType == UpdateType.ISO
? WizardHelpers.IsValidFile(unzippedUpdateFilePath) &&
Path.GetExtension(FilePath).ToLowerInvariant().Equals(".zip")
? unzippedUpdateFilePath ? unzippedUpdateFilePath
: FilePath : FilePath
: null; : null;
} }
else
return null; return null;
} }
} }
@ -490,19 +487,6 @@ namespace XenAdmin.Wizards.PatchingWizard
OnPageUpdated(); OnPageUpdated();
} }
private void dataGridViewPatches_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
{
if (e.Button != MouseButtons.Left)
return;
if (e.RowIndex < 0)
// The click is on a column header
return;
PatchGridViewRow row = (PatchGridViewRow) dataGridViewPatches.Rows[e.RowIndex];
row.toggleExpandedState();
OnPageUpdated();
}
private void dataGridViewPatches_SortCompare(object sender, DataGridViewSortCompareEventArgs e) private void dataGridViewPatches_SortCompare(object sender, DataGridViewSortCompareEventArgs e)
{ {
Alert alert1 = ((PatchGridViewRow) dataGridViewPatches.Rows[e.RowIndex1]).UpdateAlert; Alert alert1 = ((PatchGridViewRow) dataGridViewPatches.Rows[e.RowIndex1]).UpdateAlert;
@ -539,30 +523,15 @@ namespace XenAdmin.Wizards.PatchingWizard
{ {
private readonly XenServerPatchAlert _alert; private readonly XenServerPatchAlert _alert;
private bool expanded = false; private DataGridViewTextBoxCell _nameCell = new DataGridViewTextBoxCell();
private DataGridViewTextBoxCell _descriptionCell = new DataGridViewTextBoxCell();
private bool _isFile = false; private DataGridViewTextBoxCell _dateCell = new DataGridViewTextBoxCell();
private string _patchPath; private DataGridViewLinkCell _webPageCell = new DataGridViewLinkCell();
private DataGridViewImageCell _imageCell;
private DataGridViewTextBoxCell _nameCell;
private DataGridViewTextBoxCell _descriptionCell;
private DataGridViewTextBoxCell _dateCell;
private DataGridViewTextBoxCell _statusCell;
private DataGridViewLinkCell _webPageCell;
public PatchGridViewRow(XenServerPatchAlert alert) public PatchGridViewRow(XenServerPatchAlert alert)
{ {
_alert = alert; _alert = alert;
_nameCell = new DataGridViewTextBoxCell(); Cells.AddRange(_nameCell, _descriptionCell, _dateCell, _webPageCell);
_descriptionCell = new DataGridViewTextBoxCell();
_dateCell = new DataGridViewTextBoxCell();
_webPageCell = new DataGridViewLinkCell();
Cells.Add(_nameCell);
Cells.Add(_descriptionCell);
Cells.Add(_dateCell);
Cells.Add(_webPageCell);
_nameCell.Value = String.Format(alert.Name); _nameCell.Value = String.Format(alert.Name);
_descriptionCell.Value = String.Format(alert.Description); _descriptionCell.Value = String.Format(alert.Description);
@ -571,80 +540,14 @@ namespace XenAdmin.Wizards.PatchingWizard
_webPageCell.Value = Messages.PATCHING_WIZARD_WEBPAGE_CELL; _webPageCell.Value = Messages.PATCHING_WIZARD_WEBPAGE_CELL;
} }
public PatchGridViewRow(string patchPath)
{
_isFile = true;
_patchPath = patchPath;
SetupCells();
}
public XenServerPatchAlert UpdateAlert public XenServerPatchAlert UpdateAlert
{ {
get { return _alert; } get { return _alert; }
} }
public string PathPatch
{
get { return _patchPath; }
}
private void SetupCells()
{
_imageCell = new DataGridViewExImageCell();
_nameCell = new DataGridViewTextBoxCell();
_descriptionCell = new DataGridViewTextBoxCell();
_statusCell = new DataGridViewTextBoxCell();
_webPageCell = new DataGridViewLinkCell();
Cells.Add(_imageCell);
Cells.Add(_nameCell);
Cells.Add(_descriptionCell);
Cells.Add(_statusCell);
Cells.Add(_webPageCell);
this.UpdateDetails();
}
private void UpdateFileDetails(string description, string status)
{
_descriptionCell.Value = description;
_statusCell.Value = status;
}
public void UpdateDetails()
{
_imageCell.Value = expanded ? Resources.expanded_triangle : Resources.contracted_triangle;
_webPageCell.Value = Messages.PATCHING_WIZARD_WEBPAGE_CELL;
if (_isFile)
{
_nameCell.Value = System.IO.Path.GetFileName(_patchPath);
FileInfo fileInfo = new FileInfo(_patchPath);
string description = expanded
? fileInfo.Exists
? String.Format(Messages.PATCH_EXPANDED_DESCRIPTION
, _patchPath, fileInfo.CreationTime,
fileInfo.LastWriteTime, Util.DiskSizeString(fileInfo.Length))
: String.Format(Messages.PATCH_NOT_FOUND_EXPANDED_DESCRIPTION,
_patchPath)
: _patchPath;
UpdateFileDetails(description, fileInfo.Exists ? Messages.NOT_UPLOADED : Messages.PATCH_NOT_FOUND);
}
}
public void toggleExpandedState()
{
expanded = !expanded;
}
public bool Equals(PatchGridViewRow other) public bool Equals(PatchGridViewRow other)
{ {
if (other.UpdateAlert != null && this.UpdateAlert != null && if (other != null && other.UpdateAlert != null && UpdateAlert != null && UpdateAlert.uuid == other.UpdateAlert.uuid)
this.UpdateAlert.uuid == other.UpdateAlert.uuid)
return true;
if (other.PathPatch != null && this.PathPatch != null && this.PathPatch == other.PathPatch)
return true; return true;
return false; return false;
} }