コード例 #1
0
        public override async Task <Resource> Create(PackageSource source)
        {
            try
            {
                object repo = null;
                string host = "TestHost";

                // Check if the source is already present in the cache.
                if (!packageSourceCache.TryGetValue(source.Url, out repo))
                {
                    // if it's not in cache, then check if it is V2.
                    if (await V2Utilities.IsV2(source))
                    {
                        // Get a IPackageRepo object and add it to the cache.
                        repo = V2Utilities.GetV2SourceRepository(source, host);
                        packageSourceCache.Add(source.Url, repo);
                    }
                    else
                    {
                        // if it's not V2, returns null
                        return(null);
                    }
                }

                // Create a resource and return it.
                var resource = new V2Resource((IPackageRepository)repo, host);
                return(resource);
            }
            catch (Exception)
            {
                // *TODOs:Do tracing and throw apppropriate exception here.
                return(null);
            }
        }
コード例 #2
0
        // TODO: clean up
        public async Task <INuGetResource> Create(SourceRepository source)
        {
            V2PackageRepositoryResource 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);
                        }
                    }
                    catch (Exception)
                    {
                        // *TODOs:Do tracing and throw apppropriate exception here.
                        Debug.Fail("Unable to create V2 repository on: " + source.PackageSource.Source);
                    }
                }

                if (repo != null)
                {
                    repoResource = new V2PackageRepositoryResource(repo);
                }

                // cache regardless of if we are v2 or not
                _cache.TryAdd(source.PackageSource, repoResource);
            }

            return(repoResource);
        }
コード例 #3
0
        private SimpleSearchMetadata CreatePackageSearchResult(IPackage package)
        {
            var versions = V2Client.FindPackagesById(package.Id);

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

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

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

            return(searchMetaData);
        }