コード例 #1
0
        protected override async void OnCurrentPackageChanged()
        {
            if (_searchResultPackage == null)
            {
                return;
            }

            UpdateInstalledVersions();

            // update alternative package managers
            if (_packageManagerProviders.Any())
            {
                // clear providers first
                foreach (var p in _projects)
                {
                    p.Providers = null;
                }

                // update the providers list async
                foreach (var p in _projects)
                {
                    p.Providers = await AlternativePackageManagerProviders.CalculateAlternativePackageManagersAsync(
                        _packageManagerProviders,
                        Id,
                        p.NuGetProject);
                }
            }
        }
コード例 #2
0
        public IEnumerable <PackageItemListViewModel> GetCurrent()
        {
            if (_state.ItemsCount == 0)
            {
                return(Enumerable.Empty <PackageItemListViewModel>());
            }

            var listItems = _state.Results
                            .Select((metadata, index) =>
            {
                VersionRange allowedVersions = VersionRange.All;

                // get the allowed version range and pass it to package item view model to choose the latest version based on that
                if (_packageReferences != null)
                {
                    var matchedPackageReferences = _packageReferences.Where(r => StringComparer.OrdinalIgnoreCase.Equals(r.Identity.Id, metadata.Identity.Id));
                    var allowedVersionsRange     = matchedPackageReferences.Select(r => r.AllowedVersions).Where(v => v != null).ToArray();

                    if (allowedVersionsRange.Length > 0)
                    {
                        allowedVersions = allowedVersionsRange[0];
                    }
                }

                var listItem = new PackageItemListViewModel
                {
                    Id                  = metadata.Identity.Id,
                    Version             = metadata.Identity.Version,
                    IconUrl             = metadata.IconUrl,
                    Author              = metadata.Authors,
                    DownloadCount       = metadata.DownloadCount,
                    Summary             = metadata.Summary,
                    Versions            = AsyncLazy.New(metadata.GetVersionsAsync),
                    AllowedVersions     = allowedVersions,
                    PrefixReserved      = metadata.PrefixReserved && !IsMultiSource,
                    DeprecationMetadata = AsyncLazy.New(metadata.GetDeprecationMetadataAsync),
                    Vulnerabilities     = metadata.Vulnerabilities,
                    Recommended         = index < _recommendedCount,
                    PackageReader       = (metadata as PackageSearchMetadataBuilder.ClonedPackageSearchMetadata)?.PackageReader,
                };

                listItem.UpdatePackageStatus(_installedPackages);

                if (!_context.IsSolution && _context.PackageManagerProviders.Any())
                {
                    listItem.ProvidersLoader = AsyncLazy.New(
                        async() =>
                    {
                        string uniqueProjectName = await _context.Projects[0].GetUniqueNameOrNameAsync(CancellationToken.None);
                        return(await AlternativePackageManagerProviders.CalculateAlternativePackageManagersAsync(_context.PackageManagerProviders, listItem.Id, uniqueProjectName));
                    });
                }

                return(listItem);
            });

            return(listItems.ToArray());
        }
コード例 #3
0
        public IEnumerable <PackageItemListViewModel> GetCurrent()
        {
            if (_state.ItemsCount == 0)
            {
                return(Enumerable.Empty <PackageItemListViewModel>());
            }

            var listItems = _state.Results
                            .Select(metadata =>
            {
                VersionRange allowedVersions = VersionRange.All;

                // get the allowed version range and pass it to package item view model to choose the latest version based on that
                if (_packageReferences != null)
                {
                    var matchedPackageReferences = _packageReferences.Where(r => StringComparer.OrdinalIgnoreCase.Equals(r.PackageIdentity.Id, metadata.Identity.Id));
                    var allowedVersionsRange     = matchedPackageReferences.Select(r => r.AllowedVersions).Where(v => v != null).ToArray();

                    if (allowedVersionsRange.Length > 0)
                    {
                        allowedVersions = allowedVersionsRange[0];
                    }
                }

                var listItem = new PackageItemListViewModel
                {
                    Id                  = metadata.Identity.Id,
                    Version             = metadata.Identity.Version,
                    IconUrl             = metadata.IconUrl,
                    Author              = metadata.Authors,
                    DownloadCount       = metadata.DownloadCount,
                    Summary             = metadata.Summary,
                    Versions            = AsyncLazy.New(() => metadata.GetVersionsAsync()),
                    AllowedVersions     = allowedVersions,
                    PrefixReserved      = metadata.PrefixReserved && !IsMultiSource,
                    IsPackageDeprecated = metadata.DeprecationMetadata != null,
                };
                listItem.UpdatePackageStatus(_installedPackages);

                if (!_context.IsSolution && _context.PackageManagerProviders.Any())
                {
                    listItem.ProvidersLoader = AsyncLazy.New(
                        () => AlternativePackageManagerProviders.CalculateAlternativePackageManagersAsync(
                            _context.PackageManagerProviders,
                            listItem.Id,
                            _context.Projects[0]));
                }

                return(listItem);
            });

            return(listItems.ToArray());
        }
