public async Task <IEnumerable <IPackageSearchMetadata> > GetVersionsOfPackageAsync(IRepository packageRepository, IPackageDetails package, bool allowPrereleaseVersions, int skip)
        {
            if (skip < 0)
            {
                return(Enumerable.Empty <IPackageSearchMetadata>());
            }

            var sourceRepository = _repositoryProvider.CreateRepository(packageRepository.ToPackageSource());

            var getMetadataResult = await _packageMetadataProvider.GetPackageMetadataListAsync(package.Id, allowPrereleaseVersions, false, CancellationToken.None);

            var versions = getMetadataResult.Skip(skip).ToList();

            return(versions);
        }
        public async ValueTask<IReadOnlyCollection<PackageSearchMetadataContextInfo>> GetPackageMetadataListAsync(
            string id,
            IReadOnlyCollection<PackageSourceContextInfo> packageSources,
            bool includePrerelease,
            bool includeUnlisted,
            CancellationToken cancellationToken)
        {
            Assumes.NotNullOrEmpty(id);
            Assumes.NotNullOrEmpty(packageSources);

            IPackageMetadataProvider packageMetadataProvider = await GetPackageMetadataProviderAsync(packageSources, cancellationToken);
            IEnumerable<IPackageSearchMetadata> packageMetadata = await packageMetadataProvider.GetPackageMetadataListAsync(
                id,
                includePrerelease,
                includeUnlisted,
                cancellationToken);

            return packageMetadata.Select(package => PackageSearchMetadataContextInfo.Create(package)).ToList();
        }
        internal async Task LoadPackageMetadaAsync(IPackageMetadataProvider metadataProvider, CancellationToken token)
        {
            var versions = await _searchResultPackage.GetVersionsAsync();

            var packages = Enumerable.Empty <IPackageSearchMetadata>();

            try
            {
                // load up the full details for each version
                if (metadataProvider != null)
                {
                    packages = await metadataProvider.GetPackageMetadataListAsync(Id, true, false, token);
                }
            }
            catch (InvalidOperationException)
            {
                // Ignore failures.
            }

            var uniquePackages = packages
                                 .GroupBy(m => m.Identity.Version, (v, ms) => ms.First());

            var s = uniquePackages
                    .GroupJoin(
                versions,
                m => m.Identity.Version,
                d => d.Version,
                (m, d) => new DetailedPackageMetadata(m, d.FirstOrDefault()?.DownloadCount));

            _metadataDict = s.ToDictionary(m => m.Version);

            DetailedPackageMetadata p;

            if (SelectedVersion != null &&
                _metadataDict.TryGetValue(SelectedVersion.Version, out p))
            {
                PackageMetadata = p;
            }
        }
Пример #4
0
        internal async Task LoadPackageMetadaAsync(IPackageMetadataProvider metadataProvider, CancellationToken token)
        {
            var versions = await _searchResultPackage.GetVersionsAsync();

            // First try to load the metadata from the version info. This will happen if we already fetched metadata
            // about each version at the same time as fetching the version list (that it, V2). This also acts as a
            // means to cache version metadata.
            _metadataDict = versions
                            .Where(v => v.PackageSearchMetadata != null)
                            .ToDictionary(
                v => v.Version,
                v => new DetailedPackageMetadata(v.PackageSearchMetadata, v.DownloadCount));

            // If we are missing any metadata, go to the metadata provider and fetch all of the data again.
            if (versions.Select(v => v.Version).Except(_metadataDict.Keys).Any())
            {
                try
                {
                    // Load up the full details for each version.
                    var packages = await metadataProvider?.GetPackageMetadataListAsync(
                        Id,
                        includePrerelease : true,
                        includeUnlisted : false,
                        cancellationToken : token);

                    var uniquePackages = packages
                                         .GroupBy(
                        m => m.Identity.Version,
                        (v, ms) => ms.First());

                    _metadataDict = uniquePackages
                                    .GroupJoin(
                        versions,
                        m => m.Identity.Version,
                        d => d.Version,
                        (m, d) =>
                    {
                        var versionInfo = d.OrderByDescending(v => v.DownloadCount).FirstOrDefault();
                        if (versionInfo != null)
                        {
                            // Save the metadata about this version to the VersionInfo instance.
                            versionInfo.PackageSearchMetadata = m;
                        }

                        return(new DetailedPackageMetadata(m, versionInfo?.DownloadCount));
                    })
                                    .ToDictionary(m => m.Version);
                }
                catch (InvalidOperationException)
                {
                    // Ignore failures.
                }
            }

            DetailedPackageMetadata p;

            if (SelectedVersion != null &&
                _metadataDict.TryGetValue(SelectedVersion.Version, out p))
            {
                PackageMetadata = p;
            }
        }
