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

103 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;}
2023-01-29 13:04:50 +00:00
private readonly string pkgid;
private readonly List<PackageVersion> items;
2022-10-15 18:26:55 +01:00
protected string Bid { get ; private set; }
2022-10-17 19:17:04 +01:00
protected string DlBase { get; }
2022-10-15 18:26:55 +01:00
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;
2022-12-11 14:54:47 +00:00
Parent = Bid + $"/{pkgid}/index.json";
2022-10-15 18:26:55 +01:00
DlBase = dlBase;
this.items = new List<PackageVersion>(items);
2022-10-17 19:17:04 +01:00
this.Id = Bid + "/" + pkgid + "/index.json";
this.pkgid = pkgid;
2022-10-15 18:26:55 +01:00
UpdateCompact();
}
2022-10-17 19:17:04 +01:00
public string GetPackageId()
2022-10-15 18:26:55 +01:00
{
2022-10-17 19:17:04 +01:00
return pkgid;
2022-10-15 18:26:55 +01:00
}
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
}
}