private void disableNotApplicableHosts(PatchingHostsDataGridViewRow row, List <Host> selectedHosts, Host host) { if (selectedHosts != null && !selectedHosts.Contains(host)) { string patchUuidFromAlert = null; if (SelectedUpdateAlert != null && SelectedUpdateAlert.Patch != null) { patchUuidFromAlert = SelectedUpdateAlert.Patch.Uuid; } else if (FileFromDiskAlert != null) { patchUuidFromAlert = FileFromDiskAlert.Patch.Uuid; } if (!string.IsNullOrEmpty(patchUuidFromAlert)) { if (isPatchApplied(patchUuidFromAlert, host)) { row.Cells[3].ToolTipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_ALREADY_APPLIED; } else { row.Cells[3].ToolTipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_NOT_APPLICABLE; } row.Enabled = false; } } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { Image icon = value as Image; if (icon == null) { return; } PatchingHostsDataGridViewRow row = (PatchingHostsDataGridViewRow)DataGridView.Rows[RowIndex]; if ((cellState & DataGridViewElementStates.Selected) != 0 && row.Enabled) { graphics.FillRectangle( new SolidBrush(DataGridView.DefaultCellStyle.SelectionBackColor), cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height); } else { graphics.FillRectangle(new SolidBrush(DataGridView.DefaultCellStyle.BackColor), cellBounds.X, cellBounds.Y, cellBounds.Width, cellBounds.Height); } if (row.Enabled) { graphics.DrawImage(icon, cellBounds.X, cellBounds.Y + 3, icon.Width, icon.Height); } else { graphics.DrawImage(icon, new Rectangle(cellBounds.X, cellBounds.Y + 3, icon.Width, icon.Height), 0, 0, icon.Width, icon.Height, GraphicsUnit.Pixel, Drawing.GreyScaleAttributes); } }
protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { Pool pool = value as Pool; if (pool != null) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } else { Host host = value as Host; if (host != null) { PatchingHostsDataGridViewRow row = (PatchingHostsDataGridViewRow)this.DataGridView.Rows[this.RowIndex]; if (row.HasPool) { Image hostIcon = Images.GetImage16For(host); base.Paint(graphics, clipBounds, new Rectangle(cellBounds.X + 16, cellBounds.Y, cellBounds.Width - 16, cellBounds.Height), rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); if ((cellState & DataGridViewElementStates.Selected) != 0 && row.Enabled) { using (var brush = new SolidBrush(DataGridView.DefaultCellStyle.SelectionBackColor)) graphics.FillRectangle( brush, cellBounds.X, cellBounds.Y, hostIcon.Width, cellBounds.Height); } else { using (var brush = new SolidBrush(DataGridView.DefaultCellStyle.BackColor)) graphics.FillRectangle(brush, cellBounds.X, cellBounds.Y, hostIcon.Width, cellBounds.Height); } if (row.Enabled) { graphics.DrawImage(hostIcon, cellBounds.X, cellBounds.Y + 3, hostIcon.Width, hostIcon.Height); } else { graphics.DrawImage(hostIcon, new Rectangle(cellBounds.X, cellBounds.Y + 3, hostIcon.Width, hostIcon.Height), 0, 0, hostIcon.Width, hostIcon.Height, GraphicsUnit.Pixel, Drawing.GreyScaleAttributes); } } else { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); } } } }
protected override void SortColumns() { PatchingHostsDataGridViewRow firstRow = Rows[0] as PatchingHostsDataGridViewRow; if (firstRow == null) { return; } if (columnToBeSortedIndex == firstRow.NameCellIndex || columnToBeSortedIndex == firstRow.VersionCellIndex) { SortAndRebuildTree(new CollapsingPoolHostRowSorter <PatchingHostsDataGridViewRow>(direction, columnToBeSortedIndex)); } }
protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e) { base.OnCellPainting(e); if (e.RowIndex >= 0 && Rows[e.RowIndex].Tag is Host) { PatchingHostsDataGridViewRow row = (PatchingHostsDataGridViewRow)Rows[e.RowIndex]; if (row.HasPool && (e.ColumnIndex == POOL_CHECKBOX_COL || e.ColumnIndex == PLUS_MINUS_COL)) { e.PaintBackground(e.ClipBounds, true); e.Handled = true; } else if (!row.HasPool && e.ColumnIndex == PLUS_MINUS_COL) { e.PaintBackground(e.ClipBounds, true); e.Handled = true; } else if (row.HasPool && !row.IsSelectableHost && e.ColumnIndex == POOL_ICON_HOST_CHECKBOX_COL) { e.PaintBackground(e.ClipBounds, true); e.Handled = true; } else if (!row.HasPool && !row.Enabled && e.ColumnIndex == POOL_CHECKBOX_COL) { e.PaintBackground(e.ClipBounds, true); e.Handled = true; } } if (e.RowIndex >= 0 && Rows[e.RowIndex].Tag is Pool) { PatchingHostsDataGridViewRow row = (PatchingHostsDataGridViewRow)Rows[e.RowIndex]; if (!row.Enabled && e.ColumnIndex == POOL_CHECKBOX_COL) { e.PaintBackground(e.ClipBounds, true); e.Handled = true; } } }
private void applyUpdatesCheckBox_CheckedChanged(object sender, System.EventArgs e) { PatchingHostsDataGridViewRow masterRow = null; foreach (PatchingHostsDataGridViewRow row in dataGridViewHosts.Rows) { var host = row.Tag as Host; if (host != null) { string tooltipText; row.Enabled = CanEnableRow(host, out tooltipText); row.Cells[3].ToolTipText = tooltipText; if (row.ParentPoolRow != null) { if (row.Enabled) { row.ParentPoolRow.Enabled = true; row.ParentPoolRow.Cells[3].ToolTipText = null; } if (masterRow == null) { masterRow = row; if (!row.Enabled) { row.ParentPoolRow.Cells[3].ToolTipText = row.Cells[3].ToolTipText; } } } } else { row.Enabled = false; masterRow = null;//reset the stored masterRow } } }
private void disableNotApplicableHosts(PatchingHostsDataGridViewRow row, List <Host> applicableHosts, Host host) { if (applicableHosts == null) { return; } if (poolSelectionOnly && row.IsPoolOrStandaloneHost && host.Connection.Cache.Hosts.Any(applicableHosts.Contains)) { return; } if (!applicableHosts.Contains(host)) { string patchUuidFromAlert = null; if (SelectedUpdateAlert != null && SelectedUpdateAlert.Patch != null) { patchUuidFromAlert = SelectedUpdateAlert.Patch.Uuid; } else if (FileFromDiskAlert != null) { patchUuidFromAlert = FileFromDiskAlert.Patch.Uuid; } if (!string.IsNullOrEmpty(patchUuidFromAlert)) { if (isPatchApplied(patchUuidFromAlert, host)) { row.Cells[3].ToolTipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_ALREADY_APPLIED; } else { row.Cells[3].ToolTipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_NOT_APPLICABLE; } row.Enabled = false; } } }
protected override void PageLoadedCore(PageLoadedDirection direction) { poolSelectionOnly = WizardMode == WizardMode.AutomatedUpdates || UpdateAlertFromWeb != null || AlertFromFileOnDisk != null; switch (WizardMode) { case WizardMode.AutomatedUpdates: label1.Text = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_AUTOMATED_MODE; break; case WizardMode.NewVersion: label1.Text = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_NEW_VERSION_MODE; break; case WizardMode.SingleUpdate: label1.Text = poolSelectionOnly ? Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_POOL_SELECTION : Messages.PATCHINGWIZARD_SELECTSERVERPAGE_RUBRIC_DEFAULT; break; } List <IXenConnection> xenConnections = ConnectionsManager.XenConnectionsCopy; xenConnections.Sort(); int licensedPoolCount = 0; int poolCount = 0; foreach (IXenConnection xenConnection in xenConnections) { var hosts = xenConnection.Cache.Hosts; if (hosts.Length > 0) { poolCount++; //check if any host is not licensed for automated updates var automatedUpdatesRestricted = hosts.Any(Host.RestrictBatchHotfixApply); if (!automatedUpdatesRestricted) { licensedPoolCount++; } } } if (WizardMode == WizardMode.NewVersion && licensedPoolCount > 0) { applyUpdatesCheckBox.Visible = true; applyUpdatesCheckBox.Text = poolCount == licensedPoolCount ? Messages.PATCHINGWIZARD_SELECTSERVERPAGE_APPLY_UPDATES : Messages.PATCHINGWIZARD_SELECTSERVERPAGE_APPLY_UPDATES_MIXED; } else { applyUpdatesCheckBox.Visible = false; } dataGridViewHosts.Rows.Clear(); foreach (IXenConnection xenConnection in xenConnections) { // add pools, their members and standalone hosts Pool pool = Helpers.GetPool(xenConnection); bool hasPool = pool != null; PatchingHostsDataGridViewRow poolRow = null; if (hasPool) { poolRow = new PatchingHostsDataGridViewRow(pool); dataGridViewHosts.Rows.Add(poolRow); poolRow.Enabled = false; } Host[] hosts = xenConnection.Cache.Hosts; Array.Sort(hosts); PatchingHostsDataGridViewRow masterRow = null; foreach (Host host in hosts) { var hostRow = new PatchingHostsDataGridViewRow(host, hasPool, !poolSelectionOnly) { ParentPoolRow = poolRow }; dataGridViewHosts.Rows.Add(hostRow); string tooltipText; hostRow.Enabled = CanEnableRow(host, out tooltipText); hostRow.Cells[3].ToolTipText = tooltipText; //Enable the pool row if (poolRow != null && hostRow.Enabled) { poolRow.Enabled = true; } if (masterRow == null) //this will be true for the first iteration { masterRow = hostRow; } } if (poolRow != null && !poolRow.Enabled && masterRow != null) { poolRow.Cells[3].ToolTipText = masterRow.Cells[3].ToolTipText; } } // restore server selection SelectServers(SelectedServers); }
public override void CheckBoxChange(int RowIndex, int ColumnIndex) { if (RowIndex < 0 || Rows.Count == 0) { return; } var currentRow = Rows[RowIndex] as PatchingHostsDataGridViewRow; if (currentRow == null || !currentRow.Enabled) { return; } if (currentRow.Tag is Host) { if (ColumnIndex == POOL_ICON_HOST_CHECKBOX_COL && currentRow.Cells[ColumnIndex] is DataGridViewCheckBoxCell) { int hostNewValue = ClickCheckBox(RowIndex, ColumnIndex); PatchingHostsDataGridViewRow poolRow = FindPoolRow(RowIndex); bool allHostSameValue = true; bool atLeastOneHostChecked = false; for (int i = poolRow.Index + 1; i < Rows.Count; i++) { if (Rows[i].Tag is Host && ((PatchingHostsDataGridViewRow)Rows[i]).HasPool) { if ((int)Rows[i].Cells[POOL_ICON_HOST_CHECKBOX_COL].Value == CHECKED) { atLeastOneHostChecked = true; } if (((PatchingHostsDataGridViewRow)Rows[i]).Enabled && (int)Rows[i].Cells[POOL_ICON_HOST_CHECKBOX_COL].Value != hostNewValue) { allHostSameValue = false; } } else { break; } } if (allHostSameValue) { poolRow.Cells[POOL_CHECKBOX_COL].Value = hostNewValue; } else if (atLeastOneHostChecked) { poolRow.Cells[POOL_CHECKBOX_COL].Value = INDETERMINATE; } } else if (ColumnIndex == POOL_CHECKBOX_COL) { ClickCheckBox(RowIndex, ColumnIndex); } } else if (currentRow.Tag is Pool) { if (ColumnIndex == POOL_CHECKBOX_COL) { ClickCheckBox(RowIndex, ColumnIndex); for (int i = RowIndex + 1; i < Rows.Count; i++) { if (Rows[i].Tag is Host && ((PatchingHostsDataGridViewRow)Rows[i]).HasPool) { var value = (int)currentRow.Cells[ColumnIndex].Value; if (value == UNCHECKED || value == CHECKED) { Rows[i].Cells[POOL_ICON_HOST_CHECKBOX_COL].Value = value; } } else { break; } } } } OnCheckBoxClicked(); }
private void disableNotApplicableHosts(PatchingHostsDataGridViewRow row, List<Host> selectedHosts, Host host) { if (selectedHosts != null && !selectedHosts.Contains(host)) { string patchUuidFromAlert = null; if (SelectedUpdateAlert != null && SelectedUpdateAlert.Patch != null) { patchUuidFromAlert = SelectedUpdateAlert.Patch.Uuid; } else if (FileFromDiskAlert != null) { patchUuidFromAlert = FileFromDiskAlert.Patch.Uuid; } if (!string.IsNullOrEmpty(patchUuidFromAlert)) { if (isPatchApplied(patchUuidFromAlert, host)) { row.Cells[3].ToolTipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_ALREADY_APPLIED; } else { row.Cells[3].ToolTipText = Messages.PATCHINGWIZARD_SELECTSERVERPAGE_PATCH_NOT_APPLICABLE; } row.Enabled = false; } } }