protected override void WndProc(ref System.Windows.Forms.Message msg) { switch (msg.Msg) { case Win32.WM_LBUTTONDOWN: case Win32.WM_LBUTTONDBLCLK: int i = IndexFromPoint(PointToClient(MousePosition)); if (i < 0 || i >= Items.Count) { break; } SR.SRInfo info = Items[i] as SR.SRInfo; if (info == null) { break; } // If cannot select item, ignore message if (!CanSelectSRInfo(info)) { return; } break; } base.WndProc(ref msg); }
private bool RunProbe(Host master, SR.SRTypes srType, out List <SR.SRInfo> srs) { srs = null; Dictionary <String, String> dconf = GetDeviceConfig(srType); if (dconf == null) { return(false); } var action = new SrProbeAction(Connection, master, srType, dconf); using (var dialog = new ActionProgressDialog(action, ProgressBarStyle.Marquee)) { dialog.ShowCancel = true; dialog.ShowDialog(this); } _srToIntroduce = null; if (action.Succeeded) { try { srs = action.ProbeExtResult != null?SR.ParseSRList(action.ProbeExtResult) : SR.ParseSRListXML(action.Result); return(true); } catch (Exception) { return(false); } } Exception exn = action.Exception; log.Warn(exn, exn); Failure failure = exn as Failure; if (failure != null) { errorIconAtHostOrIP.Visible = true; errorLabelAtHostname.Visible = true; errorLabelAtHostname.Text = failure.ErrorDescription[0] == "SR_BACKEND_FAILURE_140" ? Messages.INVALID_HOST : (failure.ErrorDescription.Count > 2 ? failure.ErrorDescription[2] : failure.ErrorDescription[0]); textBoxIscsiHost.Focus(); } return(false); }
public IscsiChoicesDialog(IXenConnection connection, SR.SRInfo srInfo, SR.SRTypes existingSrType, SR.SRTypes requestedSrType) : base(connection) { InitializeComponent(); this.labelSRinfo.Text = String.Format(Messages.ISCSI_DIALOG_SR_DETAILS, Util.DiskSizeString(srInfo.Size), srInfo.UUID); this.labelMessage.Text = String.Format(Messages.EXISTING_SR_FOUND_ON_LUN, SR.getFriendlyTypeName(existingSrType), SR.getFriendlyTypeName(requestedSrType)); }
private bool CanSelectSRInfo(SR.SRInfo info) { SR sr = SrWizardHelpers.SrInUse(info.UUID); if (sr != null && sr.HasPBDs()) { return(false); } if (!String.IsNullOrEmpty(MustSelectUUID) && info.UUID != MustSelectUUID) { return(false); } return(true); }
protected override void OnSelectedIndexChanged(EventArgs e) { SR.SRInfo info = SelectedItem as SR.SRInfo; if (info == null || CanSelectSRInfo(info)) { base.OnSelectedIndexChanged(e); return; } //If we cannot select any SRInfos - give up if (!Items.Cast <SR.SRInfo>().Any(CanSelectSRInfo)) { return; } TryAndSelectUUID(); }
public LVMoIsciWarningDialog(IXenConnection connection, SR.SRInfo srInfo, SR.SRTypes existingSrType, SR.SRTypes requestedSrType) : base(connection, "", 0, srInfo != null, existingSrType, requestedSrType) { labelLUNDetails.Visible = false; labelSrDetails.Visible = srInfo != null; // CA-17230: if the found SR is used by other connected pools, offer only to attach it if (srInfo != null) { SR sr = SrWizardHelpers.SrInUse(srInfo.UUID); if (sr != null) { panelFormat.Visible = false; labelWarning.Text = GetSrInUseMessage(sr); } labelSrDetails.Text = string.Format(Messages.ISCSI_DIALOG_SR_DETAILS, Util.DiskSizeString(srInfo.Size), srInfo.UUID); } }
public SrRow(SR.SRInfo srInfo, SR.SRTypes type, bool poolMetadataDetected, bool selected) { SrInfo = srInfo; var cellTick = new DataGridViewCheckBoxCell { Value = selected }; var cellName = new DataGridViewTextBoxCell { Value = srInfo.Name }; var cellDesc = new DataGridViewTextBoxCell { Value = srInfo.Description }; var cellType = new DataGridViewTextBoxCell { Value = SR.getFriendlyTypeName(type) }; var cellMetadata = new DataGridViewTextBoxCell { Value = poolMetadataDetected.ToStringI18n() }; Cells.AddRange(cellTick, cellName, cellDesc, cellType, cellMetadata); }
public SrRow(SR.SRInfo srInfo, SR.SRTypes type, bool poolMetadataDetected, bool selected) { SrInfo = srInfo; HasMetadata = poolMetadataDetected; var cellTick = new DataGridViewCheckBoxCell { Value = selected }; var cellName = new DataGridViewTextBoxCell { Value = srInfo.Name }; var cellDesc = new DataGridViewTextBoxCell { Value = srInfo.Description }; var cellType = new DataGridViewTextBoxCell { Value = SR.getFriendlyTypeName(type) }; var cellMetadata = new DataGridViewTextBoxCell { Value = poolMetadataDetected.ToStringI18n() }; Cells.AddRange(cellTick, cellName, cellDesc, cellType, cellMetadata); }
private bool ExamineIscsiProbeResults(SR.SRTypes currentSrType, List <SR.SRInfo> srs) { _srToIntroduce = null; if (srs == null) { return(false); } // There should be 0 or 1 SRs on the LUN System.Diagnostics.Debug.Assert(srs.Count == 0 || srs.Count == 1); try { if (!string.IsNullOrEmpty(SrWizardType.UUID)) { // Check LUN contains correct SR if (srs.Count == 1 && srs[0].UUID == SrWizardType.UUID) { _srToIntroduce = srs[0]; SrType = currentSrType; // the type of the existing SR return(true); } ShowError(errorIconAtTargetLUN, errorLabelAtTargetLUN, string.Format(Messages.INCORRECT_LUN_FOR_SR, SrWizardType.SrName)); return(false); } if (srs.Count == 0) { if (!SrWizardType.AllowToCreateNewSr) { using (var dlg = new ErrorDialog(Messages.NEWSR_LUN_HAS_NO_SRS)) dlg.ShowDialog(this); return(false); } if (Program.RunInAutomatedTestMode) { return(true); } // SR creation is allowed; ask the user if they want to proceed and format. using (var dlog = new LVMoIsciWarningDialog(Connection, null, currentSrType, SrType)) { dlog.ShowDialog(this); return(dlog.SelectedOption == LVMoHBAWarningDialog.UserSelectedOption.Format); } } if (Program.RunInAutomatedTestMode) { return(true); } // offer to attach it, or format it to create a new SR, or cancel SR.SRInfo srInfo = srs[0]; using (var dlog = new LVMoIsciWarningDialog(Connection, srInfo, currentSrType, SrType)) { dlog.ShowDialog(this); switch (dlog.SelectedOption) { case LVMoHBAWarningDialog.UserSelectedOption.Reattach: _srToIntroduce = srInfo; SrType = currentSrType; // the type of the existing SR return(true); case LVMoHBAWarningDialog.UserSelectedOption.Format: return(true); default: return(false); } } } catch { // We really want to prevent the user getting to the next step if there is any kind of // exception here, since clicking 'finish' might destroy data: require another probe. return(false); } }
/// <summary> /// Called with the results of an iSCSI SR.probe(), either immediately after the scan, or after the /// user has performed a scan, clicked 'cancel' on a dialog, and then clicked 'next' again (this /// avoids duplicate probing if none of the settings have changed). /// </summary> /// <returns> /// Whether to continue or not - wheter to format or not is stored in /// iScsiFormatLUN. /// </returns> private bool ExamineIscsiProbeResults(SrProbeAction action) { _srToIntroduce = null; if (!action.Succeeded) { Exception exn = action.Exception; log.Warn(exn, exn); Failure failure = exn as Failure; if (failure != null && failure.ErrorDescription[0] == "SR_BACKEND_FAILURE_140") { errorIconAtHostOrIP.Visible = true; errorLabelAtHostname.Visible = true; errorLabelAtHostname.Text = Messages.INVALID_HOST; textBoxIscsiHost.Focus(); } else if (failure != null) { errorIconAtHostOrIP.Visible = true; errorLabelAtHostname.Visible = true; errorLabelAtHostname.Text = failure.ErrorDescription.Count > 2 ? failure.ErrorDescription[2] : failure.ErrorDescription[0]; textBoxIscsiHost.Focus(); } return(false); } try { List <SR.SRInfo> SRs = SR.ParseSRListXML(action.Result); if (!String.IsNullOrEmpty(SrWizardType.UUID)) { // Check LUN contains correct SR if (SRs.Count == 1 && SRs[0].UUID == SrWizardType.UUID) { _srToIntroduce = SRs[0]; return(true); } errorIconAtTargetLUN.Visible = true; errorLabelAtTargetLUN.Visible = true; errorLabelAtTargetLUN.Text = String.Format(Messages.INCORRECT_LUN_FOR_SR, SrWizardType.SrName); return(false); } else if (SRs.Count == 0) { // No existing SRs were found on this LUN. If allowed to create new SR, ask the user if they want to proceed and format. if (!SrWizardType.AllowToCreateNewSr) { using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Error, Messages.NEWSR_LUN_HAS_NO_SRS, Messages.XENCENTER))) { dlg.ShowDialog(this); } return(false); } DialogResult result = DialogResult.Yes; if (!Program.RunInAutomatedTestMode) { using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Warning, Messages.NEWSR_ISCSI_FORMAT_WARNING, this.Text), ThreeButtonDialog.ButtonYes, new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true))) { result = dlg.ShowDialog(this); } } return(result == DialogResult.Yes); } else { // There should be 0 or 1 SRs on the LUN System.Diagnostics.Trace.Assert(SRs.Count == 1); // CA-17230 // Check this isn't a detached SR SR.SRInfo info = SRs[0]; SR sr = SrWizardHelpers.SrInUse(info.UUID); if (sr != null) { DialogResult res; using (var d = new ThreeButtonDialog( new ThreeButtonDialog.Details(null, string.Format(Messages.DETACHED_ISCI_DETECTED, Helpers.GetName(sr.Connection))), new ThreeButtonDialog.TBDButton(Messages.ATTACH_SR, DialogResult.OK), ThreeButtonDialog.ButtonCancel)) { res = d.ShowDialog(Program.MainWindow); } if (res == DialogResult.Cancel) { return(false); } _srToIntroduce = info; return(true); } // An SR exists on this LUN. Ask the user if they want to attach it, format it and // create a new SR, or cancel. DialogResult result = Program.RunInAutomatedTestMode ? DialogResult.Yes : new IscsiChoicesDialog(Connection, info).ShowDialog(this); switch (result) { case DialogResult.Yes: // Reattach _srToIntroduce = SRs[0]; return(true); case DialogResult.No: // Format - SrToIntroduce is already null return(true); default: return(false); } } } catch { // We really want to prevent the user getting to the next step if there is any kind of // exception here, since clicking 'finish' might destroy data: require another probe. return(false); } }
/// <summary> /// Called with the results of an iSCSI SR.probe(), either immediately after the scan, or after the /// user has performed a scan, clicked 'cancel' on a dialog, and then clicked 'next' again (this /// avoids duplicate probing if none of the settings have changed). /// </summary> /// <returns> /// Whether to continue or not - wheter to format or not is stored in /// iScsiFormatLUN. /// </returns> private bool ExamineIscsiProbeResults(SrProbeAction action) { _srToIntroduce = null; if (!action.Succeeded) { Exception exn = action.Exception; log.Warn(exn, exn); Failure failure = exn as Failure; if (failure != null && failure.ErrorDescription[0] == "SR_BACKEND_FAILURE_140") { errorIconAtHostOrIP.Visible = true; errorLabelAtHostname.Visible = true; errorLabelAtHostname.Text = Messages.INVALID_HOST; textBoxIscsiHost.Focus(); } else if (failure != null) { errorIconAtHostOrIP.Visible = true; errorLabelAtHostname.Visible = true; errorLabelAtHostname.Text = failure.ErrorDescription.Count > 2 ? failure.ErrorDescription[2] : failure.ErrorDescription[0]; textBoxIscsiHost.Focus(); } return false; } try { List<SR.SRInfo> SRs = SR.ParseSRListXML(action.Result); if (!String.IsNullOrEmpty(SrWizardType.UUID)) { // Check LUN contains correct SR if (SRs.Count == 1 && SRs[0].UUID == SrWizardType.UUID) { _srToIntroduce = SRs[0]; return true; } errorIconAtTargetLUN.Visible = true; errorLabelAtTargetLUN.Visible = true; errorLabelAtTargetLUN.Text = String.Format(Messages.INCORRECT_LUN_FOR_SR, SrWizardType.SrName); return false; } else if (SRs.Count == 0) { // No existing SRs were found on this LUN. If allowed to create new SR, ask the user if they want to proceed and format. if (!SrWizardType.AllowToCreateNewSr) { using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Error, Messages.NEWSR_LUN_HAS_NO_SRS, Messages.XENCENTER))) { dlg.ShowDialog(this); } return false; } DialogResult result = DialogResult.Yes; if (!Program.RunInAutomatedTestMode) { using (var dlg = new ThreeButtonDialog( new ThreeButtonDialog.Details(SystemIcons.Warning, Messages.NEWSR_ISCSI_FORMAT_WARNING, this.Text), ThreeButtonDialog.ButtonYes, new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, ThreeButtonDialog.ButtonType.CANCEL, true))) { result = dlg.ShowDialog(this); } } return result == DialogResult.Yes; } else { // There should be 0 or 1 SRs on the LUN System.Diagnostics.Trace.Assert(SRs.Count == 1); // CA-17230 // Check this isn't a detached SR SR.SRInfo info = SRs[0]; SR sr = SrWizardHelpers.SrInUse(info.UUID); if (sr != null) { DialogResult res; using (var d = new ThreeButtonDialog( new ThreeButtonDialog.Details(null, string.Format(Messages.DETACHED_ISCI_DETECTED, Helpers.GetName(sr.Connection))), new ThreeButtonDialog.TBDButton(Messages.ATTACH_SR, DialogResult.OK), ThreeButtonDialog.ButtonCancel)) { res = d.ShowDialog(Program.MainWindow); } if (res == DialogResult.Cancel) return false; _srToIntroduce = info; return true; } // An SR exists on this LUN. Ask the user if they want to attach it, format it and // create a new SR, or cancel. DialogResult result = Program.RunInAutomatedTestMode ? DialogResult.Yes : new IscsiChoicesDialog(Connection, info).ShowDialog(this); switch (result) { case DialogResult.Yes: // Reattach _srToIntroduce = SRs[0]; return true; case DialogResult.No: // Format - SrToIntroduce is already null return true; default: return false; } } } catch { // We really want to prevent the user getting to the next step if there is any kind of // exception here, since clicking 'finish' might destroy data: require another probe. return false; } }
protected override void OnKeyDown(KeyEventArgs e) { bool movingUp = e.KeyCode == Keys.Up || e.KeyCode == Keys.Left || e.KeyCode == Keys.PageUp; bool movingDown = e.KeyCode == Keys.Down || e.KeyCode == Keys.Right || e.KeyCode == Keys.PageDown; bool movingPage = e.KeyCode == Keys.PageUp || e.KeyCode == Keys.PageDown; if (Items.Count <= 0 || !(movingUp || movingDown)) { base.OnKeyDown(e); return; } int index = SelectedIndex; int bottomIndex = TopIndex + ClientSize.Height / ItemHeight; int firstAvailable = -1; int lastAvailableInView = -1; int lastAvailableOffView = -1; if (movingUp) { while (--index >= 0) { SR.SRInfo nextInfo = Items[index] as SR.SRInfo; if (nextInfo == null || CanSelectSRInfo(nextInfo)) { if (firstAvailable == -1) { firstAvailable = index; } if (movingPage) { if (index >= TopIndex) { lastAvailableInView = index; } else { lastAvailableOffView = index; } } else { break; } } } } if (movingDown) { while (++index <= Items.Count - 1) { SR.SRInfo nextInfo = Items[index] as SR.SRInfo; if (nextInfo == null || CanSelectSRInfo(nextInfo)) { if (firstAvailable == -1) { firstAvailable = index; } if (movingPage) { if (index <= bottomIndex) { lastAvailableInView = index; } else { lastAvailableOffView = index; } } else { break; } } } } if (movingPage) { if (lastAvailableInView > -1) { SelectedIndex = lastAvailableInView; } else if (lastAvailableOffView > -1) { SelectedIndex = lastAvailableOffView; } } else if (firstAvailable > -1) { SelectedIndex = firstAvailable; } e.Handled = true; base.OnKeyDown(e); }
private void SRListBox_DrawItem(object sender, DrawItemEventArgs e) { if (e.Index == -1) { return; } SR.SRInfo info = Items[e.Index] as SR.SRInfo; if (info == null) { return; } SR sr = SrWizardHelpers.SrInUse(info.UUID); Color fore, back; if (!Enabled) { fore = SystemColors.GrayText; back = SystemColors.Control; } else if (!CanSelectSRInfo(info)) { // Draw in-use SRs grayed out fore = SystemColors.GrayText; back = SystemColors.Window; } else if ((e.State & DrawItemState.Selected) > 0) { // When control enabled, draw the selected item blue fore = SystemColors.HighlightText; back = SystemColors.Highlight; } else { fore = SystemColors.ControlText; back = SystemColors.Window; } // Fill in background using (SolidBrush backBrush = new SolidBrush(back)) { e.Graphics.FillRectangle(backBrush, e.Bounds); } if (sr == null) { // Draw SR UUID in monospace, but size in normal font Size s = Drawing.MeasureText(info.UUID + " ", MonospaceFont); Drawing.DrawText(e.Graphics, info.UUID + " ", MonospaceFont, e.Bounds.Location, fore); if (!String.IsNullOrEmpty(info.Aggr)) { Drawing.DrawText(e.Graphics, info.Aggr + " ", e.Font, new Point(e.Bounds.Left + s.Width, e.Bounds.Top), fore); } } else { String text = String.Format(Messages.SR_X_ON_Y, sr.Name(), Helpers.GetName(sr.Connection)); if (!sr.HasPBDs()) { text = String.Format(Messages.DETACHED_BRACKETS, text); } Drawing.DrawText(e.Graphics, text, e.Font, e.Bounds.Location, fore); } }
/// <summary> /// Called with the results of an iSCSI SR.probe(), either immediately after the scan, or after the /// user has performed a scan, clicked 'cancel' on a dialog, and then clicked 'next' again (this /// avoids duplicate probing if none of the settings have changed). /// </summary> /// <returns> /// Whether to continue or not - wheter to format or not is stored in /// iScsiFormatLUN. /// </returns> private bool ExamineIscsiProbeResults(SR.SRTypes currentSrType, List <SR.SRInfo> srs) { _srToIntroduce = null; if (srs == null) { return(false); } try { if (!String.IsNullOrEmpty(SrWizardType.UUID)) { // Check LUN contains correct SR if (srs.Count == 1 && srs[0].UUID == SrWizardType.UUID) { _srToIntroduce = srs[0]; SrType = currentSrType; // the type of the existing SR return(true); } errorIconAtTargetLUN.Visible = true; errorLabelAtTargetLUN.Visible = true; errorLabelAtTargetLUN.Text = String.Format(Messages.INCORRECT_LUN_FOR_SR, SrWizardType.SrName); return(false); } else if (srs.Count == 0) { // No existing SRs were found on this LUN. If allowed to create new SR, ask the user if they want to proceed and format. if (!SrWizardType.AllowToCreateNewSr) { using (var dlg = new ErrorDialog(Messages.NEWSR_LUN_HAS_NO_SRS)) dlg.ShowDialog(this); return(false); } DialogResult result = DialogResult.Yes; if (!Program.RunInAutomatedTestMode) { using (var dlg = new WarningDialog(Messages.NEWSR_ISCSI_FORMAT_WARNING, ThreeButtonDialog.ButtonYes, new ThreeButtonDialog.TBDButton(Messages.NO_BUTTON_CAPTION, DialogResult.No, selected: true)) { WindowTitle = Text }) { result = dlg.ShowDialog(this); } } return(result == DialogResult.Yes); } else { // There should be 0 or 1 SRs on the LUN System.Diagnostics.Trace.Assert(srs.Count == 1); // CA-17230 // Check this isn't a detached SR SR.SRInfo info = srs[0]; SR sr = SrWizardHelpers.SrInUse(info.UUID); if (sr != null) { DialogResult res; using (var d = new NoIconDialog(string.Format(Messages.DETACHED_ISCI_DETECTED, Helpers.GetName(sr.Connection)), new ThreeButtonDialog.TBDButton(Messages.ATTACH_SR, DialogResult.OK), ThreeButtonDialog.ButtonCancel)) { res = d.ShowDialog(Program.MainWindow); } if (res == DialogResult.Cancel) { return(false); } _srToIntroduce = info; SrType = currentSrType; // the type of the existing SR return(true); } // An SR exists on this LUN. Ask the user if they want to attach it, format it and // create a new SR, or cancel. DialogResult result = Program.RunInAutomatedTestMode ? DialogResult.Yes : new IscsiChoicesDialog(Connection, info, currentSrType, SrType).ShowDialog(this); switch (result) { case DialogResult.Yes: // Reattach _srToIntroduce = srs[0]; SrType = currentSrType; // the type of the existing SR return(true); case DialogResult.No: // Format - SrToIntroduce is already null return(true); default: return(false); } } } catch { // We really want to prevent the user getting to the next step if there is any kind of // exception here, since clicking 'finish' might destroy data: require another probe. return(false); } }