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 BatchUpdateExecuteAsync() { 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 update. One or multiple package cannot be updated due to validation errors", "Can't update packages"); return; } var projects = _projectLocator.GetAllExtensibleProjects() .Where(x => _projectLocator.IsEnabled(x)).ToList(); using (var cts = new CancellationTokenSource()) { var updatePackageList = new List <IPackageDetails>(); foreach (var package in batchedPackages) { var targetProjects = new List <IExtensibleProject>(); foreach (var project in projects) { if (!await _projectManager.IsPackageInstalledAsync(project, package.Identity, cts.Token)) { targetProjects.Add(project); } } var targetVersion = (await package.LoadVersionsAsync() ?? package.Versions)?.FirstOrDefault(); if (targetVersion is null) { Log.Warning("Cannot perform upgrade because of 'Target version' is null"); return; } var updatePackageDetails = PackageDetailsFactory.Create(PackageOperationType.Update, package.GetMetadata(), targetVersion, null); updatePackageList.Add(updatePackageDetails); } using (var operationContext = _packageOperationContextService.UseOperationContext(PackageOperationType.Update, updatePackageList.ToArray())) { foreach (var updatePackageDetails in updatePackageList) { await _packageCommandService.ExecuteUpdateAsync(updatePackageDetails, operationContext, cts.Token); } } } await Task.Delay(200); } catch (Exception ex) { Log.Error(ex, $"Error when updating package"); } finally { _progressManager.HideBar(this); _parentManagerPage.StartLoadingTimerOrInvalidateData(); } }