Пример #5
0
        public async Task <IEnumerable <IPackageSearchMetadata> > GetPackagesWithUpdatesAsync(string searchText, SearchFilter searchFilter, CancellationToken cancellationToken)
        {
            var packages = _installedPackages
                           .Where(p => !p.IsAutoReferenced())
                           .GetEarliest()
                           .Where(p => p.Id.IndexOf(searchText, StringComparison.OrdinalIgnoreCase) != -1);

            // Prefetch metadata for all installed packages
            var prefetch = await TaskCombinators.ThrottledAsync(
                packages,
                (p, t) => _metadataProvider.GetPackageMetadataListAsync(p.Id, searchFilter.IncludePrerelease, includeUnlisted: false, cancellationToken: t),
                cancellationToken);

            // Flatten the result list
            var prefetchedPackages = prefetch
                                     .Where(p => p != null)
                                     .SelectMany(p => p)
                                     .ToArray();

            // Traverse all projects and determine packages with updates
            var packagesWithUpdates = new List <IPackageSearchMetadata>();

            foreach (var project in _projects)
            {
                var installed = await project.GetInstalledPackagesAsync(_serviceBroker, cancellationToken);

                foreach (var installedPackage in installed)
                {
                    var installedVersion = installedPackage.Identity.Version;
                    var allowedVersions  = installedPackage.AllowedVersions ?? VersionRange.All;

                    // filter packages based on current package identity
                    var allPackages = prefetchedPackages
                                      .Where(p => StringComparer.OrdinalIgnoreCase.Equals(
                                                 p.Identity.Id,
                                                 installedPackage.Identity.Id))
                                      .ToArray();

                    // and allowed versions
                    var allowedPackages = allPackages
                                          .Where(p => allowedVersions.Satisfies(p.Identity.Version));

                    // peek the highest available
                    var highest = allowedPackages
                                  .OrderByDescending(e => e.Identity.Version, VersionComparer.VersionRelease)
                                  .FirstOrDefault();

                    if (highest != null &&
                        VersionComparer.VersionRelease.Compare(installedVersion, highest.Identity.Version) < 0)
                    {
                        packagesWithUpdates.Add(highest.WithVersions(ToVersionInfo(allPackages)));
                    }
                }
            }

            // select the earliest package update candidates
            var uniquePackageIds = packagesWithUpdates
                                   .Select(p => p.Identity)
                                   .GetEarliest();

            // get unique list of package metadata as similar updates may come from different projects
            var uniquePackages = uniquePackageIds
                                 .GroupJoin(
                packagesWithUpdates,
                id => id,
                p => p.Identity,
                (id, pl) => pl.First());

            return(uniquePackages
                   .OrderBy(p => p.Identity.Id)
                   .ToArray());
        }
		internal async Task LoadPackageMetadaAsync(IPackageMetadataProvider metadataProvider, CancellationToken token)
		{
			var versions = await _searchResultPackage.GetVersionsAsync();

			var packages = Enumerable.Empty<IPackageSearchMetadata>();
			try
			{
				// load up the full details for each version
				if (metadataProvider != null)
					packages = await metadataProvider.GetPackageMetadataListAsync(Id, true, false, token);
			}
			catch (InvalidOperationException)
			{
				// Ignore failures.
			}

			var uniquePackages = packages
				.GroupBy(m => m.Identity.Version, (v, ms) => ms.First());

			var s = uniquePackages
				.GroupJoin(
					versions,
					m => m.Identity.Version,
					d => d.Version,
					(m, d) => new DetailedPackageMetadata(m, d.FirstOrDefault()?.DownloadCount));

			_metadataDict = s.ToDictionary(m => m.Version);

			DetailedPackageMetadata p;
			if (SelectedVersion != null
			    && _metadataDict.TryGetValue(SelectedVersion.Version, out p))
			{
				PackageMetadata = p;
			}
		}