public async Task <IEnumerable <IServerPackage> > SearchAsync(
            string searchTerm,
            IEnumerable <string> targetFrameworks,
            bool allowPrereleaseVersions,
            ClientCompatibility compatibility,
            CancellationToken token)
        {
            var cache = await GetPackagesAsync(compatibility, token);

            var packages = cache
                           .Find(searchTerm)
                           .FilterByPrerelease(allowPrereleaseVersions);

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

            if (EnableFrameworkFiltering && targetFrameworks.Any())
            {
                // Get the list of framework names
                var frameworkNames = targetFrameworks
                                     .Select(frameworkName => VersionUtility.ParseFrameworkName(frameworkName));

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

            return(packages);
        }
        private static async Task <IEnumerable <IServerPackage> > GetUpdateCandidatesAsync(
            IServerPackageRepository repository,
            IEnumerable <IPackageName> packages,
            bool includePrerelease,
            ClientCompatibility compatibility,
            CancellationToken token)
        {
            var query = await repository.GetPackagesAsync(compatibility, token);

            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);
        }
        /// <summary>
        /// Package cache containing packages metadata.
        /// This data is generated if it does not exist already.
        /// </summary>
        public async Task <IEnumerable <IServerPackage> > GetPackagesAsync(
            ClientCompatibility compatibility,
            CancellationToken token)
        {
            await RebuildIfNeededAsync(shouldLock : true, token : token);

            // First time we come here, attach the file system watcher.
            if (_fileSystemWatcher == null &&
                EnableFileSystemMonitoring &&
                _runBackgroundTasks)
            {
                RegisterFileSystemWatcher();
            }

            // First time we come here, setup background jobs.
            if (_persistenceTimer == null &&
                _runBackgroundTasks)
            {
                SetupBackgroundJobs();
            }

            var cache = _serverPackageCache.GetAll();

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

            return(cache);
        }
Exemplo n.º 4
0
 public async Task <IEnumerable <IServerPackage> > SearchAsync(
     string searchTerm,
     IEnumerable <string> targetFrameworks,
     bool allowPrereleaseVersions,
     ClientCompatibility compatibility,
     CancellationToken token)
 {
     return(await SearchAsync(searchTerm, targetFrameworks, allowPrereleaseVersions, false, compatibility, token));
 }
        public static async Task <IEnumerable <IServerPackage> > FindPackagesByIdAsync(
            this IServerPackageRepository repository,
            string id,
            ClientCompatibility compatibility,
            CancellationToken token)
        {
            var packages = await repository.GetPackagesAsync(compatibility, token);

            return(packages.Where(p => StringComparer.OrdinalIgnoreCase.Equals(p.Id, id)));
        }
        public static async Task <IServerPackage> FindPackageAsync(
            this IServerPackageRepository repository,
            string id,
            ClientCompatibility compatibility,
            CancellationToken token)
        {
            var packages = await repository.FindPackagesByIdAsync(id, compatibility, token);

            return(packages
                   .OrderByDescending(p => p.Version)
                   .FirstOrDefault());
        }
 public static async Task <IEnumerable <IServerPackage> > SearchAsync(
     this IServerPackageRepository repository,
     string searchTerm,
     bool allowPrereleaseVersions,
     ClientCompatibility compatibility,
     CancellationToken token)
 {
     return(await repository.SearchAsync(
                searchTerm,
                Enumerable.Empty <string>(),
                allowPrereleaseVersions,
                compatibility,
                token));
 }
        public static async Task <IEnumerable <IServerPackage> > GetUpdatesAsync(
            this IServerPackageRepository repository,
            IEnumerable <IPackageName> packages,
            bool includePrerelease,
            bool includeAllVersions,
            IEnumerable <FrameworkName> targetFramework,
            IEnumerable <IVersionSpec> versionConstraints,
            ClientCompatibility compatibility,
            CancellationToken token)
        {
            List <IPackageName> packageList = packages.ToList();

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

            IList <IVersionSpec> versionConstraintList;

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

            if (packageList.Count != versionConstraintList.Count)
            {
                throw new ArgumentException(Strings.GetUpdatesParameterMismatch);
            }

            // These are the packages that we need to look at for potential updates.
            var candidates = await GetUpdateCandidatesAsync(
                repository,
                packageList,
                includePrerelease,
                compatibility,
                token);

            ILookup <string, IServerPackage> sourcePackages = candidates
                                                              .ToList()
                                                              .ToLookup(package => package.Id, StringComparer.OrdinalIgnoreCase);

            var results = new List <IServerPackage>();

            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);
        }