Example #1
0
        public override async Task <SourcePackageDependencyInfo> ResolvePackage(
            PackageIdentity package,
            NuGetFramework projectFramework,
            ILogger log,
            CancellationToken token)
        {
            token.ThrowIfCancellationRequested();
            try
            {
                var packageInfo = await _feedParser.GetPackage(package, log, token);

                if (packageInfo == null)
                {
                    return(null);
                }
                return(CreateDependencyInfo(packageInfo, projectFramework));
            }
            catch (Exception ex)
            {
                // Wrap exceptions coming from the server with a user friendly message
                var error = String.Format(CultureInfo.CurrentUICulture, Strings.Protocol_PackageMetadataError, package, _source);

                throw new FatalProtocolException(error, ex);
            }
        }
Example #2
0
        public override async Task <IPackageSearchMetadata> GetMetadataAsync(
            PackageIdentity package,
            Common.ILogger log,
            CancellationToken token)
        {
            var v2Package = await _feedParser.GetPackage(package, log, token);

            if (v2Package != null)
            {
                return(new PackageSearchMetadataV2Feed(v2Package));
            }
            return(null);
        }
        public override async Task <bool> Exists(PackageIdentity identity, bool includeUnlisted, ILogger log, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            try
            {
                var package = await _feedParser.GetPackage(identity, log, token);

                return(package != null);
            }
            catch (Exception ex)
            {
                throw new FatalProtocolException(string.Format(CultureInfo.CurrentCulture, Strings.Protocol_PackageMetadataError, identity, _source), ex);
            }
        }
        public override async Task <IPackageSearchMetadata> GetMetadataAsync(
            PackageIdentity package,
            SourceCacheContext sourceCacheContext,
            Common.ILogger log,
            CancellationToken token)
        {
            var v2Package = await _feedParser.GetPackage(package, sourceCacheContext, log, token);

            if (v2Package != null)
            {
                var metadataCache = new MetadataReferenceCache();
                var filter        = new SearchFilter(v2Package.Version.IsPrerelease);
                filter.IncludeDelisted = !v2Package.IsListed;

                return(V2FeedUtilities.CreatePackageSearchResult(v2Package, metadataCache, filter, _feedParser, log, token));
            }
            return(null);
        }
        public override async Task <DownloadResourceResult> GetDownloadResourceResultAsync(
            PackageIdentity identity,
            ISettings settings,
            ILogger logger,
            CancellationToken token)
        {
            if (identity == null)
            {
                throw new ArgumentNullException(nameof(identity));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            token.ThrowIfCancellationRequested();

            var  sourcePackage = identity as SourcePackageDependencyInfo;
            bool isFromUri     = sourcePackage?.PackageHash != null &&
                                 sourcePackage?.DownloadUri != null;

            Uri sourceUri;

            if (isFromUri)
            {
                sourceUri = sourcePackage.DownloadUri;
            }
            else
            {
                V2FeedPackageInfo packageInfo = await _parser.GetPackage(identity, logger, token);

                if (packageInfo == null)
                {
                    return(new DownloadResourceResult(DownloadResourceResultStatus.NotFound));
                }

                sourceUri = new Uri(packageInfo.DownloadUrl);
            }

            try
            {
                return(await GetDownloadResultUtilityPrivate.GetDownloadResultAsync(_source, sourcePackage, sourceUri, settings, logger, token));
            }
            catch (OperationCanceledException)
            {
                return(new DownloadResourceResult(DownloadResourceResultStatus.Cancelled));
            }
            catch (Exception ex) when(!(ex is FatalProtocolException))
            {
                // if the expcetion is not FatalProtocolException, catch it.
                string message = string.Format(CultureInfo.CurrentCulture, "Error downloading '{0}' from '{1}'.", identity, sourceUri);

                logger.LogError(message + Environment.NewLine + ExceptionUtilities.DisplayMessage(ex));

                throw new FatalProtocolException(message, ex);
            }
        }