private async Task AddPackageAsync(List <IPackage> result, SourceRepository repository, IPackageSearchMetadata package, bool isPrereleaseIncluded, CancellationToken cancellationToken)
        {
            NuGetPackageFilterResult filterResult = await filter.FilterAsync(repository, package, cancellationToken);

            switch (filterResult)
            {
            case NuGetPackageFilterResult.Ok:
                log.Debug("Package added.");
                result.Add(new NuGetPackage(package, repository, contentService, versionService));
                break;

            case NuGetPackageFilterResult.NotCompatibleVersion:
                log.Debug("Loading order versions.");
                result.AddRange(
                    await versionService.GetListAsync(
                        1,
                        package,
                        repository,
                        (source, target) => source.Identity.Version != target.Identity.Version,
                        isPrereleaseIncluded,
                        cancellationToken
                        )
                    );
                break;

            default:
                log.Debug("Package skipped.");
                break;
            }
        }
Beispiel #2
0
        public async Task <NuGetPackageFilterResult> FilterAsync(SourceRepository repository, IPackageSearchMetadata package, CancellationToken cancellationToken)
        {
            if (!dependencies.Any())
            {
                return(NuGetPackageFilterResult.Ok);
            }

            DependencyInfoResource resource = await repository.GetResourceAsync <DependencyInfoResource>();

            if (resource == null)
            {
                return(NuGetPackageFilterResult.NotCompatible);
            }

            NuGetPackageFilterResult result = NuGetPackageFilterResult.Ok;

            foreach (NuGetFramework framework in frameworks)
            {
                SourcePackageDependencyInfo dependencyInfo = await resource.ResolvePackage(package.Identity, framework, new SourceCacheContext(), nuGetLogger, cancellationToken);

                if (dependencyInfo != null)
                {
                    // Dependency filtering:
                    // - When incompatible dependency version is found there is a chance that previous version has the right one.
                    // - When all dependencies are missing, don't even try previous versions.
                    foreach (var dependency in dependencies)
                    {
                        PackageDependency packageDependency = dependencyInfo.Dependencies.FirstOrDefault(p => string.Equals(p.Id, dependency.Id, StringComparison.CurrentCultureIgnoreCase));
                        if (packageDependency == null)
                        {
                            log.Info($"Package '{package.Identity}' skipped: missing dependency '{dependency.Id}'.");
                            result = NuGetPackageFilterResult.NotCompatible;
                        }

                        if (dependency.Version != null && !packageDependency.VersionRange.Satisfies(new NuGetVersion(dependency.Version)))
                        {
                            log.Info($"Package '{package.Identity}' skipped: not compatible version '{dependency.Version}' on dependency '{dependency.Id}'.");
                            return(NuGetPackageFilterResult.NotCompatibleVersion);
                        }
                    }

                    return(result);
                }
            }

            return(NuGetPackageFilterResult.NotCompatible);
        }
Beispiel #3
0
        private IPackage ProcessOlderVersion(SourceRepository repository, IPackageSearchMetadata version)
        {
            log.Debug($"Found '{version.Identity}'.");

            NuGetPackageFilterResult filterResult = filter.IsPassed(version);

            switch (filterResult)
            {
            case NuGetPackageFilterResult.Ok:
                log.Debug("Package added.");
                return(new NuGetPackage(version, repository, contentService, this));

            default:
                log.Debug("Package skipped.");
                break;
            }

            return(null);
        }
        private async Task <IPackage> ProcessOlderVersionAsync(SourceRepository repository, IPackageSearchMetadata version, CancellationToken cancellationToken)
        {
            log.Debug($"Found '{version.Identity}'.");

            NuGetPackageFilterResult filterResult = await filter.FilterAsync(repository, version, cancellationToken);

            switch (filterResult)
            {
            case NuGetPackageFilterResult.Ok:
                log.Debug("Package added.");
                return(new NuGetPackage(version, repository, contentService, this));

            default:
                log.Debug("Package skipped.");
                break;
            }

            return(null);
        }
Beispiel #5
0
        public async Task <IReadOnlyCollection <IInstalledPackage> > GetInstalledAsync(IEnumerable <IPackageSource> packageSources, CancellationToken cancellationToken)
        {
            log.Debug($"Getting list of installed packages from '{ConfigFilePath}'.");

            List <IInstalledPackage> result = new List <IInstalledPackage>();

            await ReadPackageConfig(
                async (package, context) =>
            {
                foreach (IPackageSource packageSource in packageSources)
                {
                    log.Debug($"Looking in repository '{packageSource.Uri}'.");
                    SourceRepository repository = repositoryFactory.Create(packageSource);

                    PackageMetadataResource metadataResource = await repository.GetResourceAsync <PackageMetadataResource>(cancellationToken);
                    if (metadataResource != null)
                    {
                        IPackageSearchMetadata metadata = await metadataResource.GetMetadataAsync(package.PackageIdentity, context, nuGetLog, cancellationToken);
                        if (metadata != null)
                        {
                            log.Debug($"Package '{package.PackageIdentity}' was found.");

                            NuGetPackageFilterResult filterResult = await packageFilter.FilterAsync(repository, metadata, cancellationToken);
                            result.Add(new NuGetInstalledPackage(
                                           new NuGetPackage(metadata, repository, contentService, versionService),
                                           filterResult == NuGetPackageFilterResult.Ok
                                           ));
                            break;
                        }
                    }
                }

                return(false);
            },
                cancellationToken
                );

            log.Debug($"Returning '{result.Count}' installed packages.");
            return(result);
        }
Beispiel #6
0
        public NuGetPackageFilterResult IsPassed(IPackageSearchMetadata package)
        {
            if (!dependencies.Any())
            {
                return(NuGetPackageFilterResult.Ok);
            }

            foreach (var group in package.DependencySets)
            {
                if (frameworks.Contains(group.TargetFramework))
                {
                    NuGetPackageFilterResult result = NuGetPackageFilterResult.Ok;

                    // Dependency filtering:
                    // - When incompatible dependency version is found there is a chance that previous version has the right one.
                    // - When all dependencies are missing, don't even try previous versions.
                    foreach (var dependency in dependencies)
                    {
                        PackageDependency packageDependency = group.Packages.FirstOrDefault(p => p.Id == dependency.Id);
                        if (packageDependency == null)
                        {
                            result = NuGetPackageFilterResult.NotCompatible;
                        }

                        if (dependency.Version != null && !packageDependency.VersionRange.Satisfies(new NuGetVersion(dependency.Version)))
                        {
                            return(NuGetPackageFilterResult.NotCompatibleVersion);
                        }
                    }

                    return(result);
                }
            }

            return(NuGetPackageFilterResult.NotCompatible);
        }