A valid package index page
This commit is contained in:
parent
88c8480911
commit
58f77a06ea
15 changed files with 210 additions and 153 deletions
|
|
@ -1,18 +1,62 @@
|
|||
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
|
||||
public class RegistrationPage
|
||||
{
|
||||
[JsonProperty("@id")]
|
||||
[JsonRequired]
|
||||
public string Id { get; }
|
||||
public RegistrationPage (string id)
|
||||
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)
|
||||
{
|
||||
Id = id;
|
||||
Items = new List<RegistrationLeaf>();
|
||||
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()
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -21,19 +65,26 @@ namespace isnd.Data.Catalog
|
|||
/// <value></value>
|
||||
[JsonProperty("items")]
|
||||
|
||||
public List<RegistrationLeaf> Items { get; set; }
|
||||
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();
|
||||
}
|
||||
/// <summary>
|
||||
/// The highest SemVer 2.0.0 version in the page (inclusive)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("upper"), JsonRequired]
|
||||
public Version Upper { get; set; }
|
||||
public string Upper { get; private set; }
|
||||
/// <summary>
|
||||
/// The lowest SemVer 2.0.0 version in the page (inclusive)
|
||||
/// </summary>
|
||||
/// <value></value>
|
||||
[JsonProperty("lower"), JsonRequired]
|
||||
public Version Lower { get; set; }
|
||||
public string Lower { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The URL to the registration index
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue