private void SelectPhysicalDiskForm_Load(object sender, EventArgs e)
        {
            List <Volume> volumes = WindowsVolumeHelper.GetVolumes();

            for (int index = 0; index < volumes.Count; index++)
            {
                Volume volume = volumes[index];
                string title  = String.Format("Volume {0}", index);
                string type   = VolumeHelper.GetVolumeTypeString(volume);
                string status = VolumeHelper.GetVolumeStatusString(volume);

                ulong  volumeID = 0;
                string name     = String.Empty;
                if (volume is DynamicVolume)
                {
                    volumeID = ((DynamicVolume)volume).VolumeID;
                    name     = ((DynamicVolume)volume).Name;
                }
                else if (volume is GPTPartition)
                {
                    name = ((GPTPartition)volume).PartitionName;
                }
                ListViewItem item = new ListViewItem(title);
                item.SubItems.Add(name);
                item.SubItems.Add(type);
                item.SubItems.Add(status);
                item.SubItems.Add(FormattingHelper.GetStandardSizeString(volume.Size));
                item.Tag = volume;
                listVolumes.Items.Add(item);
            }
        }
Beispiel #2
0
        public static void SelectCommand(string[] args)
        {
            if (args.Length == 1)
            {
                HelpSelect();
                return;
            }

            switch (args[1].ToLower())
            {
            case "disk":
            {
                if (args.Length == 3)
                {
                    int diskIndex = Conversion.ToInt32(args[2], -1);
                    if (diskIndex >= 0)
                    {
                        PhysicalDisk disk = null;
                        try
                        {
                            disk = new PhysicalDisk(diskIndex);
                        }
                        catch
                        {
                            Console.WriteLine();
                            Console.WriteLine("Error: Invalid disk number");
                        }

                        if (disk != null)
                        {
                            m_selectedDisk = disk;
                        }
                    }
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Error: Invalid number of arguments");
                }
                break;
            }

            case "vdisk":
            {
                if (args.Length == 3)
                {
                    KeyValuePairList <string, string> parameters = ParseParameters(args, 2);
                    if (parameters.ContainsKey("file"))
                    {
                        string path = parameters.ValueOf("file");
                        if (new FileInfo(path).Exists)
                        {
                            try
                            {
                                m_selectedDisk = DiskImage.GetDiskImage(path);
                            }
                            catch (InvalidDataException)
                            {
                                Console.WriteLine("Invalid virtual disk format");
                            }
                            catch (NotImplementedException)
                            {
                                Console.WriteLine("Unsupported virtual disk format");
                            }
                            catch (IOException ex)
                            {
                                Console.WriteLine("Cannot read file: " + ex.Message);
                            }
                        }
                        else
                        {
                            Console.WriteLine("File not found: \"{0}\"", path);
                        }
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Error: Invalid argument");
                    }
                }
                else
                {
                    Console.WriteLine("Error: Invalid number of arguments");
                }
                break;
            }

            case "partition":
            {
                if (m_selectedDisk != null)
                {
                    if (args.Length == 3)
                    {
                        int partitionIndex          = Conversion.ToInt32(args[2], -1);
                        List <Partition> partitions = BasicDiskHelper.GetPartitions(m_selectedDisk);
                        if (partitionIndex >= 0 && partitionIndex < partitions.Count)
                        {
                            m_selectedVolume = partitions[partitionIndex];
                        }
                        else
                        {
                            Console.WriteLine("Error: Invalid partition number");
                        }
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Error: Partition number was not specified");
                    }
                }
                else
                {
                    Console.WriteLine("No disk has been selected");
                }
                break;
            }

            case "volume":
            {
                if (args.Length == 3)
                {
                    List <Volume> volumes;
                    try
                    {
                        volumes = WindowsVolumeHelper.GetVolumes();
                    }
                    catch
                    {
                        volumes = new List <Volume>();
                    }

                    int volumeIndex = Conversion.ToInt32(args[2], -1);
                    if (volumeIndex >= 0 && volumeIndex < volumes.Count)
                    {
                        m_selectedVolume = volumes[volumeIndex];
                    }
                    else
                    {
                        Console.WriteLine();
                        Console.WriteLine("Error: Invalid volume number");
                    }
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Error: Volume number was not specified");
                }
                break;
            }

            default:
                HelpSelect();
                break;
            }
        }
Beispiel #3
0
        public static void ListVolumes()
        {
            List <Volume> volumes = WindowsVolumeHelper.GetVolumes();

            Console.WriteLine("Volume ##  ID    Name          Type       Size     Status   ");
            Console.WriteLine("---------  ----  ------------  ---------  -------  ---------");

            for (int index = 0; index < volumes.Count; index++)
            {
                Volume volume = volumes[index];
                string type   = String.Empty;
                string status = String.Empty;

                ulong  volumeID = 0;
                string name     = String.Empty;

                if (volume is DynamicVolume)
                {
                    volumeID = ((DynamicVolume)volume).VolumeID;
                    name     = ((DynamicVolume)volume).Name;

                    if (((DynamicVolume)volume).IsHealthy)
                    {
                        status = "Healthy";
                    }
                    else
                    {
                        status = "Failed";
                    }
                }

                if (volume is SimpleVolume)
                {
                    type = "Simple";
                }
                else if (volume is SpannedVolume)
                {
                    type = "Spanned";
                }
                else if (volume is StripedVolume)
                {
                    type = "Striped";
                }
                else if (volume is MirroredVolume)
                {
                    type = "Mirrored";
                    if (!((MirroredVolume)volume).IsHealthy && ((MirroredVolume)volume).IsOperational)
                    {
                        status = "Failed Rd";
                    }
                }
                else if (volume is Raid5Volume)
                {
                    type = "RAID-5";
                    if (!((Raid5Volume)volume).IsHealthy && ((Raid5Volume)volume).IsOperational)
                    {
                        status = "Failed Rd";
                    }
                }
                else if (volume is Partition)
                {
                    type   = "Partition";
                    status = "Healthy";
                }

                string volumeNumber = index.ToString().PadLeft(2);
                type   = type.ToString().PadRight(9);
                name   = name.ToString().PadRight(12);
                status = status.ToString().PadRight(9);

                string volumeIDString = String.Empty;
                if (volumeID != 0)
                {
                    volumeIDString = volumeID.ToString();
                }
                volumeIDString = volumeIDString.PadRight(4);

                Console.WriteLine("Volume {0}  {1}  {2}  {3}  {4}  {5}", volumeNumber, volumeIDString, name, type, GetStandardSizeString(volume.Size), status);
            }
        }