public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token)
        {
            DepedencyInfoResource DependencyInfoResourceV2 = null;
            var v2repo = await GetRepository(source, token);

            if (v2repo != null)
            {
                DependencyInfoResourceV2 = new DependencyInfoResourceV2(v2repo);
            }

            return(Tuple.Create <bool, INuGetResource>(DependencyInfoResourceV2 != null, DependencyInfoResourceV2));
        }
        public async Task TestDependencyInfoResourceForPackageWithAnyFramework(string SourceUrl)
        {
            SourceRepository      repo     = GetSourceRepository(SourceUrl);
            DepedencyInfoResource resource = await repo.GetResource <DepedencyInfoResource>();

            //Check if we are able to obtain a resource
            Assert.True(resource != null);
            List <PackageIdentity> packageIdentities = new List <PackageIdentity>();

            //Check the dependency tree depth for a known package. Since the same test executes for both V2 and V3 source, we cna also ensure that the pre-resolver data is same for both V2 and V3.
            packageIdentities.Add(new PackageIdentity("WebGrease", new NuGetVersion("1.6.0")));
            IEnumerable <PackageDependencyInfo> packages = await resource.ResolvePackages(packageIdentities, NuGet.Frameworks.NuGetFramework.AnyFramework, true, new CancellationToken());

            Assert.True(packages.Count() >= 16);
        }
        public override async Task <Tuple <bool, INuGetResource> > TryCreate(SourceRepository source, CancellationToken token)
        {
            DepedencyInfoResource curResource = null;

            if (await source.GetResourceAsync <ServiceIndexResourceV3>(token) != null)
            {
                var messageHandlerResource = await source.GetResourceAsync <HttpHandlerResource>(token);

                DataClient client = new DataClient(messageHandlerResource.MessageHandler);

                var regResource = await source.GetResourceAsync <RegistrationResourceV3>(token);

                // construct a new resource
                curResource = new DependencyInfoResourceV3(client, regResource);
            }

            return(new Tuple <bool, INuGetResource>(curResource != null, curResource));
        }
        public async Task TestAllResourcesForNonExistentPackage(string SourceUrl)
        {
            string           packageId = "nonexistentpackage";
            string           version   = "1.0";
            SourceRepository repo      = GetSourceRepository(SourceUrl);

            DownloadResource downloadResource = await repo.GetResource <DownloadResource>();

            Assert.True(downloadResource != null);
            Uri downloadMetadata = await downloadResource.GetDownloadUrl(new PackageIdentity(packageId, new NuGetVersion(version)));

            Assert.True(downloadMetadata == null);

            MetadataResource metadataResource = await repo.GetResource <MetadataResource>();

            Assert.True(metadataResource != null);
            NuGetVersion latestVersion = await metadataResource.GetLatestVersion(packageId, true, true, CancellationToken.None);

            Assert.True(latestVersion == null);

            UIMetadataResource uiMetadataResource = await repo.GetResource <UIMetadataResource>();

            Assert.True(uiMetadataResource != null);

            var result = await uiMetadataResource.GetMetadata(packageId, true, true, CancellationToken.None);

            Assert.False(result.Any());

            DepedencyInfoResource resource = await repo.GetResource <DepedencyInfoResource>();

            //Check if we are able to obtain a resource
            Assert.True(resource != null);
            List <PackageIdentity> packageIdentities = new List <PackageIdentity>();

            packageIdentities.Add(new PackageIdentity(packageId, new NuGetVersion(version)));
            IEnumerable <PackageDependencyInfo> packages = await resource.ResolvePackages(packageIdentities, NuGet.Frameworks.NuGetFramework.AnyFramework, true, new CancellationToken());

            Assert.True(packages == null || packages.Count() == 0);
        }
Beispiel #5
0
        /// <summary>
        /// ***NOTE: Parameters combinedResults, sourceToPackageIdsChecked may get updated before the return of this call
        /// </summary>
        private static async Task <bool> ProcessMissingPackageIds(HashSet <SourceDependencyInfo> combinedResults,
                                                                  HashSet <string> allDiscoveredIds,
                                                                  Dictionary <SourceRepository, HashSet <string> > sourceToPackageIdsChecked,
                                                                  List <Tuple <SourceRepository, DepedencyInfoResource> > dependencyResources,
                                                                  NuGetFramework targetFramework,
                                                                  ResolutionContext context,
                                                                  bool ignoreExceptions,
                                                                  CancellationToken token)
        {
            bool complete = true;

            // results need to be kept in order
            var results = new Queue <Tuple <SourceRepository, Task <IEnumerable <PackageDependencyInfo> > > >();

            // resolve further on each source
            foreach (SourceRepository source in sourceToPackageIdsChecked.Keys)
            {
                // reuse the existing resource
                // TODO: Try using the SourceRepositoryComparer and see if this works fine
                var resolverResTuple = dependencyResources.Where(e => e.Item1 == source).FirstOrDefault();
                if (resolverResTuple == null)
                {
                    continue;
                }

                DepedencyInfoResource resolverRes = resolverResTuple.Item2;

                // check each source for packages discovered on other sources if we have no checked here already
                foreach (string missingId in allDiscoveredIds.Except(sourceToPackageIdsChecked[source], StringComparer.OrdinalIgnoreCase).ToArray())
                {
                    token.ThrowIfCancellationRequested();

                    // an id was missing - we will have to loop again on all sources incase this finds new ids
                    complete = false;

                    // mark that we searched for this id here
                    sourceToPackageIdsChecked[source].Add(missingId);

                    // search on another thread, we'll retrieve the results later
                    var task = Task.Run(async() => await resolverRes.ResolvePackages(missingId, targetFramework, context.IncludePrerelease, token));

                    var data = new Tuple <SourceRepository, Task <IEnumerable <PackageDependencyInfo> > >(source, task);

                    results.Enqueue(data);
                }
            }

            // retrieve package results from the gather tasks
            // order is important here. packages from the first repository beat packages from later repositories
            while (results.Count > 0)
            {
                var data   = results.Dequeue();
                var source = data.Item1;

                var task = data.Item2;

                try
                {
                    var packages = await task;

                    ProcessResults(combinedResults, source, sourceToPackageIdsChecked[source], packages, context.IncludePrerelease);
                }
                catch (Exception ex)
                {
                    // swallow exceptions for secondary repositories
                    if (!ignoreExceptions)
                    {
                        throw;
                    }
                }
            }

            return(complete);
        }