public DisplayPackageViewModel(Package package, User currentUser, IOrderedEnumerable <Package> packageHistory) : this(package, currentUser, (string)null) { HasSemVer2Version = NuGetVersion.IsSemVer2; HasSemVer2Dependency = package.Dependencies.ToList() .Where(pd => !string.IsNullOrEmpty(pd.VersionSpec)) .Select(pd => VersionRange.Parse(pd.VersionSpec)) .Any(p => (p.HasUpperBound && p.MaxVersion.IsSemVer2) || (p.HasLowerBound && p.MinVersion.IsSemVer2)); Dependencies = new DependencySetsViewModel(package.Dependencies); PackageVersions = packageHistory.Select(p => new DisplayPackageViewModel(p, currentUser, GetPushedBy(p, currentUser))); PushedBy = GetPushedBy(package, currentUser); PackageFileSize = package.PackageFileSize; LatestSymbolsPackage = package.LatestSymbolPackage(); if (packageHistory.Any()) { // calculate the number of days since the package registration was created // round to the nearest integer, with a min value of 1 // divide the total download count by this number TotalDaysSinceCreated = Convert.ToInt32(Math.Max(1, Math.Round((DateTime.UtcNow - packageHistory.Min(p => p.Created)).TotalDays))); DownloadsPerDay = TotalDownloadCount / TotalDaysSinceCreated; // for the package DownloadsPerDayLabel = DownloadsPerDay < 1 ? "<1" : DownloadsPerDay.ToNuGetNumberString(); IsDotnetToolPackageType = package.PackageTypes.Any(e => e.Name.Equals("DotnetTool", StringComparison.OrdinalIgnoreCase)); } }
public DisplayPackageViewModel(Package package, IOrderedEnumerable <Package> packageHistory, bool isVersionHistory) : base(package) { Copyright = package.Copyright; if (!isVersionHistory) { Dependencies = new DependencySetsViewModel(package.Dependencies); PackageVersions = packageHistory.Select(p => new DisplayPackageViewModel(p, packageHistory, isVersionHistory: true)); } DownloadCount = package.DownloadCount; LastEdited = package.LastEdited; if (!isVersionHistory && packageHistory.Any()) { // calculate the number of days since the package registration was created // round to the nearest integer, with a min value of 1 // divide the total download count by this number TotalDaysSinceCreated = Convert.ToInt32(Math.Max(1, Math.Round((DateTime.UtcNow - packageHistory.Last().Created).TotalDays))); DownloadsPerDay = TotalDownloadCount / TotalDaysSinceCreated; // for the package } else { TotalDaysSinceCreated = 0; DownloadsPerDay = 0; } DownloadsPerDayLabel = DownloadsPerDay < 1 ? "<1" : DownloadsPerDay.ToNuGetNumberString(); }
public DisplayPackageViewModel(Package package, User currentUser, PackageDeprecation deprecation) : this(package, currentUser, (string)null) { HasSemVer2Version = NuGetVersion.IsSemVer2; HasSemVer2Dependency = package.Dependencies.ToList() .Where(pd => !string.IsNullOrEmpty(pd.VersionSpec)) .Select(pd => VersionRange.Parse(pd.VersionSpec)) .Any(p => (p.HasUpperBound && p.MaxVersion.IsSemVer2) || (p.HasLowerBound && p.MinVersion.IsSemVer2)); Dependencies = new DependencySetsViewModel(package.Dependencies); var packageHistory = package .PackageRegistration .Packages .OrderByDescending(p => new NuGetVersion(p.Version)) .ToList(); PackageVersions = packageHistory.Select(p => new DisplayPackageViewModel(p, currentUser, GetPushedBy(p, currentUser))).ToList(); PushedBy = GetPushedBy(package, currentUser); PackageFileSize = package.PackageFileSize; LatestSymbolsPackage = package.LatestSymbolPackage(); LatestAvailableSymbolsPackage = LatestSymbolsPackage != null && LatestSymbolsPackage.StatusKey == PackageStatus.Available ? LatestSymbolsPackage : package.LatestAvailableSymbolPackage(); if (packageHistory.Any()) { // calculate the number of days since the package registration was created // round to the nearest integer, with a min value of 1 // divide the total download count by this number TotalDaysSinceCreated = Convert.ToInt32(Math.Max(1, Math.Round((DateTime.UtcNow - packageHistory.Min(p => p.Created)).TotalDays))); DownloadsPerDay = TotalDownloadCount / TotalDaysSinceCreated; // for the package DownloadsPerDayLabel = DownloadsPerDay < 1 ? "<1" : DownloadsPerDay.ToNuGetNumberString(); IsDotnetToolPackageType = package.PackageTypes.Any(e => e.Name.Equals("DotnetTool", StringComparison.OrdinalIgnoreCase)); } if (deprecation != null) { AlternatePackageId = deprecation.AlternatePackageRegistration?.Id; var alternatePackage = deprecation.AlternatePackage; if (alternatePackage != null) { // A deprecation should not have both an alternate package registration and an alternate package. // In case a deprecation does have both, we will hide the alternate package registration's ID in this model. AlternatePackageId = alternatePackage?.Id; AlternatePackageVersion = alternatePackage?.Version; } CustomMessage = deprecation.CustomMessage; } }
public DisplayPackageViewModel(Package package, User currentUser, IOrderedEnumerable <Package> packageHistory, bool isVersionHistory) : base(package, currentUser) { Copyright = package.Copyright; if (!isVersionHistory) { HasSemVer2Version = NuGetVersion.IsSemVer2; HasSemVer2Dependency = package.Dependencies.ToList() .Where(pd => !string.IsNullOrEmpty(pd.VersionSpec)) .Select(pd => VersionRange.Parse(pd.VersionSpec)) .Any(p => (p.HasUpperBound && p.MaxVersion.IsSemVer2) || (p.HasLowerBound && p.MinVersion.IsSemVer2)); Dependencies = new DependencySetsViewModel(package.Dependencies); PackageVersions = packageHistory.Select(p => new DisplayPackageViewModel(p, currentUser, packageHistory, isVersionHistory: true)); } DownloadCount = package.DownloadCount; LastEdited = package.LastEdited; if (!isVersionHistory && packageHistory.Any()) { // calculate the number of days since the package registration was created // round to the nearest integer, with a min value of 1 // divide the total download count by this number TotalDaysSinceCreated = Convert.ToInt32(Math.Max(1, Math.Round((DateTime.UtcNow - packageHistory.Min(p => p.Created)).TotalDays))); DownloadsPerDay = TotalDownloadCount / TotalDaysSinceCreated; // for the package } else { TotalDaysSinceCreated = 0; DownloadsPerDay = 0; } DownloadsPerDayLabel = DownloadsPerDay < 1 ? "<1" : DownloadsPerDay.ToNuGetNumberString(); }