Пример #1
0
        private void FindPackagesByPSSearchService()
        {
            var remotePackages = GetPackagesFromRemoteSource(Id, IncludePrerelease.IsPresent);

            if (ExactMatch.IsPresent)
            {
                remotePackages = remotePackages.Where(p => string.Equals(p.Identity.Id, Id, StringComparison.OrdinalIgnoreCase));
            }

            remotePackages = remotePackages.Skip(Skip).Take(First);

            VersionType versionType;

            if (AllVersions.IsPresent)
            {
                versionType = VersionType.All;
            }
            else
            {
                versionType = VersionType.Latest;
            }

            var view = PowerShellRemotePackage.GetPowerShellPackageView(remotePackages, versionType);

            foreach (var package in view)
            {
                // Just start the task and don't wait for it to complete
                package.AsyncLazyVersions.GetValueAsync();
            }

            if (view.Any())
            {
                WriteObject(view, enumerateCollection: true);
            }
        }
Пример #2
0
        /// <summary>
        /// Get the view of PowerShellPackage. Used for Get-Package -ListAvailable command.
        /// </summary>
        internal static List <PowerShellRemotePackage> GetPowerShellPackageView(IEnumerable <IPackageSearchMetadata> metadata, VersionType versionType)
        {
            var view = new List <PowerShellRemotePackage> ();

            foreach (var data in metadata)
            {
                var package = new PowerShellRemotePackage()
                {
                    Id                = data.Identity.Id,
                    Description       = data.Summary,
                    AsyncLazyVersions = new AsyncLazy <IEnumerable <NuGetVersion> > (async delegate {
                        var versions = await data.GetVersionsAsync();
                        var results  = versions?.Select(v => v.Version).OrderByDescending(v => v).ToArray();
                        return(results ?? Enumerable.Empty <NuGetVersion> ());
                    }),
                    LicenseUrl = data.LicenseUrl?.AbsoluteUri
                };

                switch (versionType)
                {
                case VersionType.All:
                    package.AllVersions = true;
                    break;

                case VersionType.Latest:
                    break;
                }

                view.Add(package);
            }

            return(view);
        }
Пример #3
0
        private void WritePackages(IEnumerable <IPackageSearchMetadata> packages, VersionType versionType, bool outputOnEmpty)
        {
            var view = PowerShellRemotePackage.GetPowerShellPackageView(packages, versionType);

            if (view.Any() || !outputOnEmpty)
            {
                WriteObject(view, enumerateCollection: true);
            }
            else
            {
                LogCore(MessageLevel.Info, Resources.Cmdlet_GetPackageNoPackageFound);
            }
        }
        void WritePackages(IEnumerable <IPackageSearchMetadata> packages, VersionType versionType, bool outputOnEmpty)
        {
            var view = PowerShellRemotePackage.GetPowerShellPackageView(packages, versionType);

            if (view.Any() || !outputOnEmpty)
            {
                WriteObject(view, enumerateCollection: true);
            }
            else
            {
                LogCore(MessageLevel.Info, "No packages found in the current package source.");
            }
        }
Пример #5
0
        /// <summary>
        /// Get the view of PowerShellPackage. Used for Get-Package -ListAvailable command.
        /// </summary>
        /// <param name="metadata">list of PSSearchMetadata</param>
        /// <param name="versionType"></param>
        /// <returns></returns>
        internal static List <PowerShellRemotePackage> GetPowerShellPackageView(IEnumerable <PSSearchMetadata> metadata, VersionType versionType)
        {
            List <PowerShellRemotePackage> view = new List <PowerShellRemotePackage>();

            foreach (PSSearchMetadata data in metadata)
            {
                PowerShellRemotePackage package = new PowerShellRemotePackage();
                package.Id          = data.Identity.Id;
                package.Description = data.Summary;

                switch (versionType)
                {
                case VersionType.all:
                {
                    package.Versions = data.Versions.OrderByDescending(v => v);
                    if (package.Versions != null && package.Versions.Any())
                    {
                        LegacyNuGet.SemanticVersion sVersion;
                        LegacyNuGet.SemanticVersion.TryParse(package.Versions.FirstOrDefault().ToNormalizedString(), out sVersion);
                        package.Version = sVersion;
                    }
                }
                break;

                case VersionType.latest:
                {
                    NuGetVersion nVersion = data.Version == null?data.Versions.OrderByDescending(v => v).FirstOrDefault() : data.Version;

                    package.Versions = new List <NuGetVersion>()
                    {
                        nVersion
                    };
                    if (nVersion != null)
                    {
                        LegacyNuGet.SemanticVersion sVersion;
                        LegacyNuGet.SemanticVersion.TryParse(nVersion.ToNormalizedString(), out sVersion);
                        package.Version = sVersion;
                    }
                }
                break;
                }

                view.Add(package);
            }
            return(view);
        }
        /// <summary>
        /// Get the view of PowerShellPackage. Used for Get-Package -ListAvailable command. 
        /// </summary>
        /// <param name="metadata">list of PSSearchMetadata</param>
        /// <param name="versionType"></param>
        /// <returns></returns>
        internal static List<PowerShellRemotePackage> GetPowerShellPackageView(IEnumerable<PSSearchMetadata> metadata, VersionType versionType)
        {
            List<PowerShellRemotePackage> view = new List<PowerShellRemotePackage>();
            foreach (PSSearchMetadata data in metadata)
            {
                PowerShellRemotePackage package = new PowerShellRemotePackage();
                package.Id = data.Identity.Id;
                package.Description = data.Summary;

                switch (versionType)
                {
                    case VersionType.all:
                        {
                            package.Versions = data.Versions.OrderByDescending(v => v);
                            if (package.Versions != null && package.Versions.Any())
                            {
                                LegacyNuGet.SemanticVersion sVersion;
                                LegacyNuGet.SemanticVersion.TryParse(package.Versions.FirstOrDefault().ToNormalizedString(), out sVersion);
                                package.Version = sVersion;
                            }
                        }
                        break;
                    case VersionType.latest:
                        {
                            NuGetVersion nVersion = data.Version == null ? data.Versions.OrderByDescending(v => v).FirstOrDefault() : data.Version;
                            package.Versions = new List<NuGetVersion>() { nVersion };
                            if (nVersion != null)
                            {
                                LegacyNuGet.SemanticVersion sVersion;
                                LegacyNuGet.SemanticVersion.TryParse(nVersion.ToNormalizedString(), out sVersion);
                                package.Version = sVersion;
                            }
                        }
                        break;
                }

                view.Add(package);
            }
            return view;
        }