isn/src/isnd/Data/Catalog/RegistrationPage.cs

101 lines
3 KiB
C#
Raw Normal View History

2022-09-23 20:34:51 +01:00
using System;
2022-09-25 02:24:21 +01:00
using System.Collections.Generic;
2022-10-15 18:26:55 +01:00
using System.Linq;
using isnd.Data.Packages;
2022-09-23 20:34:51 +01:00
using Newtonsoft.Json;
2022-10-15 18:26:55 +01:00
using NuGet.Versioning;
2022-09-23 20:34:51 +01:00
namespace isnd.Data.Catalog
{
2022-10-15 18:26:55 +01:00
public class RegistrationPage
2022-09-23 20:34:51 +01:00
{
2022-09-25 02:24:21 +01:00
[JsonProperty("@id")]
[JsonRequired]
2022-10-15 18:26:55 +01:00
public string Id { get; protected set;}
private List<PackageVersion> items;
protected string Bid { get ; private set; }
public string DlBase { get; }
public RegistrationPage (string bid, string dlBase)
{
Bid = bid;
DlBase = dlBase;
this.items = new List<PackageVersion>();
}
public RegistrationPage (string bid, string pkgid, string dlBase, IEnumerable<PackageVersion> items)
{
Bid = bid;
Parent = Bid + "/index.json";
DlBase = dlBase;
this.items = new List<PackageVersion>(items);
SetPackageId(pkgid);
UpdateCompact();
}
protected void SetPackageId(string pkgid)
{
this.Id = Bid + "/" + pkgid + "/index.json";
}
private void UpdateCompact()
2022-09-25 02:24:21 +01:00
{
2022-10-15 18:26:55 +01:00
NuGetVersion upper = new NuGetVersion(0,0,0);
// Assert.True(items.All(p=>p.Id == id));
foreach (var p in items)
{
if (upper < p.NugetVersion) upper = p.NugetVersion;
}
Upper = upper.ToFullString();
NuGetVersion lower = upper;
foreach (var p in items)
{
if (lower > p.NugetVersion) lower = p.NugetVersion;
}
Lower = lower.ToFullString();
2022-09-25 02:24:21 +01:00
}
2022-09-23 20:34:51 +01:00
/// <summary>
/// no The array of registration leaves and their associate metadata
/// </summary>
/// <value></value>
[JsonProperty("items")]
2022-10-15 18:26:55 +01:00
public RegistrationLeaf[] Items { get => items.Select((p) => p.ToLeave(Bid, DlBase)).ToArray(); }
public void AddVersionRange(IEnumerable<PackageVersion> vitems)
{
if (vitems.Count() == 0) return;
items.AddRange(vitems);
UpdateCompact();
}
2022-09-23 20:34:51 +01:00
/// <summary>
/// The highest SemVer 2.0.0 version in the page (inclusive)
/// </summary>
/// <value></value>
[JsonProperty("upper"), JsonRequired]
2022-10-15 18:26:55 +01:00
public string Upper { get; private set; }
2022-09-23 20:34:51 +01:00
/// <summary>
/// The lowest SemVer 2.0.0 version in the page (inclusive)
/// </summary>
/// <value></value>
[JsonProperty("lower"), JsonRequired]
2022-10-15 18:26:55 +01:00
public string Lower { get; private set; }
2022-09-23 20:34:51 +01:00
/// <summary>
/// The URL to the registration index
/// </summary>
/// <value></value>
[JsonProperty("parent")]
public string Parent { get; set; }
2022-09-25 02:24:21 +01:00
[JsonProperty("count")]
public int Count { get; internal set; }
public string CommitId { get; internal set; }
public DateTime CommitTimeStamp { get; internal set; }
2022-09-23 20:34:51 +01:00
}
}