Ejemplo n.º 1
0
        private async Task IndexFromSourceAsync(Uri packageUri, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            _logger.LogInformation("Attempting to mirror package {PackageUri}...", packageUri);

            try
            {
                using (var stream = await _downloader.DownloadOrNullAsync(packageUri, cancellationToken))
                {
                    if (stream == null)
                    {
                        _logger.LogWarning(
                            "Failed to download package at {PackageUri}",
                            packageUri);

                        return;
                    }

                    _logger.LogInformation("Downloaded package at {PackageUri}, indexing...", packageUri);

                    var result = await _indexer.IndexAsync(stream, cancellationToken);

                    _logger.LogInformation(
                        "Finished indexing package at {PackageUri} with result {Result}",
                        packageUri,
                        result);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to mirror package at {PackageUri}", packageUri);
            }
        }
Ejemplo n.º 2
0
        private async Task IndexFromSourceAsync(string id, NuGetVersion version, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            _logger.LogInformation(
                "Attempting to mirror package {PackageId} {PackageVersion}...",
                id,
                version);

            try
            {
                var packageUri = await _upstreamFeed.GetPackageContentUriAsync(id, version);

                using (var stream = await _downloader.DownloadOrNullAsync(packageUri, cancellationToken))
                {
                    if (stream == null)
                    {
                        _logger.LogWarning(
                            "Failed to download package {PackageId} {PackageVersion}",
                            id,
                            version);

                        return;
                    }

                    _logger.LogInformation(
                        "Downloaded package {PackageId} {PackageVersion}, indexing...",
                        id,
                        version);

                    var result = await _indexer.IndexAsync(stream, cancellationToken);

                    _logger.LogInformation(
                        "Finished indexing package {PackageId} {PackageVersion} with result {Result}",
                        packageUri,
                        result);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(
                    e,
                    "Failed to mirror package {PackageId} {PackageVersion}",
                    id,
                    version);
            }
        }
Ejemplo n.º 3
0
        private async Task IndexFromSourceAsync(PackageIdentity pid, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            string id      = pid.Id.ToLowerInvariant();
            string version = pid.Version.ToNormalizedString().ToLowerInvariant();

            _logger.LogInformation("Attempting to mirror package {Id} {Version}...", id, version);

            try
            {
                Uri packageUri = await _sourceRepository.GetPackageUriAsync(id, version, cancellationToken);

                using (var stream = await _downloader.DownloadOrNullAsync(packageUri, cancellationToken))
                {
                    if (stream == null)
                    {
                        _logger.LogWarning(
                            "Failed to download package {Id} {Version} at {PackageUri}",
                            id,
                            version,
                            packageUri);

                        return;
                    }

                    _logger.LogInformation("Downloaded package {Id} {Version}, adding to cache...", id, version);

                    await _localPackages.AddPackageAsync(stream);

                    _logger.LogInformation(
                        "Finished adding package {Id} {Version}",
                        id,
                        version);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to mirror package {Id} {Version}", id, version);
            }
            finally {
                lock (_startLock) {
                    _downloads.Remove(pid);
                }
            }
        }
        public static async Task Run(
            [ServiceBusTrigger("index", Connection = "ServiceBusConnectionString")]
            byte[] packageUrl,
            [Inject] IPackageDownloader downloader,
            [Inject] IPackageIndexingService indexer,
            ILogger log,
            CancellationToken cancellationToken)
        {
            var packageUri = new Uri(Encoding.Unicode.GetString(packageUrl));

            using (var packageStream = await downloader.DownloadOrNullAsync(packageUri, cancellationToken))
            {
                if (packageStream == null)
                {
                    log.LogError("Could not find package at url {PackageUrl}", packageUri);
                    return;
                }

                await indexer.IndexAsync(packageStream, cancellationToken);
            }
        }
Ejemplo n.º 5
0
        private async Task IndexFromSourceAsync(string id, string version, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            _logger.LogInformation("Attempting to mirror package {Id} {Version}...", id, version);

            try
            {
                // See https://github.com/NuGet/NuGet.Client/blob/4eed67e7e159796ae486d2cca406b283e23b6ac8/src/NuGet.Core/NuGet.Protocol/Resources/DownloadResourceV3.cs#L82
                var packageUri = new Uri(_packageBaseAddress, $"{id}/{version}/{id}.{version}.nupkg");

                using (var stream = await _downloader.DownloadOrNullAsync(packageUri, cancellationToken))
                {
                    if (stream == null)
                    {
                        _logger.LogWarning(
                            "Failed to download package {Id} {Version} at {PackageUri}",
                            id,
                            version,
                            packageUri);

                        return;
                    }

                    _logger.LogInformation("Downloaded package {Id} {Version}, indexing...", id, version);

                    var result = await _indexer.IndexAsync(stream, cancellationToken);

                    _logger.LogInformation(
                        "Finished indexing package {Id} {Version} with result {Result}",
                        id,
                        version,
                        result);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Failed to mirror package {Id} {Version}", id, version);
            }
        }