Example #1
0
        /// <summary>
        /// Get IPowerShellPackage from the remote package source
        /// </summary>
        /// <param name="autoCompleteResource"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private IPowerShellPackage GetIPowerShellPackageFromRemoteSource(PSAutoCompleteResource autoCompleteResource, string id)
        {
            IEnumerable <NuGetVersion> versions = Enumerable.Empty <NuGetVersion>();

            try
            {
                Task <IEnumerable <NuGetVersion> > versionTask = autoCompleteResource.VersionStartsWith(id, Version, IncludePrerelease.IsPresent, CancellationToken.None);
                versions = versionTask.Result;
            }
            catch (Exception) { }

            IPowerShellPackage package = new PowerShellPackage();

            package.Id = id;
            if (AllVersions.IsPresent)
            {
                if (versions != null && versions.Any())
                {
                    package.Versions = versions.OrderByDescending(v => v);
                    LegacyNuGet.SemanticVersion sVersion;
                    LegacyNuGet.SemanticVersion.TryParse(package.Versions.FirstOrDefault().ToNormalizedString(), out sVersion);
                    package.Version = sVersion;
                }
            }
            else
            {
                NuGetVersion nVersion = null;
                if (versions != null && versions.Any())
                {
                    nVersion = versions.OrderByDescending(v => v).FirstOrDefault();
                }

                if (nVersion != null)
                {
                    package.Versions = new List <NuGetVersion>()
                    {
                        nVersion
                    };
                    LegacyNuGet.SemanticVersion sVersion;
                    LegacyNuGet.SemanticVersion.TryParse(nVersion.ToNormalizedString(), out sVersion);
                    package.Version = sVersion;
                }
            }
            return(package);
        }
Example #2
0
        /// <summary>
        /// Get IPowerShellPackage from the remote package source
        /// </summary>
        private PowerShellPackage GetPowerShellPackageFromRemoteSource(string id)
        {
            var asyncLazyVersions = new AsyncLazy <IEnumerable <NuGetVersion> >(
                () => GetPackageVersionsFromRemoteSourceAsync(id, Version, IncludePrerelease.IsPresent),
                NuGetUIThreadHelper.JoinableTaskFactory);

            var package = new PowerShellPackage();

            package.Id = id;
            package.AsyncLazyVersions = asyncLazyVersions;

            if (AllVersions.IsPresent)
            {
                package.AllVersions = true;
            }
            else
            {
                package.AllVersions = false;
            }

            return(package);
        }
        /// <summary>
        /// Get IPowerShellPackage from the remote package source
        /// </summary>
        /// <param name="autoCompleteResource"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        private IPowerShellPackage GetIPowerShellPackageFromRemoteSource(PSAutoCompleteResource autoCompleteResource, string id)
        {
            IEnumerable<NuGetVersion> versions = Enumerable.Empty<NuGetVersion>();
            try
            {
                Task<IEnumerable<NuGetVersion>> versionTask = autoCompleteResource.VersionStartsWith(id, Version, IncludePrerelease.IsPresent, CancellationToken.None);
                versions = versionTask.Result;
            }
            catch (Exception) { }

            IPowerShellPackage package = new PowerShellPackage();
            package.Id = id;
            if (AllVersions.IsPresent)
            {
                if (versions != null && versions.Any())
                {
                    package.Versions = versions.OrderByDescending(v => v);
                    LegacyNuGet.SemanticVersion sVersion;
                    LegacyNuGet.SemanticVersion.TryParse(package.Versions.FirstOrDefault().ToNormalizedString(), out sVersion);
                    package.Version = sVersion;
                }
            }
            else
            {
                NuGetVersion nVersion = null;
                if (versions != null && versions.Any())
                {
                    nVersion = versions.OrderByDescending(v => v).FirstOrDefault();
                }

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