in src/PortingAssistant.Client.NuGet/Checkers/PortabilityAnalyzerCompatibilityChecker.cs [125:193]
private async void ProcessCompatibility(IEnumerable<PackageVersionPair> packageVersions,
Dictionary<string, List<PackageVersionPair>> foundPackages,
Dictionary<PackageVersionPair, TaskCompletionSource<PackageDetails>> compatibilityTaskCompletionSources)
{
var packageVersionsFound = new HashSet<PackageVersionPair>();
var packageVersionsWithErrors = new HashSet<PackageVersionPair>();
foreach (var url in foundPackages)
{
try
{
_logger.LogInformation("Downloading {0} from {1}", url.Key, CompatibilityCheckerType);
using var stream = await _httpService.DownloadS3FileAsync(url.Key);
using var gzipStream = new GZipStream(stream, CompressionMode.Decompress);
using var streamReader = new StreamReader(gzipStream);
var packageFromS3 = JsonConvert.DeserializeObject<PackageFromS3>(streamReader.ReadToEnd());
packageFromS3.Package.Name = url.Value.First().PackageId;
foreach (var packageVersion in url.Value)
{
if (compatibilityTaskCompletionSources.TryGetValue(packageVersion, out var taskCompletionSource))
{
taskCompletionSource.SetResult(packageFromS3.Package);
packageVersionsFound.Add(packageVersion);
}
}
}
catch (Exception ex)
{
if (ex.Message.Contains("404"))
{
_logger.LogInformation($"Encountered {ex.GetType()} while downloading and parsing {url.Key} " +
$"from {CompatibilityCheckerType}, but it was ignored. " +
$"ErrorMessage: {ex.Message}.");
// filter all 404 errors
ex = null;
}
else
{
_logger.LogError("Failed when downloading and parsing {0} from {1}, {2}", url.Key, CompatibilityCheckerType, ex);
}
foreach (var packageVersion in url.Value)
{
if (compatibilityTaskCompletionSources.TryGetValue(packageVersion, out var taskCompletionSource))
{
taskCompletionSource.SetException(new PortingAssistantClientException(ExceptionMessage.PackageNotFound(packageVersion), ex));
packageVersionsWithErrors.Add(packageVersion);
}
}
}
}
foreach (var packageVersion in packageVersions)
{
if (packageVersionsFound.Contains(packageVersion) || packageVersionsWithErrors.Contains(packageVersion))
{
continue;
}
if (compatibilityTaskCompletionSources.TryGetValue(packageVersion, out var taskCompletionSource))
{
var errorMessage = $"Could not find package {packageVersion} in external source; try checking an internal source.";
_logger.LogInformation(errorMessage);
var innerException = new PackageNotFoundException(errorMessage);
taskCompletionSource.TrySetException(new PortingAssistantClientException(ExceptionMessage.PackageNotFound(packageVersion), innerException));
}
}
}