コード例 #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());
        }
コード例 #2
0
        public async override Task SetCurrentPackageAsync(
            PackageItemViewModel searchResultPackage,
            ItemFilter filter,
            Func <PackageItemViewModel> getPackageItemViewModel)
        {
            // Set InstalledVersion before fetching versions list.
            InstalledVersion = searchResultPackage.InstalledVersion;

            await base.SetCurrentPackageAsync(searchResultPackage, filter, getPackageItemViewModel);

            // SetCurrentPackage can take long time to return, user might changed selected package.
            // Check selected package.
            if (getPackageItemViewModel() != searchResultPackage)
            {
                return;
            }
            InstalledVersion = searchResultPackage.InstalledVersion;
            SelectedVersion.IsCurrentInstalled = InstalledVersion == SelectedVersion.Version;
        }
コード例 #3
0
        public async override Task SetCurrentPackageAsync(
            PackageItemViewModel searchResultPackage,
            ItemFilter filter,
            Func <PackageItemViewModel> getPackageItemViewModel)
        {
            // Set InstalledVersion before fetching versions list.
            PackageLevel          = searchResultPackage.PackageLevel;
            InstalledVersion      = searchResultPackage.InstalledVersion;
            InstalledVersionRange = searchResultPackage.AllowedVersions;

            VersionsView = new CollectionViewSource()
            {
                Source = Versions
            }.View;

            if (IsProjectPackageReference)
            {
                VersionsView.Filter += VersionsFilter;
            }

            OnPropertyChanged(nameof(VersionsView));

            await base.SetCurrentPackageAsync(searchResultPackage, filter, getPackageItemViewModel);

            // SetCurrentPackage can take long time to return, user might changed selected package.
            // Check selected package.
            if (getPackageItemViewModel() != searchResultPackage)
            {
                return;
            }
            PreviousSelectedVersion            = null;
            PackageLevel                       = searchResultPackage.PackageLevel;
            InstalledVersion                   = searchResultPackage.InstalledVersion;
            InstalledVersionRange              = searchResultPackage.AllowedVersions;
            SelectedVersion.IsCurrentInstalled = InstalledVersion == SelectedVersion.Version && InstalledVersionRange == SelectedVersion.Range;
        }
コード例 #4
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());
        }