Ejemplo n.º 1
0
 public override void Build(IMainWindow mainWindow, SelectedItemCollection selection, ContextMenuItemCollection items)
 {
     items.Add(MoveVirtualDiskDialog.MoveMigrateCommand(mainWindow, selection));
     // Default behaviour of this command is very conservative, they wont be able to delete if there are multi vbds,
     // or if any of the vbds are plugged on top of the other constraints.
     items.Add(new DeleteVirtualDiskCommand(mainWindow, selection));
 }
Ejemplo n.º 2
0
        private void MoveSelectedVdis()
        {
            SelectedItemCollection vdis = SelectedVDIs;
            Command cmd = MoveVirtualDiskDialog.MoveMigrateCommand(Program.MainWindow, vdis);

            if (cmd.CanExecute())
            {
                cmd.Execute();
            }
        }
Ejemplo n.º 3
0
        private void MoveVdi()
        {
            List <VBDRow> rows = SelectedVBDRows;

            if (rows == null)
            {
                return;
            }

            var vdis = (from VBDRow r in rows select new SelectedItem(r.VDI)).ToList();

            var cmd = MoveVirtualDiskDialog.MoveMigrateCommand(Program.MainWindow, new SelectedItemCollection(vdis));

            if (cmd.CanExecute())
            {
                cmd.Execute();
            }
        }
Ejemplo n.º 4
0
        private void RefreshButtons()
        {
            var vdis = dataGridViewVDIs.SelectedRows.Cast <VDIRow>().Select(r => new SelectedItem(r.VDI)).ToList();

            // 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).

            RemoveButton.Command = new DeleteVirtualDiskCommand(Program.MainWindow, vdis)
            {
                AllowMultipleVBDDelete = true
            };

            // Move button
            buttonMove.Command = MoveVirtualDiskDialog.MoveMigrateCommand(Program.MainWindow, new SelectedItemCollection(vdis));

            // 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
            EditButton.Enabled = vdis.Count == 1 && vdis[0].XenObject is VDI vdi &&
                                 sr != null && !sr.Locked && !vdi.is_a_snapshot && !vdi.Locked;
            EditButton.Tag = EditButton.Enabled ? vdis[0].XenObject as VDI : null;
        }
Ejemplo n.º 5
0
        private void MoveVdi()
        {
            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));
            }

            Command cmd = MoveVirtualDiskDialog.MoveMigrateCommand(Program.MainWindow, l);

            if (cmd.CanExecute())
            {
                cmd.Execute();
            }
        }
Ejemplo n.º 6
0
        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);
            }
        }
Ejemplo n.º 7
0
        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;
            }
        }