// ReSharper disable once UnusedParameter.Local private async Task <IList <AppxVolume> > GetVolumes(GetVolumesCommand command, CancellationToken cancellationToken, IProgress <ProgressData> progressData) { var manager = await this.volumeManagerProvider.GetProxyFor(SelfElevationLevel.AsInvoker, cancellationToken).ConfigureAwait(false); var selected = this.ApplicationState.Volumes.SelectedVolumes.Select(p => p.PackageStorePath).ToArray(); var results = await manager.GetAll(cancellationToken, progressData).ConfigureAwait(false); var defaultVol = await manager.GetDefault(cancellationToken).ConfigureAwait(false); var findMe = defaultVol == null ? null : results.FirstOrDefault(d => d.PackageStorePath == defaultVol.PackageStorePath); if (findMe != null) { findMe.IsDefault = true; } this.ApplicationState.Volumes.AllVolumes.Clear(); this.ApplicationState.Volumes.AllVolumes.AddRange(results); if (selected.Any()) { await this.Invoke(this, new SelectVolumesCommand(selected), cancellationToken).ConfigureAwait(false); } else { await this.Invoke(this, new SelectVolumesCommand(new string[0]), cancellationToken).ConfigureAwait(false); } return(results); }
public async Task <IList <AppxVolume> > Handle(GetVolumesCommand request, CancellationToken cancellationToken) { var context = this.busyManager.Begin(OperationType.VolumeLoading); try { var manager = await this.volumeManagerProvider.GetProxyFor(SelfElevationLevel.AsInvoker, cancellationToken).ConfigureAwait(false); var selected = this.commandExecutor.ApplicationState.Volumes.SelectedVolumes.Select(p => p.PackageStorePath).ToArray(); var results = await manager.GetAll(cancellationToken, context).ConfigureAwait(false); var defaultVol = await manager.GetDefault(cancellationToken).ConfigureAwait(false); var findMe = defaultVol == null ? null : results.FirstOrDefault(d => d.PackageStorePath == defaultVol.PackageStorePath); if (findMe != null) { findMe.IsDefault = true; } this.commandExecutor.ApplicationState.Volumes.AllVolumes.Clear(); this.commandExecutor.ApplicationState.Volumes.AllVolumes.AddRange(results); if (selected.Any()) { await this.commandExecutor.Invoke(this, new SelectVolumesCommand(selected), cancellationToken).ConfigureAwait(false); } else { await this.commandExecutor.Invoke(this, new SelectVolumesCommand(Array.Empty <string>()), cancellationToken).ConfigureAwait(false); } return(results); } finally { this.busyManager.End(context); } }