public async Task <IReadOnlyList <CheckUpdateResult> > GetLatestVersionAsync(IEnumerable <IManagedTemplatePackage> packages, IManagedTemplatePackageProvider provider, CancellationToken cancellationToken) { _ = packages ?? throw new ArgumentNullException(nameof(packages)); return(await Task.WhenAll(packages.Select(async package => { if (package is NuGetManagedTemplatePackage nugetPackage) { try { (string latestVersion, bool isLatestVersion) = await _updateChecker.GetLatestVersionAsync(nugetPackage.Identifier, nugetPackage.Version, nugetPackage.NuGetSource, cancellationToken).ConfigureAwait(false); return CheckUpdateResult.CreateSuccess(package, latestVersion, isLatestVersion); } catch (PackageNotFoundException e) { return CheckUpdateResult.CreateFailure( package, InstallerErrorCode.PackageNotFound, string.Format(LocalizableStrings.NuGetInstaller_Error_FailedToReadPackage, e.PackageIdentifier, string.Join(", ", e.SourcesList))); } catch (InvalidNuGetSourceException e) { string message = e.SourcesList == null || !e.SourcesList.Any() ? LocalizableStrings.NuGetInstaller_InstallResut_Error_InvalidSources_None : string.Format(LocalizableStrings.NuGetInstaller_InstallResut_Error_InvalidSources, string.Join(", ", e.SourcesList)); return CheckUpdateResult.CreateFailure( package, InstallerErrorCode.InvalidSource, message); } catch (OperationCanceledException) { return CheckUpdateResult.CreateFailure( package, InstallerErrorCode.GenericError, LocalizableStrings.NuGetInstaller_InstallResut_Error_OperationCancelled); } catch (Exception e) { _logger.LogDebug($"Retrieving latest version for package {package.DisplayName} failed. Details: {e}."); return CheckUpdateResult.CreateFailure( package, InstallerErrorCode.GenericError, string.Format(LocalizableStrings.NuGetInstaller_InstallResut_Error_UpdateCheckGeneric, package.DisplayName, e.Message)); } } else { return CheckUpdateResult.CreateFailure( package, InstallerErrorCode.UnsupportedRequest, string.Format(LocalizableStrings.NuGetInstaller_InstallResut_Error_PackageNotSupported, package.DisplayName, Factory.Name)); } })).ConfigureAwait(false)); }
public async Task <IReadOnlyList <CheckUpdateResult> > GetLatestVersionAsync(IEnumerable <IManagedTemplatePackage> packages, IManagedTemplatePackageProvider provider, CancellationToken cancellationToken) { _ = packages ?? throw new ArgumentNullException(nameof(packages)); return(await Task.WhenAll(packages.Select(async package => { if (package is NuGetManagedTemplatePackage nugetPackage) { try { (string latestVersion, bool isLatestVersion) = await _updateChecker.GetLatestVersionAsync(nugetPackage.Identifier, nugetPackage.Version, nugetPackage.NuGetSource, cancellationToken).ConfigureAwait(false); return CheckUpdateResult.CreateSuccess(package, latestVersion, isLatestVersion); } catch (PackageNotFoundException e) { return CheckUpdateResult.CreateFailure(package, InstallerErrorCode.PackageNotFound, e.Message); } catch (InvalidNuGetSourceException e) { return CheckUpdateResult.CreateFailure(package, InstallerErrorCode.InvalidSource, e.Message); } catch (OperationCanceledException) { return CheckUpdateResult.CreateFailure(package, InstallerErrorCode.GenericError, "Operation canceled"); } catch (Exception e) { _environmentSettings.Host.LogDiagnosticMessage($"Retrieving latest version for package {package.DisplayName} failed.", DebugLogCategory); _environmentSettings.Host.LogDiagnosticMessage($"Details:{e}", DebugLogCategory); return CheckUpdateResult.CreateFailure(package, InstallerErrorCode.GenericError, $"Failed to check the update for the package {package.Identifier}, reason: {e.Message}"); } } else { return CheckUpdateResult.CreateFailure(package, InstallerErrorCode.UnsupportedRequest, $"package {package.Identifier} is not supported by installer {Factory.Name}"); } })).ConfigureAwait(false)); }
public Task <IReadOnlyList <CheckUpdateResult> > GetLatestVersionAsync(IEnumerable <IManagedTemplatePackage> packages, IManagedTemplatePackageProvider provider, CancellationToken cancellationToken) { _ = packages ?? throw new ArgumentNullException(nameof(packages)); return(Task.FromResult <IReadOnlyList <CheckUpdateResult> >(packages.Select(s => CheckUpdateResult.CreateSuccess(s, null, true)).ToList())); }