public PackageViewModel(Package package) { _package = package ?? throw new ArgumentNullException(nameof(package)); FullVersion = NuGetVersionFormatter.ToFullString(package.Version); IsSemVer2 = package.SemVerLevelKey == SemVerLevelKey.SemVer2; Version = String.IsNullOrEmpty(package.NormalizedVersion) ? NuGetVersionFormatter.Normalize(package.Version) : package.NormalizedVersion; NuGetVersion = NuGetVersion.Parse(FullVersion); Description = package.Description; ReleaseNotes = package.ReleaseNotes; IconUrl = package.IconUrl; LatestVersion = package.IsLatest; LatestVersionSemVer2 = package.IsLatestSemVer2; LatestStableVersion = package.IsLatestStable; LatestStableVersionSemVer2 = package.IsLatestStableSemVer2; DevelopmentDependency = package.DevelopmentDependency; LastUpdated = package.Published; Listed = package.Listed; _packageStatus = package.PackageStatusKey; DownloadCount = package.DownloadCount; Prerelease = package.IsPrerelease; }
private DisplayPackageViewModel SetupCommon( DisplayPackageViewModel viewModel, Package package, string pushedBy, IReadOnlyDictionary <int, PackageDeprecation> packageKeyToDeprecation) { viewModel.NuGetVersion = NuGetVersion.Parse(NuGetVersionFormatter.ToFullString(package.Version)); viewModel.Copyright = package.Copyright; viewModel.DownloadCount = package.DownloadCount; viewModel.LastEdited = package.LastEdited; viewModel.TotalDaysSinceCreated = 0; viewModel.DownloadsPerDay = 0; viewModel.PushedBy = pushedBy; viewModel.InitializeRepositoryMetadata(package.RepositoryUrl, package.RepositoryType); if (PackageHelper.TryPrepareUrlForRendering(package.ProjectUrl, out string projectUrl)) { viewModel.ProjectUrl = projectUrl; } viewModel.EmbeddedLicenseType = package.EmbeddedLicenseType; viewModel.LicenseExpression = package.LicenseExpression; if (PackageHelper.TryPrepareUrlForRendering(package.LicenseUrl, out string licenseUrl)) { viewModel.LicenseUrl = licenseUrl; var licenseNames = package.LicenseNames; if (!string.IsNullOrEmpty(licenseNames)) { viewModel.LicenseNames = licenseNames.Split(',').Select(l => l.Trim()).ToList(); } } if (packageKeyToDeprecation != null && packageKeyToDeprecation.TryGetValue(package.Key, out var deprecation)) { viewModel.DeprecationStatus = deprecation.Status; } else { viewModel.DeprecationStatus = PackageDeprecationStatus.NotDeprecated; } return(viewModel); }
public PackageViewModel Setup(PackageViewModel viewModel, Package package) { if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } if (package == null) { throw new ArgumentNullException(nameof(package)); } viewModel.FullVersion = NuGetVersionFormatter.ToFullString(package.Version); viewModel.IsSemVer2 = package.SemVerLevelKey == SemVerLevelKey.SemVer2; viewModel.Id = package.PackageRegistration.Id; viewModel.Version = String.IsNullOrEmpty(package.NormalizedVersion) ? NuGetVersionFormatter.Normalize(package.Version) : package.NormalizedVersion; viewModel.Description = package.Description; viewModel.ReleaseNotes = package.ReleaseNotes; viewModel.IconUrl = _iconUrlProvider.GetIconUrlString(package); viewModel.LatestVersion = package.IsLatest; viewModel.LatestVersionSemVer2 = package.IsLatestSemVer2; viewModel.LatestStableVersion = package.IsLatestStable; viewModel.LatestStableVersionSemVer2 = package.IsLatestStableSemVer2; viewModel.DevelopmentDependency = package.DevelopmentDependency; viewModel.LastUpdated = package.Published; viewModel.Listed = package.Listed; viewModel.DownloadCount = package.DownloadCount; viewModel.Prerelease = package.IsPrerelease; viewModel.FailedValidation = package.PackageStatusKey == PackageStatus.FailedValidation; viewModel.Available = package.PackageStatusKey == PackageStatus.Available; viewModel.Validating = package.PackageStatusKey == PackageStatus.Validating; viewModel.Deleted = package.PackageStatusKey == PackageStatus.Deleted; viewModel.PackageStatusSummary = GetPackageStatusSummary(package.PackageStatusKey, package.Listed); viewModel.TotalDownloadCount = package.PackageRegistration.DownloadCount; return(viewModel); }
public static string GetSelectListText(Package package) { var tags = new List <string>(); if (package.IsLatestSemVer2) { tags.Add("Latest"); } var deprecation = package.Deprecations.SingleOrDefault(); if (deprecation != null) { var deprecationReasons = new List <string>(); if (deprecation.Status.HasFlag(PackageDeprecationStatus.Legacy)) { deprecationReasons.Add("Legacy"); } if (deprecation.Status.HasFlag(PackageDeprecationStatus.CriticalBugs)) { deprecationReasons.Add("Critical Bugs"); } if (deprecation.Status.HasFlag(PackageDeprecationStatus.Other)) { deprecationReasons.Add("Other"); } if (deprecationReasons.Any()) { tags.Add("Deprecated - " + string.Join(", ", deprecationReasons)); } } return(NuGetVersionFormatter.ToFullString(package.Version) + (tags.Any() ? $" ({string.Join(", ", tags)})" : string.Empty)); }
private DisplayPackageViewModel SetupCommon( DisplayPackageViewModel viewModel, Package package, string pushedBy, IReadOnlyDictionary <int, PackageDeprecation> packageKeyToDeprecation, IReadOnlyDictionary <int, IReadOnlyList <PackageVulnerability> > packageKeyToVulnerabilities) { viewModel.NuGetVersion = NuGetVersion.Parse(NuGetVersionFormatter.ToFullString(package.Version)); viewModel.Copyright = package.Copyright; viewModel.DownloadCount = package.DownloadCount; viewModel.LastEdited = package.LastEdited; viewModel.TotalDaysSinceCreated = 0; viewModel.DownloadsPerDay = 0; viewModel.PushedBy = pushedBy; viewModel.InitializeRepositoryMetadata(package.RepositoryUrl, package.RepositoryType); if (PackageHelper.TryPrepareUrlForRendering(package.ProjectUrl, out string projectUrl)) { viewModel.ProjectUrl = projectUrl; } var fugetUrl = $"https://www.fuget.org/packages/{package.Id}/{package.NormalizedVersion}"; if (PackageHelper.TryPrepareUrlForRendering(fugetUrl, out string fugetReadyUrl)) { viewModel.FuGetUrl = fugetReadyUrl; } viewModel.EmbeddedLicenseType = package.EmbeddedLicenseType; viewModel.LicenseExpression = package.LicenseExpression; if (PackageHelper.TryPrepareUrlForRendering(package.LicenseUrl, out string licenseUrl)) { viewModel.LicenseUrl = licenseUrl; var licenseNames = package.LicenseNames; if (!string.IsNullOrEmpty(licenseNames)) { viewModel.LicenseNames = licenseNames.Split(',').Select(l => l.Trim()).ToList(); } } PackageDeprecation deprecation = null; if (packageKeyToDeprecation != null && packageKeyToDeprecation.TryGetValue(package.Key, out deprecation)) { viewModel.DeprecationStatus = deprecation.Status; } else { viewModel.DeprecationStatus = PackageDeprecationStatus.NotDeprecated; } PackageVulnerabilitySeverity?maxVulnerabilitySeverity = null; if (packageKeyToVulnerabilities != null && packageKeyToVulnerabilities.TryGetValue(package.Key, out var vulnerabilities) && vulnerabilities != null && vulnerabilities.Any()) { viewModel.Vulnerabilities = vulnerabilities; maxVulnerabilitySeverity = viewModel.Vulnerabilities.Max(v => v.Severity); // cache for messaging viewModel.MaxVulnerabilitySeverity = maxVulnerabilitySeverity.Value; } else { viewModel.Vulnerabilities = null; viewModel.MaxVulnerabilitySeverity = default; } viewModel.PackageWarningIconTitle = GetWarningIconTitle(viewModel.Version, deprecation, maxVulnerabilitySeverity); return(viewModel); }