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

53 lines
1.6 KiB
C#

3 years ago
using isnd.Data.Packages;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
namespace isnd.Data.Catalog
{
3 years ago
public class PackageRegistration : Permalink
3 years ago
{
3 years ago
public PackageRegistration(string url) : base(url)
3 years ago
{
3 years ago
Items = new List<CatalogPage>();
3 years ago
}
3 years ago
public PackageRegistration(string bid, string id, string apiBase, IEnumerable<Packages.Package> pkgs) : base(bid + $"/{id}/index.json")
3 years ago
{
3 years ago
Items = new List<CatalogPage>();
3 years ago
long cnid = 0;
var pkgsGroups = pkgs.GroupBy(l => l.Id);
// Pour tous les groupes par Id
foreach (var gsp in pkgsGroups)
{
var pkgsbi = gsp.ToArray();
List<PackageVersion> versions = new List<PackageVersion>();
foreach(var l in pkgsbi.Select(p => p.Versions))
{
versions.AddRange(l);
foreach (var pv in l)
{
if (pv.CommitNId> cnid)
{
cnid = pv.CommitNId;
}
}
}
3 years ago
Items.Add(new CatalogPage(bid, gsp.Key, apiBase, versions));
3 years ago
}
CommitId = cnid.ToString();
}
[JsonProperty("count")]
public int Count { get => Items.Count; }
[JsonProperty("items")]
3 years ago
public List<CatalogPage> Items { get; set; }
3 years ago
public string CommitId { get; set; }
3 years ago
public DateTimeOffset CommitTimeStamp { get; internal set; }
3 years ago
}
}