コード例 #1
0
        public IQueryable <ServerPackage> Search(
            string searchTerm,
            IEnumerable <string> targetFrameworks,
            bool allowPrereleaseVersions,
            ClientCompatibility compatibility)
        {
            var packages = GetPackages(compatibility)
                           .AsQueryable()
                           .Find(searchTerm)
                           .FilterByPrerelease(allowPrereleaseVersions);

            if (EnableDelisting)
            {
                packages = packages.Where(p => p.Listed);
            }

            if (EnableFrameworkFiltering && targetFrameworks.Any())
            {
                throw new NotImplementedException("filter target frameworks");
                // // Get the list of framework names
                // var frameworkNames = targetFrameworks
                //     .Select(frameworkName => NuGetFramework.Parse(frameworkName));

                // packages = packages
                //     .Where(package => frameworkNames
                //         .Any(frameworkName => VersionUtility
                //             .IsCompatible(frameworkName, package.GetSupportedFrameworks())));
            }

            return(packages.AsQueryable());
        }
コード例 #2
0
        public IQueryable <ServerPackage> GetPackages(ClientCompatibility compatibility)
        {
            var cache = CachedPackages.AsQueryable();

            if (!compatibility.AllowSemVer2)
            {
                cache = cache.Where(p => !p.IsSemVer2);
            }

            return(cache);
        }
コード例 #3
0
        private static IQueryable <IPackage> GetUpdateCandidates(
            IServerPackageRepository repository,
            IEnumerable <IPackageName> packages,
            bool includePrerelease,
            ClientCompatibility compatibility)
        {
            var query = repository.GetPackages(compatibility);

            var ids = new HashSet <string>(
                packages.Select(p => p.Id),
                StringComparer.OrdinalIgnoreCase);

            query = query.Where(p => ids.Contains(p.Id));

            if (!includePrerelease)
            {
                query = query.Where(p => p.IsReleaseVersion());
            }

            // for updates, we never consider unlisted packages
            query = query.Where(p => p.Listed);

            return(query);
        }
コード例 #4
0
        public static IEnumerable <IPackage> GetUpdatesCore(
            this IServerPackageRepository repository,
            IEnumerable <IPackageName> packages,
            bool includePrerelease,
            bool includeAllVersions,
            IEnumerable <FrameworkName> targetFramework,
            IEnumerable <VersionRange> versionConstraints,
            ClientCompatibility compatibility)
        {
            List <IPackageName> packageList = packages.ToList();

            if (!packageList.Any())
            {
                return(Enumerable.Empty <IPackage>());
            }

            IList <VersionRange> versionConstraintList;

            if (versionConstraints == null)
            {
                versionConstraintList = new VersionRange[packageList.Count];
            }
            else
            {
                versionConstraintList = versionConstraints.ToList();
            }

            if (packageList.Count != versionConstraintList.Count)
            {
                throw new ArgumentException("The 'packages' and 'versionConstraints' parameters must have the same number of elements.");
            }

            // These are the packages that we need to look at for potential updates.
            ILookup <string, IPackage> sourcePackages = GetUpdateCandidates(
                repository,
                packageList,
                includePrerelease,
                compatibility)
                                                        .ToList()
                                                        .ToLookup(package => package.Id, StringComparer.OrdinalIgnoreCase);

            var results = new List <IPackage>();

            for (int i = 0; i < packageList.Count; i++)
            {
                var package    = packageList[i];
                var constraint = versionConstraintList[i];

                var updates = from candidate in sourcePackages[package.Id]
                              where (candidate.Version > package.Version) &&
                              SupportsTargetFrameworks(targetFramework, candidate) &&
                              (constraint == null || constraint.Satisfies(candidate.Version))
                              select candidate;

                results.AddRange(updates);
            }

            if (!includeAllVersions)
            {
                return(CollapseById(results));
            }
            return(results);
        }
コード例 #5
0
        IEnumerable <HostedPackage> IPackageService.FindPackagesById(string id, ClientCompatibility compatibility)
        {
            var found = this.FindPackagesById(id, compatibility);

            return(found.Select(ToHostedPackage));
        }
コード例 #6
0
 public IEnumerable <ServerPackage> FindPackagesById(string packageId, ClientCompatibility compatibility)
 {
     return(GetPackages(compatibility)
            .Where(p => StringComparer.OrdinalIgnoreCase.Compare(p.Id, packageId) == 0));
 }