Catalog
This commit is contained in:
@ -1,23 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using isnd.Controllers;
|
||||
using isnd.Data;
|
||||
using isnd.Data.Catalog;
|
||||
using isnd.Entities;
|
||||
using isnd.Interfaces;
|
||||
using isnd.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Options;
|
||||
using NuGet.Versioning;
|
||||
using Unleash;
|
||||
|
||||
namespace isnd.Services
|
||||
{
|
||||
public class PackageManager
|
||||
|
||||
|
||||
public class PackageManager : IPackageManager
|
||||
{
|
||||
ApplicationDbContext dbContext;
|
||||
public PackageManager(ApplicationDbContext dbContext)
|
||||
public PackageManager(ApplicationDbContext dbContext, IOptions<IsndSettings> pmConfigOptions)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
CurrentCatalogIndex = GetCatalogIndex();
|
||||
this.pmConfigOptions = pmConfigOptions.Value;
|
||||
}
|
||||
public PackageIndexViewModel SearchByName(string query,
|
||||
int skip, int take,bool prerelease = false,
|
||||
|
||||
|
||||
public PackageIndexViewModel SearchByName(string query,
|
||||
int skip, int take, bool prerelease = false,
|
||||
string packageType = null)
|
||||
{
|
||||
|
||||
@ -32,14 +43,63 @@ namespace isnd.Services
|
||||
var pkgs = scope.Skip(skip).Take(take).ToArray();
|
||||
|
||||
return new PackageIndexViewModel
|
||||
{
|
||||
query = query,
|
||||
totalHits = total,
|
||||
data = pkgs
|
||||
};
|
||||
{
|
||||
query = query,
|
||||
totalHits = total,
|
||||
data = pkgs
|
||||
};
|
||||
}
|
||||
public AutoCompleteResult AutoComplete (string id,
|
||||
int skip, int take, bool prerelease = false,
|
||||
const int maxPageLen = 512;
|
||||
|
||||
public CatalogIndex GenerateCatalogIndex(string commitId)
|
||||
{
|
||||
|
||||
var root = "/index.json";
|
||||
|
||||
|
||||
var catalog = new CatalogIndex
|
||||
{
|
||||
CommitId = commitId,
|
||||
CommitTimeStamp = DateTime.Now
|
||||
};
|
||||
var scope = dbContext.Packages.Where(p => p.Public)
|
||||
.OrderBy(p => p.CommitTimeStamp);
|
||||
catalog.Items = new List<PageRef>();
|
||||
|
||||
int pagecount = (int)(scope.Count() / maxPageLen);
|
||||
|
||||
for (int pagelen = 0, pagenum = 0; pagelen < pagecount; pagenum++)
|
||||
{
|
||||
Page p = new Page
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
dbContext.Packages.Where(p => p.Public)
|
||||
.OrderBy(p => p.CommitTimeStamp);
|
||||
return catalog;
|
||||
|
||||
}
|
||||
public Page CatalogPage()
|
||||
{
|
||||
var scope = dbContext.Packages
|
||||
.Where(P => P.Versions.Count > 0)
|
||||
.Select(
|
||||
p => new PackageRef { Id = p.Id, Version = p.Versions.Max().FullString });
|
||||
|
||||
return new Page
|
||||
{
|
||||
Items = scope.ToList()
|
||||
};
|
||||
}
|
||||
public void PublishCatalog()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public AutoCompleteResult AutoComplete(string id,
|
||||
int skip, int take, bool prerelease = false,
|
||||
string packageType = null)
|
||||
{
|
||||
var scope = dbContext.PackageVersions.Where(
|
||||
@ -49,11 +109,11 @@ namespace isnd.Services
|
||||
)
|
||||
.OrderBy(v => v.FullString);
|
||||
return new AutoCompleteResult
|
||||
{
|
||||
totalHits = scope.Count(),
|
||||
data = scope.Select(v => v.FullString)
|
||||
{
|
||||
totalHits = scope.Count(),
|
||||
data = scope.Select(v => v.FullString)
|
||||
.Skip(skip).Take(take).ToArray()
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// TODO stocker MetaData plutôt que FullString en base,
|
||||
@ -77,11 +137,28 @@ namespace isnd.Services
|
||||
.Skip(skip).Take(take).ToArray();
|
||||
}
|
||||
|
||||
protected static bool CamelCaseMatch(string id, string q)
|
||||
public static CatalogIndex CurrentCatalogIndex { get; protected set; }
|
||||
|
||||
private IsndSettings pmConfigOptions;
|
||||
|
||||
public virtual CatalogIndex GetCatalogIndex()
|
||||
{
|
||||
if (CurrentCatalogIndex == null)
|
||||
{
|
||||
LoadCatalogFromDb();
|
||||
}
|
||||
return CurrentCatalogIndex;
|
||||
}
|
||||
void LoadCatalogFromDb()
|
||||
{
|
||||
dbContext.Commits.OrderBy(c => c.TimeStamp);
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
protected static bool CamelCaseMatch(string id, string query)
|
||||
{
|
||||
// Assert.False (q==null);
|
||||
string query = q;
|
||||
if (query.Length == 0) return false;
|
||||
if (string.IsNullOrEmpty(query)) return true;
|
||||
|
||||
while (id.Length > 0)
|
||||
{
|
||||
@ -89,7 +166,7 @@ namespace isnd.Services
|
||||
while (id.Length > i && char.IsLower(id[i])) i++;
|
||||
if (i == 0) break;
|
||||
id = id.Substring(i);
|
||||
if (id.StartsWith(q, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||
if (id.StartsWith(query, System.StringComparison.OrdinalIgnoreCase)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -102,7 +179,7 @@ namespace isnd.Services
|
||||
return false;
|
||||
}
|
||||
|
||||
internal List<Resource> GetResources(IUnleash unleashClient)
|
||||
public IEnumerable<Resource> GetResources(IUnleash unleashClient)
|
||||
{
|
||||
var res = new List<Resource>();
|
||||
if (unleashClient.IsEnabled("pkg-push"))
|
||||
@ -125,7 +202,7 @@ namespace isnd.Services
|
||||
res.Add(
|
||||
new Resource
|
||||
{
|
||||
id = "package/index.json",
|
||||
id = "package",
|
||||
type = "SearchAutocompleteService/3.5.0",
|
||||
comment = "Auto complete service"
|
||||
});
|
||||
@ -133,7 +210,7 @@ namespace isnd.Services
|
||||
res.Add(
|
||||
new Resource
|
||||
{
|
||||
id = "package/index.json",
|
||||
id = "package",
|
||||
type = "SearchQueryService/3.5.0",
|
||||
comment = "Search Query service"
|
||||
});
|
||||
|
Reference in New Issue
Block a user