Exemple #1
0
        public async Task <IList <IPartition> > GetPartitions()
        {
            var results = await PowerShellMixin.ExecuteScript($"Get-Partition -DiskNumber {Number}");

            var wmiPartitions = results
                                .Select(x => x.ImmediateBaseObject)
                                .Select(ToWmiPartition);

            ReadOnlyCollection <Core.FileSystem.Gpt.Partition> gptPartitions;

            using (var context = await GptContextFactory.Create(Number, FileAccess.Read))
            {
                gptPartitions = context.Partitions;
            }

            var partitions = wmiPartitions
                             .Join(gptPartitions, x => x.Guid, x => x.Guid, (wmi, gpt) => (IPartition) new Partition(this)
            {
                Name          = gpt.Name,
                Root          = wmi.Root,
                Number        = wmi.Number,
                Guid          = wmi.Guid,
                PartitionType = wmi.PartitionType,
                UniqueId      = wmi.UniqueId,
                Size          = wmi.Size,
            });

            return(partitions.ToList());
        }
Exemple #2
0
        public async Task SetGuid(Guid guid)
        {
            Log.Verbose("Changing disk Guid {Guid} to {Disk}", guid, this);
            var cmd = $@"Set-Disk -Number {Number} -Guid ""{{{guid}}}""";
            await PowerShellMixin.ExecuteScript(cmd);

            Log.Verbose("Disk Guid changed", guid, this);
        }
Exemple #3
0
        public async Task <ICollection <DriverMetadata> > GetDrivers()
        {
            var results = await PowerShellMixin.ExecuteScript($"Get-WindowsDriver -Path {Root}");

            var disks = results
                        .Select(ToDriverMetadata);

            return(disks.ToList());
        }
Exemple #4
0
        public async Task <IList <IDisk> > GetDisks()
        {
            var results = await PowerShellMixin.ExecuteScript("Get-Disk");

            var disks = results
                        .Select(x => x.ImmediateBaseObject)
                        .Select(ToDisk);

            return(disks.ToList());
        }
Exemple #5
0
        public static async Task <PSObject> GetPsPartition(this IPartition partition)
        {
            var psDataCollection = await PowerShellMixin.ExecuteScript($"Get-Partition -DiskNumber {partition.Disk.Number} -Number {partition.Number}");

            var psPartition = psDataCollection.FirstOrDefault();

            if (psPartition == null)
            {
                throw new ApplicationException($"Could not get PS Partition for {partition}");
            }

            return(psPartition);
        }
Exemple #6
0
        public async Task <IPartition> CreatePartition(ByteSize size, PartitionType partitionType, string name = "")
        {
            if (size.Equals(ByteSize.MaxValue))
            {
                await PowerShellMixin.ExecuteScript($"New-Partition -DiskNumber {Number} -UseMaximumSize");
            }
            else
            {
                await PowerShellMixin.ExecuteScript($"New-Partition -DiskNumber {Number} -Size {size.Bytes}");
            }

            var partitions = await GetPartitions();

            return(partitions.Last());
        }
Exemple #7
0
        public async Task <IDisk> GetDisk(int n)
        {
            Log.Verbose("Getting disk by index {Id}", n);
            var results = await PowerShellMixin.ExecuteScript($"Get-Disk -Number {n}");

            var disks = results
                        .Select(x => x.ImmediateBaseObject)
                        .Select(ToDisk);

            var disk = disks.First();

            Log.Verbose("Returned disk {Disk}", disk);

            return(disk);
        }
Exemple #8
0
        public async Task <IList <IPartition> > GetPartitions()
        {
            var results = await PowerShellMixin.ExecuteScript($"Get-Partition -DiskNumber {Number}");

            var fromWmi = GetWmiPartitions(results);

            var fromGpt = await GetGptPartitions();

            IPartition FirstSelector(PartitionData wmi) =>
            new Partition(this)
            {
                Root     = wmi.Root,
                Number   = wmi.Number,
                Guid     = wmi.Guid,
                GptType  = wmi.GptType,
                UniqueId = wmi.UniqueId,
                Size     = wmi.Size,
            };

            IPartition BothSelector(PartitionData wmi, PartitionData gpt) =>
            new Partition(this)
            {
                Name     = gpt.Name,
                Root     = wmi.Root,
                Number   = wmi.Number,
                Guid     = wmi.Guid,
                GptType  = wmi.GptType,
                UniqueId = wmi.UniqueId,
                Size     = wmi.Size,
            };

            var partitions = MoreLinq.MoreEnumerable.LeftJoin(fromWmi, fromGpt,
                                                              pd => pd.Guid, FirstSelector, BothSelector);

            return(partitions.ToList());
        }
Exemple #9
0
 public async Task PrepareForRemoval()
 {
     var script = $"SELECT DISK {Number}\nOFFLINE DISK\nONLINE DISK";
     await PowerShellMixin.ExecuteScript($@"""{script}"" | & diskpart.exe");
 }
Exemple #10
0
 public async Task Refresh()
 {
     await PowerShellMixin.ExecuteScript($@"Update-HostStorageCache");
 }