protected override bool CanExecuteCore(SelectedItemCollection selection) { if (_slr != null && selection.ContainsOneItemOfType<VDI>()) { VDI vdi = (VDI)selection[0].XenObject; var deleteCommand = new DeleteVirtualDiskCommand(MainWindowCommandInterface, vdi); return vdi.sm_config.ContainsKey("SVID") && !string.IsNullOrEmpty(vdi.sm_config["SVID"]) && deleteCommand.CanExecute(); } return false; }
protected override bool CanExecuteCore(SelectedItemCollection selection) { if (_slr != null && selection.ContainsOneItemOfType <VDI>()) { VDI vdi = (VDI)selection[0].XenObject; var deleteCommand = new DeleteVirtualDiskCommand(MainWindowCommandInterface, vdi); return(vdi.sm_config.ContainsKey("SVID") && !string.IsNullOrEmpty(vdi.sm_config["SVID"]) && deleteCommand.CanExecute()); } return(false); }
private void removeVirtualDisk_Click(object sender, EventArgs e) { SelectedItemCollection vdis = SelectedVDIs; DeleteVirtualDiskCommand cmd = new DeleteVirtualDiskCommand(Program.MainWindow, vdis); cmd.AllowMultipleVBDDelete = true; if (cmd.CanExecute()) cmd.Execute(); }
private void removeContextMenuStrip_Opening(object sender, CancelEventArgs e) { removeContextMenuStrip.Items.Clear(); SelectedItemCollection vdis = SelectedVDIs; if (vdis.Count > 0) { Command cmd = new DeleteVirtualDiskCommand(Program.MainWindow, vdis); removeContextMenuStrip.Items.Add(new CommandToolStripMenuItem(cmd, Messages.DELETE_VIRTUAL_DISK)); cmd = new RemoveStorageLinkVolumeCommand(Program.MainWindow, sr.StorageLinkRepository(Program.StorageLinkConnections), vdis); removeContextMenuStrip.Items.Add(new CommandToolStripMenuItem(cmd, Messages.DELETE_SL_VOLUME_CONTEXT_MENU_ELIPS)); } }
private void RefreshButtons() { bool srLocked = sr == null || sr.Locked; SelectedItemCollection vdis = SelectedVDIs; // Delete button DeleteVirtualDiskCommand deleteCmd = new DeleteVirtualDiskCommand(Program.MainWindow, vdis); // User has visibility that this disk is related to all it's VM. Allow deletion with multiple VBDs (non default behaviour), // but don't allow them to delete if a running vm is using the disk (default behaviour). deleteCmd.AllowMultipleVBDDelete = true; if (deleteCmd.CanExecute()) { RemoveButton.Enabled = true; RemoveButtonContainer.RemoveAll(); } else { RemoveButton.Enabled = false; RemoveButtonContainer.SetToolTip(deleteCmd.ToolTipText); } // Move button Command moveCmd = MoveMigrateCommand(vdis); if (moveCmd.CanExecute()) { buttonMove.Enabled = true; toolTipContainerMove.RemoveAll(); } else { buttonMove.Enabled = false; toolTipContainerMove.SetToolTip(moveCmd.ToolTipText); } // Rescan button if (srLocked) { buttonRefresh.Enabled = false; } else if (HelpersGUI.BeingScanned(sr)) { buttonRefresh.Enabled = false; toolTipContainerRescan.SetToolTip(Messages.SCAN_IN_PROGRESS_TOOLTIP); } else { buttonRefresh.Enabled = true; toolTipContainerRescan.RemoveAll(); } // Add VDI button addVirtualDiskButton.Enabled = !srLocked; // Properties button if (vdis.Count == 1) { VDI vdi = vdis.AsXenObjects<VDI>()[0]; EditButton.Enabled = !srLocked && !vdi.is_a_snapshot && !vdi.Locked; } else EditButton.Enabled = false; // Remove drop down button removeDropDownButton.Enabled = deleteCmd.CanExecute(); }
private void contextMenuStrip_Opening(object sender, CancelEventArgs e) { SelectedItemCollection vdis = SelectedVDIs; if (vdis.Count == 0) return; contextMenuStrip1.Items.Clear(); DeleteVirtualDiskCommand deleteCmd = new DeleteVirtualDiskCommand(Program.MainWindow, vdis); contextMenuStrip1.Items.Add(new CommandToolStripMenuItem(deleteCmd, true)); contextMenuStrip1.Items.Add(new CommandToolStripMenuItem(MoveMigrateCommand(vdis), true)); contextMenuStrip1.Items.Add(editVirtualDiskToolStripMenuItem); editVirtualDiskToolStripMenuItem.Enabled = vdis.Count == 1 && !vdis.AsXenObjects<VDI>()[0].is_a_snapshot; }
private void DeleteDriveButton_Click(object sender, EventArgs e) { List<VBDRow> rows = SelectedVBDRows; if (rows == null) return; List<SelectedItem> l = new List<SelectedItem>(); foreach (VBDRow r in rows) l.Add(new SelectedItem(r.VDI)); DeleteVirtualDiskCommand cmd = new DeleteVirtualDiskCommand(Program.MainWindow, l); // User has visibility that this disk in use by this VM. Allow unplug + delete in single step (non default behaviour), // but only if we are the only VBD (default behaviour) cmd.AllowRunningVMDelete = true; if (cmd.CanExecute()) cmd.Execute(); }
private void UpdateButtons() { AttachVirtualDiskCommand attachCmd = new AttachVirtualDiskCommand(Program.MainWindow, vm); AttachButton.Enabled = attachCmd.CanExecute(); AddButton.Enabled = attachCmd.CanExecute(); List<VBDRow> vbdRows = SelectedVBDRows; if (dataGridViewStorage.Rows.Count == 0 || vbdRows == null || vm == null) { DeactivateButton.Enabled = false; DetachDriveButton.Enabled = false; DeleteDriveButton.Enabled = false; EditButton.Enabled = false; MoveButton.Enabled = false; return; } EditButton.Enabled = vbdRows.Count == 1 && !vbdRows[0].VBD.Locked && !vbdRows[0].VDI.Locked; List<SelectedItem> selectedVDIs = new List<SelectedItem>(); List<SelectedItem> selectedVBDs = new List<SelectedItem>(); foreach (VBDRow r in vbdRows) { selectedVDIs.Add(new SelectedItem(r.VDI)); selectedVBDs.Add(new SelectedItem(r.VBD)); } DeleteVirtualDiskCommand deleteCmd = new DeleteVirtualDiskCommand(Program.MainWindow, selectedVDIs); // User has visibility that this disk in use by this VM. Allow unplug + delete in single step (non default behaviour), // but only if we are the only VBD (default behaviour) deleteCmd.AllowRunningVMDelete = true; if (deleteCmd.CanExecute()) { DeleteButtonContainer.RemoveAll(); DeleteDriveButton.Enabled = true; } else { DeleteButtonContainer.SetToolTip(deleteCmd.ToolTipText); DeleteDriveButton.Enabled = false; } Command activationCmd = null; SelectedItemCollection vbdCol = new SelectedItemCollection(selectedVBDs); if (vbdCol.AsXenObjects<VBD>().Find(delegate(VBD vbd) { return !vbd.currently_attached; }) == null) { // no VBDs are attached so we are deactivating DeactivateButton.Text = Messages.DEACTIVATE; activationCmd = new DeactivateVBDCommand(Program.MainWindow, selectedVBDs); } else { // this is the default cause in the mixed attached/detatched scenario. We try to activate all the selection // The command error reports afterwards about the ones which are already attached DeactivateButton.Text = Messages.ACTIVATE; activationCmd = new ActivateVBDCommand(Program.MainWindow, selectedVBDs); } if (activationCmd.CanExecute()) { DeactivateButtonContainer.RemoveAll(); DeactivateButton.Enabled = true; } else { DeactivateButtonContainer.SetToolTip(activationCmd.ToolTipText); DeactivateButton.Enabled = false; } DetachVirtualDiskCommand detachCmd = new DetachVirtualDiskCommand(Program.MainWindow, selectedVDIs, vm); if (detachCmd.CanExecute()) { DetachButtonContainer.RemoveAll(); DetachDriveButton.Enabled = true; } else { DetachButtonContainer.SetToolTip(detachCmd.ToolTipText); DetachDriveButton.Enabled = false; } // Move button Command moveCmd = MoveMigrateCommand(selectedVDIs); if (moveCmd.CanExecute()) { MoveButton.Enabled = true; MoveButtonContainer.RemoveAll(); } else { MoveButton.Enabled = false; MoveButtonContainer.SetToolTip(moveCmd.ToolTipText); } }
private void RemoveSelectedVdis() { SelectedItemCollection vdis = SelectedVDIs; DeleteVirtualDiskCommand cmd = new DeleteVirtualDiskCommand(Program.MainWindow, vdis) {AllowMultipleVBDDelete = true}; if (cmd.CanExecute()) cmd.Execute(); }
private void RefreshButtons() { SelectedItemCollection vdis = SelectedVDIs; // Delete button // The user can see that this disk is attached to more than one VMs. Allow deletion of multiple VBDs (non default behaviour), // but don't allow them to be deleted if a running vm is using the disk (default behaviour). DeleteVirtualDiskCommand deleteCmd = new DeleteVirtualDiskCommand(Program.MainWindow, vdis) {AllowMultipleVBDDelete = true}; if (deleteCmd.CanExecute()) { RemoveButton.Enabled = true; RemoveButtonContainer.RemoveAll(); } else { RemoveButton.Enabled = false; RemoveButtonContainer.SetToolTip(deleteCmd.ToolTipText); } // Move button Command moveCmd = MoveVirtualDiskDialog.MoveMigrateCommand(Program.MainWindow, vdis); if (moveCmd.CanExecute()) { buttonMove.Enabled = true; toolTipContainerMove.RemoveAll(); } else { buttonMove.Enabled = false; toolTipContainerMove.SetToolTip(moveCmd.ToolTipText); } // Rescan button if (sr == null || sr.Locked) { buttonRescan.Enabled = false; } else if (HelpersGUI.BeingScanned(sr)) { buttonRescan.Enabled = false; toolTipContainerRescan.SetToolTip(Messages.SCAN_IN_PROGRESS_TOOLTIP); } else { buttonRescan.Enabled = true; toolTipContainerRescan.RemoveAll(); } // Add VDI button addVirtualDiskButton.Enabled = sr != null && !sr.Locked; // Properties button if (vdis.Count == 1) { VDI vdi = vdis.AsXenObjects<VDI>()[0]; EditButton.Enabled = sr != null && !sr.Locked && !vdi.is_a_snapshot && !vdi.Locked; } else EditButton.Enabled = false; }