示例#1
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(_searchService)
                {
                    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,
                    Recommended        = metadata.IsRecommended,
                    RecommenderVersion = metadata.RecommenderVersion,
                    Vulnerabilities    = metadata.Vulnerabilities,
                    Sources            = _packageSources,
                    PackagePath        = metadata.PackagePath,
                    PackageFileService = _packageFileService,
                    IncludePrerelease  = _includePrerelease
                };

                listItem.UpdatePackageStatus(_installedPackages);

                listItemViewModels.Add(listItem);
            }

            return(listItemViewModels.ToArray());
        }
        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());
        }