private async Task <bool> ProcessLeafAsync(CatalogLeafItem leafItem, CancellationToken cancellationToken) { bool success; try { await _throttle.WaitAsync(cancellationToken); if (cancellationToken.IsCancellationRequested) { return(false); } switch (leafItem.Type) { case CatalogLeafType.PackageDelete: var packageDelete = await _client.GetPackageDeleteLeafAsync(leafItem.Url); success = await _leafProcessor.ProcessPackageDeleteAsync(packageDelete); break; case CatalogLeafType.PackageDetails: var packageDetails = await _client.GetPackageDetailsLeafAsync(leafItem.Url); success = await _leafProcessor.ProcessPackageDetailsAsync(packageDetails); break; default: throw new NotSupportedException($"The catalog leaf type '{leafItem.Type}' is not supported."); } } catch (Exception exception) { _logger.LogError( 0, exception, "An exception was thrown while processing leaf {leafUrl}.", leafItem.Url); success = false; } finally { _throttle.Release(); } if (!success) { _logger.LogWarning( "Failed to process leaf {leafUrl} ({packageId} {packageVersion}, {leafType}).", leafItem.Url, leafItem.PackageId, leafItem.PackageVersion, leafItem.Type); } return(success); }
private async Task ProcessPackageDetailsAsync( CatalogLeafItem catalogLeafItem, CancellationToken cancellationToken) { var catalogClient = _clientFactory.CreateCatalogClient(); var catalogLeaf = await catalogClient.GetPackageDetailsLeafAsync(catalogLeafItem.CatalogLeafUrl, cancellationToken); await IndexPackageAsync(catalogLeaf, cancellationToken); }
private Message ToMessage(CatalogLeafItem catalogLeafItem) { using (var stream = new MemoryStream()) { using (var writer = new StreamWriter(stream)) { _serializer.Serialize(writer, catalogLeafItem); } return(new Message { Body = stream.ToArray(), Label = "catalog-leaf", ContentType = "application/json;charset=unicode", }); } }
private async Task <bool> ProcessLeafAsync(CatalogLeafItem leafItem, CancellationToken cancellationToken) { bool success; try { if (leafItem.IsPackageDelete()) { var packageDelete = await _client.GetPackageDeleteLeafAsync(leafItem.CatalogLeafUrl); success = await _leafProcessor.ProcessPackageDeleteAsync(packageDelete, cancellationToken); } else if (leafItem.IsPackageDetails()) { var packageDetails = await _client.GetPackageDetailsLeafAsync(leafItem.CatalogLeafUrl); success = await _leafProcessor.ProcessPackageDetailsAsync(packageDetails, cancellationToken); } else { throw new NotSupportedException($"The catalog leaf type '{leafItem.Type}' is not supported."); } } catch (Exception exception) { _logger.LogError( 0, exception, "An exception was thrown while processing leaf {leafUrl}.", leafItem.CatalogLeafUrl); success = false; } if (!success) { _logger.LogWarning( "Failed to process leaf {leafUrl} ({packageId} {packageVersion}, {leafType}).", leafItem.CatalogLeafUrl, leafItem.PackageId, leafItem.PackageVersion, leafItem.Type); } return(success); }
public async Task ProcessAsync(CatalogLeafItem catalogLeafItem, CancellationToken cancellationToken = default) { _logger.LogInformation("Processing catalog leaf {CatalogLeafUrl}", catalogLeafItem.CatalogLeafUrl); switch (catalogLeafItem.Type) { case CatalogLeafType.PackageDetails: await ProcessPackageDetailsAsync(catalogLeafItem, cancellationToken); break; case CatalogLeafType.PackageDelete: await ProcessPackageDeleteAsync(catalogLeafItem, cancellationToken); break; default: throw new NotSupportedException($"Unknown catalog leaf type '{catalogLeafItem.Type}'"); } _logger.LogInformation("Processed catalog leaf {CatalogLeafUrl}", catalogLeafItem.CatalogLeafUrl); }
/// <summary> /// Determines if the provided catalog leaf is contains package details. /// </summary> /// <param name="leaf">The catalog leaf.</param> /// <returns>True if the catalog leaf contains package details.</returns> public static bool IsPackageDetails(this CatalogLeafItem leaf) { return(leaf.Type == "nuget:PackageDetails"); }
private async Task ProcessPackageDeleteAsync( CatalogLeafItem catalogLeafItem, CancellationToken cancellationToken) { await _packages.UnlistPackageAsync(catalogLeafItem.PackageId, catalogLeafItem.ParsePackageVersion()); }