コード例 #1
0
ファイル: MetadataResourceV2.cs プロジェクト: anthrax3/NuGet3
        public override async Task <IEnumerable <NuGetVersion> > GetVersions(string packageId, bool includePrerelease, bool includeUnlisted, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            return(await Task.Run(() =>
                                  // year check workaround for p.Listed showing as False for online packages
                                  V2Client.FindPackagesById(packageId).Where(p => includeUnlisted || !p.Published.HasValue || p.Published.Value.Year > 1901)
                                  .Select(p => V2Utilities.SafeToNuGetVer(p.Version))
                                  .Where(v => includePrerelease || !v.IsPrerelease).ToArray()));
        }
コード例 #2
0
        // TODO: clean up
        public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token)
        {
            PackageRepositoryResourceV2 repoResource = null;

            if (!_cache.TryGetValue(source.PackageSource, out repoResource))
            {
                IPackageRepository repo = null;

                // check if the source passed in contains the repository
                V2PackageSource v2Source = source.PackageSource as V2PackageSource;

                if (v2Source != null)
                {
                    // special case for some of the remaining legacy areas
                    repo = v2Source.CreatePackageRepository();
                }
                else
                {
                    try
                    {
                        // if it's not in cache, then check if it is V2.
                        if (await V2Utilities.IsV2(source.PackageSource))
                        {
                            // Get a IPackageRepo object and add it to the cache.
                            repo = V2Utilities.GetV2SourceRepository(source.PackageSource);
                            HttpClient.DefaultCredentialProvider = new SettingsCredentialProvider(source.PackageSource);
                        }
                    }
                    catch (Exception)
                    {
                        // *TODOs:Do tracing and throw apppropriate exception here.
                        repoResource = null;

                        // For package source that uses relative path, it will throw UriFormat exception and go here.
                        // Comment out Debug.Fail so that functional tests using relative path won't be blocked by the Assertion window.
                        //Debug.Fail("Unable to create V2 repository on: " + source.PackageSource.Source);
                    }
                }

                if (repo != null)
                {
                    repoResource = new PackageRepositoryResourceV2(repo);
                    _cache.TryAdd(source.PackageSource, repoResource);
                }
            }

            return(Tuple.Create <bool, INuGetResource>(repoResource != null, repoResource));
        }
コード例 #3
0
        public override async Task <IEnumerable <NuGetVersion> > GetVersions(string packageId, bool includePrerelease, bool includeUnlisted, Common.ILogger log, CancellationToken token)
        {
            token.ThrowIfCancellationRequested();

            try
            {
                return(await Task.Run(() =>
                                      // year check workaround for p.Listed showing as False for online packages
                                      V2Client.FindPackagesById(packageId).Where(p => includeUnlisted || !p.Published.HasValue || p.Published.Value.Year > 1901)
                                      .Select(p => V2Utilities.SafeToNuGetVer(p.Version))
                                      .Where(v => includePrerelease || !v.IsPrerelease).ToArray()));
            }
            catch (Exception ex)
            {
                throw new FatalProtocolException(string.Format(CultureInfo.CurrentCulture,
                                                               Strings.Protocol_PackageMetadataError,
                                                               packageId,
                                                               V2Client.Source),
                                                 ex);
            }
        }
コード例 #4
0
        private SimpleSearchMetadata CreatePackageSearchResult(IPackage package)
        {
            var versions = V2Client.FindPackagesById(package.Id);

            if (!versions.Any())
            {
                versions = new[] { package };
            }
            var id            = package.Id;
            var version       = V2Utilities.SafeToNuGetVer(package.Version);
            var summary       = package.Summary;
            var nuGetVersions = versions.Select(p => V2Utilities.SafeToNuGetVer(p.Version));

            if (string.IsNullOrWhiteSpace(summary))
            {
                summary = package.Description;
            }

            var iconUrl        = package.IconUrl;
            var identity       = new PackageIdentity(id, version);
            var searchMetaData = new SimpleSearchMetadata(identity, summary, nuGetVersions);

            return(searchMetaData);
        }