示例#1
0
        void DiskListTreeView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if(skipSelectedIndexChanged)
                return;

            if (DiskListTreeView.SelectedItem is DiskListSrItem || DiskListTreeView.SelectedItem == null)
            {
                //As we're changing the index below - stall the SelectedIndexChanged event until we're done
                skipSelectedIndexChanged = true;
                try
                {
                    DiskListTreeView.SelectedItem = oldSelected;
                    OkBtn.Enabled = DiskListTreeView.SelectedItem != null;
                    DeactivateAttachButtonIfHvm();
                }
                finally
                {
                    //Ensure the lock is released
                    skipSelectedIndexChanged = false;
                }
                    
                return;
            }

            DiskListVdiItem item = DiskListTreeView.SelectedItem as DiskListVdiItem;
            ReadOnlyCheckBox.Enabled = !item.ForceReadOnly;
            ReadOnlyCheckBox.Checked = item.ForceReadOnly ? true : oldROState;
            OkBtn.Enabled = true;
            oldSelected = item;
            DeactivateControlsForHvmVm();
        }
示例#2
0
        private void DeactivateAttachButtonIfHvm()
        {
            if (!TheVM.IsHVM())
                return;

            DiskListVdiItem vdiItem = DiskListTreeView.SelectedItem as DiskListVdiItem;
            if (vdiItem != null && vdiItem.ForceReadOnly)
                OkBtn.Enabled = false;
        }
示例#3
0
 private object SelectByRef(string oldRef)
 {
     for (int i = 0; i < DiskListTreeView.Items.Count; i++)
     {
         DiskListVdiItem item = DiskListTreeView.Items[i] as DiskListVdiItem;
         if (item == null)
             continue;
         else if (item.TheVDI.opaque_ref == oldRef)
             return item;
     }
     return null;
 }
示例#4
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            DiskListVdiItem item = DiskListTreeView.SelectedItem as DiskListVdiItem;

            if (item == null)
            {
                return;
            }

            VDI TheVDI = item.TheVDI;

            // Run this stuff off the event thread, since it involves a server call
            System.Threading.ThreadPool.QueueUserWorkItem(delegate
            {
                // Get a spare userdevice
                string[] uds = VM.get_allowed_VBD_devices(connection.DuplicateSession(), TheVM.opaque_ref);
                if (uds.Length == 0)
                {
                    Program.Invoke(Program.MainWindow, delegate()
                    {
                        using (var dlg = new ErrorDialog(FriendlyErrorNames.VBDS_MAX_ALLOWED)
                        {
                            WindowTitle = Messages.DISK_ATTACH
                        })
                        {
                            dlg.ShowDialog(Program.MainWindow);
                        }
                    });

                    return;
                }
                string ud = uds[0];

                VBD vbd      = new VBD();
                vbd.VDI      = new XenRef <VDI>(TheVDI);
                vbd.VM       = new XenRef <VM>(TheVM);
                vbd.bootable = ud == "0";
                vbd.device   = "";
                vbd.SetIsOwner(TheVDI.VBDs.Count == 0);
                vbd.empty       = false;
                vbd.userdevice  = ud;
                vbd.type        = vbd_type.Disk;
                vbd.mode        = ReadOnlyCheckBox.Checked ? vbd_mode.RO : vbd_mode.RW;
                vbd.unpluggable = true;

                // Try to hot plug the VBD.
                var action = new VbdSaveAndPlugAction(TheVM, vbd, TheVDI.Name(), null, false);
                action.ShowUserInstruction += Action_ShowUserInstruction;
                action.RunAsync();
            });

            Close();
        }
示例#5
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            DiskListVdiItem item = DiskListTreeView.SelectedItem as DiskListVdiItem;

            if (item == null)
            {
                return;
            }

            VDI TheVDI = item.TheVDI;

            // Run this stuff off the event thread, since it involves a server call
            System.Threading.ThreadPool.QueueUserWorkItem((System.Threading.WaitCallback) delegate(object o)
            {
                // Get a spare userdevice
                string[] uds = VM.get_allowed_VBD_devices(connection.DuplicateSession(), TheVM.opaque_ref);
                if (uds.Length == 0)
                {
                    Program.Invoke(Program.MainWindow, delegate()
                    {
                        using (var dlg = new ThreeButtonDialog(
                                   new ThreeButtonDialog.Details(
                                       SystemIcons.Error,
                                       FriendlyErrorNames.VBDS_MAX_ALLOWED, Messages.DISK_ATTACH)))
                        {
                            dlg.ShowDialog(Program.MainWindow);
                        }
                    });
                    // Give up
                    return;
                }
                string ud = uds[0];

                VBD vbd         = new VBD();
                vbd.VDI         = new XenRef <VDI>(TheVDI);
                vbd.VM          = new XenRef <VM>(TheVM);
                vbd.bootable    = ud == "0";
                vbd.device      = "";
                vbd.IsOwner     = TheVDI.VBDs.Count == 0;
                vbd.empty       = false;
                vbd.userdevice  = ud;
                vbd.type        = vbd_type.Disk;
                vbd.mode        = ReadOnlyCheckBox.Checked ? vbd_mode.RO : vbd_mode.RW;
                vbd.unpluggable = true;

                // Try to hot plug the VBD.
                new VbdSaveAndPlugAction(TheVM, vbd, TheVDI.Name, null, false, NewDiskDialog.ShowMustRebootBoxCD, NewDiskDialog.ShowVBDWarningBox).RunAsync();
            });

            Close();
        }
示例#6
0
        private void BuildList()
        {
            Program.AssertOnEventThread();

            DiskListVdiItem lastSelected = DiskListTreeView.SelectedItem as DiskListVdiItem;

            String oldRef = "";

            if (lastSelected != null)
            {
                oldRef = lastSelected.TheVDI.opaque_ref;
            }

            DiskListTreeView.BeginUpdate();
            try
            {
                DiskListTreeView.ClearAllNodes();

                foreach (SR sr in connection.Cache.SRs)
                {
                    DiskListSrItem item = new DiskListSrItem(sr, TheVM);
                    if (item.Show)
                    {
                        DiskListTreeView.AddNode(item);
                        foreach (VDI TheVDI in sr.Connection.ResolveAllShownXenModelObjects(sr.VDIs, Properties.Settings.Default.ShowHiddenVMs))
                        {
                            DiskListVdiItem VDIitem = new DiskListVdiItem(TheVDI);
                            if (VDIitem.Show)
                            {
                                DiskListTreeView.AddChildNode(item, VDIitem);
                            }
                            TheVDI.PropertyChanged -= new PropertyChangedEventHandler(Server_Changed);
                            TheVDI.PropertyChanged += new PropertyChangedEventHandler(Server_Changed);
                        }
                    }
                    sr.PropertyChanged -= new PropertyChangedEventHandler(Server_Changed);
                    sr.PropertyChanged += new PropertyChangedEventHandler(Server_Changed);
                }
            }
            finally
            {
                DiskListTreeView.EndUpdate();
                DiskListTreeView.SelectedItem = SelectByRef(oldRef);
            }
        }