private void ActivateDeactivateVdi() { List <VBDRow> rows = SelectedVBDRows; if (rows == null) { return; } var selection = from VBDRow r in rows select new SelectedItem(r.VBD); SelectedItemCollection col = new SelectedItemCollection(selection); Command cmd = null; if (col.AsXenObjects <VBD>().Find(vbd => !vbd.currently_attached) == null) { cmd = new DeactivateVBDCommand(Program.MainWindow, col); } else { cmd = new ActivateVBDCommand(Program.MainWindow, col); } if (cmd.CanExecute()) { cmd.Execute(); } }
private void DeactivateButton_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.VBD)); } SelectedItemCollection col = new SelectedItemCollection(l); Command cmd = null; if (col.AsXenObjects <VBD>().Find(vbd => !vbd.currently_attached) == null) { cmd = new DeactivateVBDCommand(Program.MainWindow, l); } else { cmd = new ActivateVBDCommand(Program.MainWindow, l); } 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; DetachButton.Enabled = false; DeleteButton.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(); DeleteButton.Enabled = true; } else { DeleteButtonContainer.SetToolTip(deleteCmd.ToolTipText); DeleteButton.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 toolStripMenuItemDeactivate.Text = DeactivateButton.Text = Messages.DEACTIVATE; activationCmd = new DeactivateVBDCommand(Program.MainWindow, selectedVBDs); } else { // this is the default cause in the mixed attached/detached scenario. We try to activate all the selection // The command error reports afterwards about the ones which are already attached toolStripMenuItemDeactivate.Text = 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(); DetachButton.Enabled = true; } else { DetachButtonContainer.SetToolTip(detachCmd.ToolTipText); DetachButton.Enabled = false; } // Move button Command moveCmd = MoveVirtualDiskDialog.MoveMigrateCommand(Program.MainWindow, selectedVDIs); if (moveCmd.CanExecute()) { MoveButton.Enabled = true; MoveButtonContainer.RemoveAll(); } else { MoveButton.Enabled = false; MoveButtonContainer.SetToolTip(moveCmd.ToolTipText); } }