private void SetComboboxCurrentVersion(string comboboxText, IEnumerable <NuGetVersion> versions) { NuGetVersion matchVersion = null; VersionRange userRange = null; // Get the best version from the range if the user typed a custom version bool userTypedAValidVersionRange = VersionRange.TryParse(comboboxText, out userRange); if (userTypedAValidVersionRange) { matchVersion = userRange.FindBestMatch(versions); } if (matchVersion == null && userRange == null) { return; } // If the selected version is not the correct one, deselect a version so Install/Update button is disabled. if (_versions.SelectedIndex != -1 && matchVersion?.ToString() != _versions.Items[_versions.SelectedIndex].ToString()) { _versions.SelectedIndex = -1; } // Automatically select the item when the input or custom range text matches it for (int i = 0; i < _versions.Items.Count; i++) { DisplayVersion currentItem = _versions.Items[i] as DisplayVersion; if (currentItem != null && (comboboxText == _versions.Items[i].ToString() || _versions.Items[i].ToString() == matchVersion?.ToString())) { _versions.SelectedIndex = i; // This is the "select" effect in the dropdown PackageDetailControlModel.SelectedVersion = new DisplayVersion(userRange, matchVersion, additionalInfo: null); } } }
private void UpdateInstalledVersions() { var hash = new HashSet <NuGetVersion>(); foreach (var project in _projects) { try { var installedVersion = GetInstalledPackage(project.NuGetProject, Id); if (installedVersion != null) { project.InstalledVersion = installedVersion.PackageIdentity.Version; hash.Add(installedVersion.PackageIdentity.Version); project.AutoReferenced = (installedVersion as BuildIntegratedPackageReference)?.Dependency?.AutoReferenced == true; } else { project.InstalledVersion = null; project.AutoReferenced = false; } } catch (Exception ex) { project.InstalledVersion = null; // we don't expect it to throw any exception here. But in some edge case when opening manager ui at solution is the // first NuGet operation, and packages.config file is not valid for any of the project, then it will throw here which // should be ignored since we already show a error bar on manager ui to show this exact error. ActivityLog.LogError(NuGetUI.LogEntrySource, ex.ToString()); } } InstalledVersionsCount = hash.Count; if (hash.Count == 0) { InstalledVersions = Resources.Text_NotInstalled; } else if (hash.Count == 1) { var displayVersion = new DisplayVersion( hash.First(), string.Empty); InstalledVersions = displayVersion.ToString(); } else { InstalledVersions = Resources.Text_MultipleVersionsInstalled; } UpdateCanInstallAndCanUninstall(); AutoSelectProjects(); }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { var version = value as NuGetVersion; if (version == null) { return(null); } var displayVersion = new DisplayVersion(version, string.Empty, versionFormat: parameter as string); return(displayVersion.ToString()); }
// Calculate the version to select among _versions and select it protected void SelectVersion() { if (_versions.Count == 0) { // there's nothing to select return; } DisplayVersion versionToSelect = _versions .FirstOrDefault(v => v != null && v.Version.Equals(_searchResultPackage.Version)); if (versionToSelect == null) { versionToSelect = _versions[0]; } if (versionToSelect != null) { SelectedVersion = versionToSelect; } }
private void UpdateInstalledVersions() { var hash = new HashSet <NuGetVersion>(); foreach (var project in _projects) { var installedVersion = GetInstalledPackage(project.NuGetProject, Id); if (installedVersion != null) { project.InstalledVersion = installedVersion.PackageIdentity.Version; hash.Add(installedVersion.PackageIdentity.Version); project.AutoReferenced = (installedVersion as BuildIntegratedPackageReference)?.Dependency?.AutoReferenced == true; } else { project.InstalledVersion = null; } } InstalledVersionsCount = hash.Count; if (hash.Count == 0) { InstalledVersions = Resources.Text_NotInstalled; } else if (hash.Count == 1) { var displayVersion = new DisplayVersion( hash.First(), string.Empty); InstalledVersions = displayVersion.ToString(); } else { InstalledVersions = Resources.Text_MultipleVersionsInstalled; } UpdateCanInstallAndCanUninstall(); AutoSelectProjects(); }
// Calculate the version to select among _versions and select it protected void SelectVersion() { if (_versions.Count == 0) { SelectedVersion = null; } // SelectedVersion should be updated if // 1. its null or // 2. current version set doesn't have existing selected version or // 3. it's right after installing a new package which means selected version will be equals to installed one or // 4. existing selected version is blocked by allowedVersions range of selected project(s). else if (SelectedVersion == null || !_versions.Contains(SelectedVersion) || SelectedVersion.Version.Equals(_searchResultPackage.InstalledVersion) || (_versions.Any(v => v != null && !v.IsValidVersion) && _versions.IndexOf(SelectedVersion) > _versions.IndexOf(_versions.FirstOrDefault(v => v != null && !v.IsValidVersion)))) { // it should always select the top version from versions list to install or update // which has a valid version. If find none, then just set to null. SelectedVersion = _versions.FirstOrDefault(v => v != null && v.IsValidVersion); } }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { DisplayVersion version = value as DisplayVersion; return(version != null && !version.IsValidVersion ? Resources.ToolTip_BlockedVersion : null); }
// Calculate the version to select among _versions and select it protected void SelectVersion() { if (_versions.Count == 0) { // there's nothing to select return; } DisplayVersion versionToSelect = _versions .Where(v => v != null && v.Version.Equals(_searchResultPackage.Version)) .FirstOrDefault(); if (versionToSelect == null) { versionToSelect = _versions[0]; } if (versionToSelect != null) { SelectedVersion = versionToSelect; } }
protected override Task CreateVersionsAsync(CancellationToken cancellationToken) { // The value will be null if the server does not return any versions. if (_allPackageVersions == null || _allPackageVersions.Count == 0) { return(Task.CompletedTask); } Versions.Clear(); var installedDependency = InstalledPackageDependencies.Where(p => StringComparer.OrdinalIgnoreCase.Equals(p.Id, Id) && p.VersionRange != null && p.VersionRange.HasLowerBound) .OrderByDescending(p => p.VersionRange.MinVersion) .FirstOrDefault(); // installVersion is null if the package is not installed var installedVersion = installedDependency?.VersionRange; List <(NuGetVersion version, bool isDeprecated)> allVersions = _allPackageVersions?.OrderByDescending(v => v.version).ToList(); // null, if no version constraint defined in package.config VersionRange allowedVersions = _projectVersionConstraints.Select(e => e.VersionRange).FirstOrDefault(); // null, if all versions are allowed to be install or update var blockedVersions = new List <NuGetVersion>(allVersions.Count); List <(NuGetVersion version, bool isDeprecated)> allVersionsAllowed; if (allowedVersions == null) { allowedVersions = VersionRange.All; allVersionsAllowed = allVersions; } else { allVersionsAllowed = allVersions.Where(v => allowedVersions.Satisfies(v.version)).ToList(); foreach ((NuGetVersion version, bool isDeprecated) in allVersions) { if (!allVersionsAllowed.Any(a => a.version.Version.Equals(version.Version))) { blockedVersions.Add(version); } } } var latestPrerelease = allVersionsAllowed.FirstOrDefault(v => v.version.IsPrerelease); var latestStableVersion = allVersionsAllowed.FirstOrDefault(v => !v.version.IsPrerelease); // Add installed version if the project is PackageReference if (_nugetProjects.Any() && installedDependency != null && installedDependency.VersionRange != null && _nugetProjects.First().ProjectStyle.Equals(ProjectModel.ProjectStyle.PackageReference)) { VersionRange installedVersionRange = VersionRange.Parse(installedDependency.VersionRange.OriginalString, true); NuGetVersion bestVersion = installedVersionRange.FindBestMatch(allVersionsAllowed.Select(v => v.version)); var deprecationInfo = allVersionsAllowed.FirstOrDefault(v => v.version == bestVersion).isDeprecated; DisplayVersion displayVersion = new DisplayVersion(installedVersionRange, bestVersion, additionalInfo: string.Empty, isDeprecated: deprecationInfo); _versions.Add(displayVersion); } var isInstalledFloatingOrRange = installedVersion != null && installedVersion.IsFloating || (installedVersion?.OriginalString != null && (installedVersion.OriginalString.StartsWith("(", StringComparison.OrdinalIgnoreCase) || installedVersion.OriginalString.StartsWith("[", StringComparison.OrdinalIgnoreCase))); // Add latest prerelease if neeeded if (latestPrerelease.version != null && (latestStableVersion.version == null || latestPrerelease.version > latestStableVersion.version) && (isInstalledFloatingOrRange || !latestPrerelease.version.Equals(installedVersion?.MinVersion))) { VersionRange latestPrereleaseVersionRange = VersionRange.Parse(latestPrerelease.version.ToString(), allowFloating: false); _versions.Add(new DisplayVersion(latestPrereleaseVersionRange, latestPrerelease.version, Resources.Version_LatestPrerelease, isDeprecated: latestPrerelease.isDeprecated)); } // Add latest stable if needed if (latestStableVersion.version != null && (isInstalledFloatingOrRange || !latestStableVersion.version.Equals(InstalledVersion))) { VersionRange latestStableVersionRange = VersionRange.Parse(latestStableVersion.version.ToString(), allowFloating: false); _versions.Add(new DisplayVersion(latestStableVersionRange, latestStableVersion.version, Resources.Version_LatestStable, isDeprecated: latestStableVersion.isDeprecated)); } // add a separator if (_versions.Count > 0) { _versions.Add(null); } // first add all the available versions to be updated foreach (var version in allVersionsAllowed) { var installed = version.version.Equals(InstalledVersion); var autoReferenced = false; if (installed && _projectVersionConstraints.Any(e => e.IsAutoReferenced && e.VersionRange?.Satisfies(version.version) == true)) { // do not allow auto referenced packages autoReferenced = true; } VersionRange versionRange = VersionRange.Parse(version.version.ToString(), allowFloating: false); _versions.Add(new DisplayVersion(versionRange, version.version, additionalInfo: null, isCurrentInstalled: installed, autoReferenced: autoReferenced, isDeprecated: version.isDeprecated)); } // Disable controls if this is an auto referenced package. SetAutoReferencedCheck(InstalledVersion); // Add disabled versions AddBlockedVersions(blockedVersions); var latestVersion = latestPrerelease.version > latestStableVersion.version ? latestPrerelease.version : latestStableVersion.version; SelectVersion(latestVersion); return(Task.CompletedTask); }