コード例 #4
0
        public IEnumerable <PackageItemListViewModel> GetCurrent()
        {
            if (_state.ItemsCount == 0)
            {
                return(Enumerable.Empty <PackageItemListViewModel>());
            }

            var listItems = _state.Results
                            .Select(metadata =>
            {
                var listItem = new PackageItemListViewModel
                {
                    Id            = metadata.Identity.Id,
                    Version       = metadata.Identity.Version,
                    IconUrl       = metadata.IconUrl,
                    Author        = metadata.Authors,
                    DownloadCount = metadata.DownloadCount,
                    Summary       = metadata.Summary,
                    Versions      = AsyncLazy.New(() => metadata.GetVersionsAsync())
                };
                listItem.UpdatePackageStatus(_installedPackages);

                if (!_context.IsSolution && _context.PackageManagerProviders.Any())
                {
                    listItem.ProvidersLoader = AsyncLazy.New(
                        () => AlternativePackageManagerProviders.CalculateAlternativePackageManagersAsync(
                            _context.PackageManagerProviders,
                            listItem.Id,
                            _context.Projects[0]));
                }

                return(listItem);
            });

            return(listItems.ToArray());
        }
コード例 #5
0
        public IEnumerable <PackageItemViewModel> GetCurrent()
        {
            if (_state.ItemsCount == 0)
            {
                return(Enumerable.Empty <PackageItemViewModel>());
            }

            var listItemViewModels = new List <PackageItemViewModel>();

            foreach (PackageSearchMetadataContextInfo metadata in _state.Results.PackageSearchItems)
            {
                VersionRange allowedVersions = VersionRange.All;

                // get the allowed version range and pass it to package item view model to choose the latest version based on that
                if (_packageReferences != null)
                {
                    IEnumerable <IPackageReferenceContextInfo> matchedPackageReferences = _packageReferences.Where(r => StringComparer.OrdinalIgnoreCase.Equals(r.Identity.Id, metadata.Identity.Id));
                    VersionRange[] allowedVersionsRange = matchedPackageReferences.Select(r => r.AllowedVersions).Where(v => v != null).ToArray();

                    if (allowedVersionsRange.Length > 0)
                    {
                        allowedVersions = allowedVersionsRange[0];
                    }
                }

                var listItem = new PackageItemViewModel
                {
                    Id                            = metadata.Identity.Id,
                    Version                       = metadata.Identity.Version,
                    IconUrl                       = metadata.IconUrl,
                    Author                        = metadata.Authors,
                    DownloadCount                 = metadata.DownloadCount,
                    Summary                       = metadata.Summary,
                    AllowedVersions               = allowedVersions,
                    PrefixReserved                = metadata.PrefixReserved && !IsMultiSource,
                    Versions                      = AsyncLazy.New(() => { return(GetVersionInfoAsync(metadata.Identity)); }),
                    DeprecationMetadata           = AsyncLazy.New(() => { return(GetDeprecationMetadataAsync(metadata.Identity)); }),
                    DetailedPackageSearchMetadata = AsyncLazy.New(() => { return(GetDetailedPackageSearchMetadataContextInfoAsync(metadata.Identity)); }),
                    Recommended                   = metadata.IsRecommended,
                    RecommenderVersion            = metadata.RecommenderVersion,
                    Vulnerabilities               = metadata.Vulnerabilities,
                    Sources                       = _packageSources,
                    PackagePath                   = metadata.PackagePath,
                    PackageFileService            = _packageFileService,
                };

                listItem.UpdatePackageStatus(_installedPackages);

                if (!_context.IsSolution && _context.PackageManagerProviders.Any())
                {
                    listItem.ProvidersLoader = AsyncLazy.New(
                        async() =>
                    {
                        string uniqueProjectName = await _context.Projects[0].GetUniqueNameOrNameAsync(
                            _context.ServiceBroker,
                            CancellationToken.None);

                        return(await AlternativePackageManagerProviders.CalculateAlternativePackageManagersAsync(
                                   _context.PackageManagerProviders,
                                   listItem.Id,
                                   uniqueProjectName));
                    });
                }
                listItemViewModels.Add(listItem);
            }

            return(listItemViewModels.ToArray());
        }