private async Task OnInstallPackageExecuteAsync() { try { _progressManager.ShowBar(this); using (var cts = new CancellationTokenSource()) { if (IsInstalled()) { var updatePackageDetails = PackageDetailsFactory.Create(PackageOperationType.Update, VersionData, SelectedVersion, null); await _packageCommandService.ExecuteUpdateAsync(updatePackageDetails, cts.Token); } else { var installPackageDetails = PackageDetailsFactory.Create(PackageOperationType.Install, VersionData, SelectedPackage, null); await _packageCommandService.ExecuteInstallAsync(installPackageDetails, cts.Token); } } await Task.Delay(200); } catch (Exception ex) { Log.Error(ex, $"Error when installing package {Package.Identity}, installation failed"); } finally { _progressManager.HideBar(this); } }
private async Task BatchInstallExecuteAsync() { try { _progressManager.ShowBar(this); var batchedPackages = _parentManagerPage.PackageItems.Where(x => x.IsChecked).ToList(); if (batchedPackages.Any(x => x.ValidationContext.HasErrors)) { await _messageService.ShowErrorAsync("Can't perform install. One or multiple package cannot be installed due to validation errors", "Can't install packages"); return; } using (var cts = new CancellationTokenSource()) { var installPackageList = new List <IPackageDetails>(); foreach (var package in batchedPackages) { var targetVersion = (await package.LoadVersionsAsync() ?? package.Versions)?.OrderByDescending(x => x).FirstOrDefault(); var installPackageDetails = PackageDetailsFactory.Create(PackageOperationType.Install, package.GetMetadata(), targetVersion, null); installPackageList.Add(installPackageDetails); } using (var operationContext = _packageOperationContextService.UseOperationContext(PackageOperationType.Install, installPackageList.ToArray())) { foreach (var packageDetails in installPackageList) { await _packageCommandService.ExecuteInstallAsync(packageDetails, operationContext, cts.Token); } } } await Task.Delay(200); } catch (Exception ex) { Log.Error(ex, $"Error when updating package"); } finally { _progressManager.HideBar(this); _parentManagerPage.StartLoadingTimerOrInvalidateData(); } }