using System; using System.Collections.Generic; using System.Linq; using isnd.Data.Packages; using Newtonsoft.Json; using NuGet.Versioning; namespace isnd.Data.Catalog { public class RegistrationPage { [JsonProperty("@id")] [JsonRequired] public string Id { get; protected set;} private readonly string pkgid; private readonly List items; protected string Bid { get ; private set; } protected string DlBase { get; } public RegistrationPage (string bid, string dlBase) { Bid = bid; DlBase = dlBase; this.items = new List(); } public RegistrationPage (string bid, string pkgid, string dlBase, IEnumerable items) { Bid = bid; Parent = Bid + $"/{pkgid}/index.json"; DlBase = dlBase; this.items = new List(items); this.Id = Bid + "/" + pkgid + "/index.json"; this.pkgid = pkgid; UpdateCompact(); } public string GetPackageId() { return pkgid; } private void UpdateCompact() { 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(); } /// /// no The array of registration leaves and their associate metadata /// /// [JsonProperty("items")] public RegistrationLeaf[] Items { get => items.Select((p) => p.ToLeave(Bid, DlBase)).ToArray(); } public void AddVersionRange(IEnumerable vitems) { if (vitems.Count() == 0) return; items.AddRange(vitems); UpdateCompact(); } /// /// The highest SemVer 2.0.0 version in the page (inclusive) /// /// [JsonProperty("upper"), JsonRequired] public string Upper { get; private set; } /// /// The lowest SemVer 2.0.0 version in the page (inclusive) /// /// [JsonProperty("lower"), JsonRequired] public string Lower { get; private set; } /// /// The URL to the registration index /// /// [JsonProperty("parent")] public string Parent { get; set; } [JsonProperty("count")] public int Count { get; internal set; } public string CommitId { get; internal set; } public DateTime CommitTimeStamp { get; internal set; } } }