@ -31,7 +31,6 @@ namespace isnd.Services
this . dbContext = dbContext ;
isndSettings = siteConfigOptionsOptions . Value ;
extUrl = isndSettings . ExternalUrl + "/" ;
CurrentCatalogIndex = GetCatalogIndex ( ) ;
}
public IEnumerable < Resource > GetResources ( IUnleash unleashClient )
@ -55,9 +54,9 @@ namespace isnd.Services
{
Id = extUrl + ApiConfig . GetPackage ,
Type = "PackageBaseAddress/3.0.0" ,
Comment = "Package Base Address service"
Comment = @ "Package Base Address service - Base URL of where NuGet packages are stored, in the format https://<host>/nupkg/{id-lower}/{version-lower}/{id-lower}.{version-lower}.nupkg "
} ) ;
if ( unleashClient . IsEnabled ( "pkg-autocomplete" , tru e) )
if ( unleashClient . IsEnabled ( "pkg-autocomplete" , fals e) )
res . Add (
new Resource
{
@ -65,7 +64,7 @@ namespace isnd.Services
Type = "SearchAutocompleteService/" + BASE_API_LEVEL ,
Comment = "Auto complete service"
} ) ;
if ( unleashClient . IsEnabled ( "pkg-search" , tru e) )
if ( unleashClient . IsEnabled ( "pkg-search" , fals e) )
res . Add (
new Resource
{
@ -73,7 +72,7 @@ namespace isnd.Services
Type = "SearchQueryService/" + BASE_API_LEVEL ,
Comment = "Search Query service"
} ) ;
if ( unleashClient . IsEnabled ( "pkg-catalog" , tru e) )
if ( unleashClient . IsEnabled ( "pkg-catalog" , fals e) )
res . Add (
new Resource
{
@ -86,7 +85,7 @@ namespace isnd.Services
res . Add (
new Resource
{
Id = extUrl + "v " + BASE_API_LEVEL + " /" + ApiConfig . Registration ,
Id = extUrl + "v 3.0.0 /" + ApiConfig . Registration ,
Type = "RegistrationsBaseUrl" ,
Comment = "Base URL of storage where isn package registration info is stored in GZIP format. This base URL includes SemVer 2.0.0 packages."
} ) ;
@ -161,32 +160,27 @@ namespace isnd.Services
. Skip ( skip ) . Take ( take ) . ToArray ( ) ;
}
public static RegistrationPageIndex CurrentCatalogIndex { get ; protected set ; }
public static List < RegistrationPage > CurrentCatalogPages { get ; protected set ; }
public string CatalogBaseUrl = > extUrl ;
private IsndSettings isndSettings ;
private string extUrl ;
public virtual RegistrationPageIndex GetCatalogIndex ( )
public virtual async Task < RegistrationPageIndex > GetCatalogIndexAsync ( )
{
if ( CurrentCatalogIndex = = null )
{
Û pdateCatalogFor ( ) ;
}
return CurrentCatalogIndex ;
return await Û pdateCatalogForAsync ( null ) ;
}
public void Û pdateCatalogFor ( Commit reason = null )
public async Task < RegistrationPageIndex > Û pdateCatalogForAsync ( Commit reason = null )
{
int i = 0 ;
var oldIndex = CurrentCatalogIndex ;
var oldPages = CurrentCatalogPages ;
string baseid = extUrl + ApiConfig . Catalog ;
string bidreg = $"{extUrl}v3.4.0/{ApiConfig.Registration}" ;
string basepageid = extUrl + ApiConfig . CatalogPage ;
CurrentCatalogIndex = new RegistrationPageIndex ( ) ;
CurrentCatalogPages = new List < RegistrationPage > ( ) ;
RegistrationPageIndex CurrentCatalogIndex = new RegistrationPageIndex ( ) ;
List< RegistrationPage > CurrentCatalogPages = new List < RegistrationPage > ( ) ;
var scope = dbContext . Commits . OrderBy ( c = > c . TimeStamp ) ;
@ -210,13 +204,12 @@ namespace isnd.Services
CurrentCatalogIndex . Items . Add ( pageRef ) ;
i = 0 ;
}
var validPkgs = dbContext . Packages
var validPkgs = dbContext . Packages
. Include ( po = > po . Owner )
. Include ( pkg = > pkg . Versions )
. Include ( pkg = > pkg . LatestVersion )
. Where (
pkg = > pkg . Versions . Count ( v = > v . CommitId = = commit . CommitId ) > 0
) . GroupBy ( ( q ) = > q . Id ) ;
. ToList ( )
. GroupBy ( ( q ) = > q . Id ) ;
// pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString
foreach ( var pkgid in validPkgs )
{
@ -251,6 +244,7 @@ namespace isnd.Services
// From a fresh db
CurrentCatalogIndex . CommitId = "none" ;
}
return CurrentCatalogIndex ;
}
public async Task < PackageDeletionReport > DeletePackageAsync ( string pkgid , string version , string type )
@ -273,7 +267,7 @@ namespace isnd.Services
}
dbContext . PackageVersions . Remove ( pkg ) ;
await dbContext . SaveChangesAsync ( ) ;
Û pdateCatalogFor ( commit ) ;
await Û pdateCatalogFor Async ( commit ) ;
return new PackageDeletionReport { Deleted = true , DeletedVersion = pkg } ;
}
@ -330,13 +324,11 @@ namespace isnd.Services
& & ( pkgType = = null | | pkgType = = v . Type ) ) ;
}
public RegistrationPageIndex GetPackageRegistrationIndex ( RegistrationPageIndexQuery query )
public async Task < RegistrationPageIndex > GetPackageRegistrationIndex Async ( RegistrationPageIndexQuery query )
{
// RegistrationPageIndexAndQuery
var scope = dbContext . Packages . Include ( p = > p . Versions ) . Include ( p = > p . Owner )
. Where ( p = > p . Id . Equals ( query . Query , StringComparison . InvariantCultureIgnoreCase )
& & ( query . Prerelease | | p . Versions . Any ( v = > ! v . IsPrerelease ) )
& & p . Versions . Count ( ) > 0 ) ;
var scope = ( await dbContext . Packages . Include ( p = > p . Versions ) . Include ( p = > p . Owner )
. ToListAsync ( ) ) . Where ( p = > MatchingExact ( p , query ) ) ;
var total = scope . Count ( ) ;
var pkgs = scope . Skip ( query . Skip ) . Take ( query . Take ) . ToArray ( ) ;
string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}" ;
@ -346,17 +338,30 @@ namespace isnd.Services
public async Task < RegistrationPageIndex > SearchPackageAsync ( RegistrationPageIndexQuery query )
{
string bid = $"{extUrl}v3.4.0/{ApiConfig.Registration}" ;
// RegistrationPageIndexAndQuery
if ( query . Query = = null ) query . Query = "" ;
var scope = dbContext . Packages . Include ( p = > p . Versions ) . Include ( p = > p . Owner )
. Where ( p = > p . Id . StartsWith ( query . Query , StringComparison . InvariantCultureIgnoreCase )
& & ( query . Prerelease | | p . Versions . Any ( v = > ! v . IsPrerelease ) ) )
. Where ( p = > p . Versions . Count > 0 ) ;
var total = await scope . Count Async ( ) ;
var pkgs = await scope . Skip ( query . Skip ) . Take ( query . Take ) . ToArrayAsync ( ) ;
var scope = ( await dbContext . Packages . Include ( p = > p . Versions ) . Include ( p = > p . Owner )
. ToListAsync ( ) )
. Where ( p = > Matching ( p , query ) )
;
var total = scope . Count ( ) ;
var pkgs = scope . Skip ( query . Skip ) . Take ( query . Take ) ;
return
new RegistrationPageIndex ( bid , query . Query , extUrl , pkgs ) ;
}
private static bool MatchingExact ( Package p , RegistrationPageIndexQuery query )
{
return
p . Id . Equals ( query . Query , StringComparison . InvariantCultureIgnoreCase )
& & ( query . Prerelease | | p . Versions . Any ( v = > ! v . IsPrerelease ) ) ;
}
private static bool Matching ( Package p , RegistrationPageIndexQuery query )
{
return p . Id . StartsWith ( query . Query , StringComparison . InvariantCultureIgnoreCase )
& & ( query . Prerelease | | p . Versions . Any ( v = > ! v . IsPrerelease ) ) ;
}
}
}