コード例 #1
0
ファイル: Partition.cs プロジェクト: zhyfeather/WOA-Deployer
        public async Task <IVolume> GetVolume()
        {
            Log.Debug("Getting volume of {Partition}", this);

            var results = await PowerShellMixin.ExecuteCommand("Get-Volume",
                                                               ("Partition", await this.GetPsPartition()));

            var result = results.FirstOrDefault()?.ImmediateBaseObject;

            if (result == null)
            {
                return(null);
            }

            var driveLetter = (char?)result.GetPropertyValue("DriveLetter");
            var vol         = new Volume(this)
            {
                Size  = new ByteSize(Convert.ToUInt64(result.GetPropertyValue("Size"))),
                Label = (string)result.GetPropertyValue("FileSystemLabel"),
                Root  = driveLetter != null?PathExtensions.GetRootPath(driveLetter.Value) : null,
                            FileSystemFormat = FileSystemFormat.FromString((string)result.GetPropertyValue("FileSystem")),
            };

            Log.Debug("Obtained {Volume}", vol);

            return(vol);
        }
コード例 #2
0
ファイル: Partition.cs プロジェクト: zhyfeather/WOA-Deployer
        public async Task RemoveDriveLetter()
        {
            var part = await this.GetPsPartition();

            await PowerShellMixin.ExecuteCommand("Remove-PartitionAccessPath",
                                                 ("InputObject", part),
                                                 ("AccessPath", Root)
                                                 );
        }
コード例 #3
0
        public async Task Format(FileSystemFormat fileSystemFormat, string label)
        {
            var part = await this.Partition.GetPsPartition();

            await PowerShellMixin.ExecuteCommand("Format-Volume",
                                                 ("Partition", part),
                                                 ("Force", null),
                                                 ("Confirm", false),
                                                 ("FileSystem", fileSystemFormat.Moniker),
                                                 ("NewFileSystemLabel", label)
                                                 );
        }
コード例 #4
0
ファイル: Partition.cs プロジェクト: zhyfeather/WOA-Deployer
        public async Task <char> AssignDriveLetter()
        {
            var part = await this.GetPsPartition();

            var letter = GetFreeDriveLetter();
            await PowerShellMixin.ExecuteCommand("Set-Partition",
                                                 ("InputObject", part),
                                                 ("NewDriveLetter", letter)
                                                 );

            Root = PathExtensions.GetRootPath(letter);

            return(letter);
        }
コード例 #5
0
ファイル: Partition.cs プロジェクト: zhyfeather/WOA-Deployer
        public async Task Resize(ByteSize size)
        {
            if (size.MegaBytes < 0)
            {
                throw new InvalidOperationException($"The partition size cannot be negative: {size}");
            }

            var sizeBytes = (ulong)size.Bytes;

            Log.Verbose("Resizing partition {Partition} to {Size}", this, size);

            var psPart = await this.GetPsPartition();

            await PowerShellMixin.ExecuteCommand("Resize-Partition", ("InputObject", psPart), ("Size", sizeBytes));
        }
コード例 #6
0
ファイル: Partition.cs プロジェクト: zhyfeather/WOA-Deployer
        public async Task SetGptType(GptType gptType)
        {
            Log.Verbose("Setting new GPT partition type {Type} to {Partition}", gptType, this);

            if (Equals(GptType, gptType))
            {
                return;
            }

            var part = await this.GetPsPartition();

            await PowerShellMixin.ExecuteCommand("Set-Partition",
                                                 ("InputObject", part),
                                                 ("GptType", $"{{{gptType.Guid}}}")
                                                 );

            await Disk.Refresh();

            Log.Verbose("New GPT type set correctly", gptType, this);
        }
コード例 #7
0
ファイル: Partition.cs プロジェクト: zhyfeather/WOA-Deployer
        public async Task Remove()
        {
            var part = await this.GetPsPartition();

            await PowerShellMixin.ExecuteCommand("Remove-Partition", ("InputObject", part), ("Confirm", false));
        }
コード例 #8
0
 public async Task ToggleOnline(bool isOnline)
 {
     await PowerShellMixin.ExecuteCommand("Set-Disk",
                                          ("Number", Number),
                                          ("IsOffline", !isOnline));
 }