예제 #1
0
 private string[] GetListItemData(DiskInfo i) => new[] { i.Name, GetDisplayString(i.State), SizeStr(i.VirtualSize), SizeStr(i.Size) };
예제 #2
0
        private void diskListView_SelectedIndexChanged(object sender, EventArgs e)
        {
            var dil = diskListView.SelectedItems.Cast <ListViewItem>().Where(i => i.Tag is DiskInfo).Select(i => i.Tag as DiskInfo).ToList();
            var cnt = dil.Count;

            CurSel = null;

            // Set values for disk details based on selection
            if (cnt != 1)
            {
                diskDetailTextBox.Text              =
                    diskEncrTextBox.Text            =
                        diskFmtTextBox.Text         =
                            diskHostTextBox.Text    =
                                diskLocTextBox.Text = diskTypeTextBox.Text = diskUuidTextBox.Text = null;
            }
            else
            {
                CurSel = dil[0];
                diskDetailTextBox.Text = CurSel.Variant.ToString().Replace("MediumVariant_", "");
                diskEncrTextBox.Text   = CurSel.EncryptionKey ?? "Not encrypted";
                //diskDetailTextBox.Font.Italic = di.EncryptionKey == null;
                diskFmtTextBox.Text  = CurSel.Format;
                diskHostTextBox.Text = CurSel.AttachedTo;
                var sb = new StringBuilder(CurSel.Location);
                PathCompactPath(CreateGraphics().GetHdc(), sb, (uint)diskLocTextBox.Width);
                diskLocTextBox.Text  = sb.ToString();
                diskTypeTextBox.Text = CurSel.MediumType.ToString().Remove(0, 11);
                diskUuidTextBox.Text = CurSel.UUID;
            }

            // Setup all of the commands based on conditions
            if (cnt == 0)
            {
                foreach (var c in commandBindings1.Commands)
                {
                    c.Enabled = false;
                }
            }
            else
            {
                cloneCmd.Enabled   = cnt == 1 && (CurSel.State == MediumState.MediumState_Created || CurSel.State == MediumState.MediumState_NotCreated);
                compactCmd.Enabled = dil.All(di => di.Format == "VDI" || di.Format == "VHD");
                removeCmd.Enabled  = cnt == 1 && CurSel.State == MediumState.MediumState_Created && !CurSel.HasChildren;
                resizeCmd.Enabled  = cnt == 1;
                moveCmd.Enabled    = cnt == 1;
                releaseCmd.Enabled = cnt == 1 && !string.IsNullOrEmpty(CurSel.AttachedTo) && CurSel.AttachedToIds.All(s => !MachineRunning(s));
                modifyCmd.Enabled  = cnt == 1 && !CurSel.Differencing;

                bool MachineRunning(string id)
                {
                    var st = MachineState.MachineState_Null;

                    try { st = Client.VBox.FindMachine(id).State; } catch { }
                    if (st == MachineState.MachineState_Null)
                    {
                        throw new InvalidOperationException();
                    }
                    return(st >= MachineState.MachineState_FirstOnline && st <= MachineState.MachineState_LastOnline);
                }
            }
            addCmd.Enabled = createCmd.Enabled = refreshCmd.Enabled = true;
        }