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); }
private async Task <Volume> GetVolumeCore(Partition partition) { Log.Debug("Getting volume of {Partition}", partition); var results = await ps.ExecuteCommand("Get-Volume", ("Partition", await GetPsPartition(partition))); var result = results.FirstOrDefault()?.ImmediateBaseObject; if (result == null) { throw new ApplicationException($"Cannot get volume for {partition}"); } var vol = new Volume(partition) { Partition = partition, Size = new ByteSize(Convert.ToUInt64(result.GetPropertyValue("Size"))), Label = (string)result.GetPropertyValue("FileSystemLabel"), Letter = (char?)result.GetPropertyValue("DriveLetter"), FileSytemFormat = FileSystemFormat.FromString((string)result.GetPropertyValue("FileSystem")), }; Log.Debug("Obtained {Volume}", vol); return(vol); }
private static async Task EnsureFormatted(Partition partition, string label, FileSystemFormat fileSystemFormat) { var volume = await partition.GetVolume(); if (volume == null) { throw new ApplicationException($"Couldn't get volume for {partition}"); } await volume.Mount(); if (Directory.EnumerateFileSystemEntries(volume.Root).Count() > 1) { throw new ApplicationException("The format operation failed. The drive shouldn't contain any file after the format"); } var sameLabel = string.Equals(volume.Label, label); var sameFileSystemFormat = Equals(volume.FileSytemFormat, fileSystemFormat); if (!sameLabel || !sameFileSystemFormat) { Log.Verbose("Same label? {Value}. Same file system format? {Value}", sameLabel, sameFileSystemFormat); throw new ApplicationException("The format operation failed"); } }
public Task Format(Volume volume, FileSystemFormat fileSystemFormat, string fileSystemLabel) { ps.Commands.Clear(); var cmd = $@"Get-Partition -UniqueId ""{volume.Partition.Id}"" | Get-Volume | Format-Volume -FileSystem {fileSystemFormat.Moniker} -NewFileSystemLabel ""{fileSystemLabel}"" -Force -Confirm:$false"; ps.AddScript(cmd); return(Task.Factory.FromAsync(ps.BeginInvoke(), x => ps.EndInvoke(x))); }
private async Task Format(string partitionName, FileSystemFormat fileSystemFormat, string label) { var part = await disk.GetPartitionByName(partitionName); await part.EnsureWritable(); var vol = await part.GetVolume(); await vol.Format(fileSystemFormat, label); }
public async Task Execute(string partitionDescriptor, string fileSystemFormat, string label = null) { var part = await fileSystem.GetPartitionFromDescriptor(partitionDescriptor); await part.EnsureWritable(); var vol = await part.GetVolume(); var systemFormat = FileSystemFormat.FromString(fileSystemFormat); await vol.Format(systemFormat, label); }
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) ); }
private async Task FormatCore(Partition partition, FileSystemFormat fileSystemFormat, string label = null) { label = label ?? partition.Name ?? ""; Log.Verbose(@"Formatting {Partition} as {Format} labeled as ""{Label}""", partition, fileSystemFormat, label); var part = await GetPsPartition(partition); await ps.ExecuteCommand("Format-Volume", ("Partition", part), ("Force", null), ("Confirm", false), ("FileSystem", fileSystemFormat.Moniker), ("NewFileSystemLabel", label) ); await EnsureFormatted(partition, label, fileSystemFormat); }
public static void FromString(this FileSystemFormat format, string str) { EnumFromString(format, str); }
public static string ToString(this FileSystemFormat format) { return(EnumToString(format)); }
public Task Format(FileSystemFormat fileSystemFormat, string label) { throw new NotImplementedException(); }
public async Task Format(Partition partition, FileSystemFormat fileSystemFormat, string label = null) { await Observable.FromAsync(() => FormatCore(partition, fileSystemFormat, label)).RetryWithBackoffStrategy(4); }
public Task Format(Volume volume, FileSystemFormat ntfs, string fileSystemLabel) { throw new NotImplementedException(); }