Esempio n. 1
0
        public override Task <JObject> GetPackageMetadata(string id, Versioning.NuGetVersion version)
        {
            return(Task.Factory.StartNew(() =>
            {
                NuGetTraceSources.V2SourceRepository.Verbose("getpackage", "Getting metadata for {0} {1}", id, version);
                var semver = CoreConverters.SafeToSemanticVersion(version);
                var package = _repository.FindPackage(id, semver);

                // Sometimes, V2 APIs seem to fail to return a value for Packages(Id=,Version=) requests...
                if (package == null)
                {
                    var packages = _repository.FindPackagesById(id);
                    package = packages.FirstOrDefault(p => Equals(p.Version, semver));
                }

                // If still null, fail
                if (package == null)
                {
                    return null;
                }

                string repoRoot = null;
                IPackagePathResolver resolver = null;
                if (_lprepo != null)
                {
                    repoRoot = _lprepo.Source;
                    resolver = _lprepo.PathResolver;
                }

                return PackageJsonLd.CreatePackage(package, repoRoot, resolver);
            }));
        }
Esempio n. 2
0
        private JObject CreatePackageSearchResult(IPackage package, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            NuGetTraceSources.V2SourceRepository.Verbose("getallvers", "Retrieving all versions for {0}", package.Id);
            var versions = _repository.FindPackagesById(package.Id);

            if (!versions.Any())
            {
                versions = new[] { package };
            }

            return(PackageJsonLd.CreatePackageSearchResult(package, versions.Select(p => p.Version)));
        }
Esempio n. 3
0
 public override Task <IEnumerable <JObject> > GetPackageMetadataById(string packageId)
 {
     return(Task.Factory.StartNew(() =>
     {
         NuGetTraceSources.V2SourceRepository.Verbose("findpackagebyid", "Getting metadata for all versions of {0}", packageId);
         string repoRoot = null;
         IPackagePathResolver resolver = null;
         if (_lprepo != null)
         {
             repoRoot = _lprepo.Source;
             resolver = _lprepo.PathResolver;
         }
         return _repository.FindPackagesById(packageId).Select(p => PackageJsonLd.CreatePackage(p, repoRoot, resolver));
     }));
 }