@ -1,4 +1,3 @@
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Linq ;
using System.Linq ;
using isnd.Controllers ;
using isnd.Controllers ;
@ -14,20 +13,65 @@ using Unleash;
namespace isnd.Services
namespace isnd.Services
{
{
public class PackageManager : IPackageManager
public class PackageManager : IPackageManager
{
{
ApplicationDbContext dbContext ;
ApplicationDbContext dbContext ;
public PackageManager ( ApplicationDbContext dbContext ,
public PackageManager ( ApplicationDbContext dbContext ,
IOptions < IsndSettings > siteConfigOptionsOptions )
IOptions < IsndSettings > siteConfigOptionsOptions )
{
{
this . dbContext = dbContext ;
this . dbContext = dbContext ;
isndSettings = siteConfigOptionsOptions . Value ;
isndSettings = siteConfigOptionsOptions . Value ;
ext Api Url = isndSettings . ExternalUrl + "/package" ;
ext Url = isndSettings . ExternalUrl ;
CurrentCatalogIndex = GetCatalogIndex ( ) ;
CurrentCatalogIndex = GetCatalogIndex ( ) ;
}
}
public IEnumerable < Resource > GetResources ( IUnleash unleashClient )
{
bool defaultActivation = false ;
#if DEBUG
defaultActivation = true ;
#endif
var res = new List < Resource > ( ) ;
// stable
if ( unleashClient . IsEnabled ( "pkg-push" , true ) )
res . Add (
new Resource
{
id = extUrl + ApiConfig . Publish ,
type = "PackagePublish/2.0.0" ,
comment = "Package Publish service"
} ) ;
// under dev, only leash in release mode
if ( defaultActivation | | unleashClient . IsEnabled ( "pkg-get" , false ) )
res . Add (
new Resource
{
id = extUrl + ApiConfig . Base ,
type = "PackageBaseAddress/3.0.0" ,
comment = "Package Base Address service"
} ) ;
if ( defaultActivation | | unleashClient . IsEnabled ( "pkg-autocomplete" , false ) )
res . Add (
new Resource
{
id = extUrl + ApiConfig . AutoComplete ,
type = "SearchAutocompleteService/3.5.0" ,
comment = "Auto complete service"
} ) ;
if ( defaultActivation | | unleashClient . IsEnabled ( "pkg-search" , false ) )
res . Add (
new Resource
{
id = extUrl + ApiConfig . Search ,
type = "SearchQueryService/3.5.0" ,
comment = "Search Query service"
} ) ;
return res ;
}
public PackageIndexViewModel SearchByName ( string query ,
public PackageIndexViewModel SearchByName ( string query ,
int skip , int take , bool prerelease = false ,
int skip , int take , bool prerelease = false ,
@ -51,9 +95,6 @@ namespace isnd.Services
data = pkgs
data = pkgs
} ;
} ;
}
}
const int maxPageLen = 512 ;
public AutoCompleteResult AutoComplete ( string id ,
public AutoCompleteResult AutoComplete ( string id ,
int skip , int take , bool prerelease = false ,
int skip , int take , bool prerelease = false ,
string packageType = null )
string packageType = null )
@ -96,7 +137,7 @@ namespace isnd.Services
public static CatalogIndex CurrentCatalogIndex { get ; protected set ; }
public static CatalogIndex CurrentCatalogIndex { get ; protected set ; }
public static List < Page > CurrentCatalogPages { get ; protected set ; }
public static List < Page > CurrentCatalogPages { get ; protected set ; }
private IsndSettings isndSettings ;
private IsndSettings isndSettings ;
private string ext Api Url;
private string ext Url;
public virtual CatalogIndex GetCatalogIndex ( )
public virtual CatalogIndex GetCatalogIndex ( )
{
{
@ -114,7 +155,7 @@ namespace isnd.Services
var oldPages = CurrentCatalogPages ;
var oldPages = CurrentCatalogPages ;
CurrentCatalogIndex = new CatalogIndex
CurrentCatalogIndex = new CatalogIndex
{
{
Id = ext Api Url,
Id = ext Url,
Items = new List < PageRef > ( )
Items = new List < PageRef > ( )
} ;
} ;
CurrentCatalogPages = new List < Page > ( ) ;
CurrentCatalogPages = new List < Page > ( ) ;
@ -148,12 +189,14 @@ namespace isnd.Services
. Include ( pkg = > pkg . Versions )
. Include ( pkg = > pkg . Versions )
. Include ( pkg = > pkg . LatestVersion )
. Include ( pkg = > pkg . LatestVersion )
. Where (
. Where (
pkg = > pkg . Versions . Count ( ) > 0 & & pkg . CommitId = = commit . CommitId
pkg = > pkg . Versions . Count ( v = > v . CommitId = = commit . CommitId ) > 0
) ;
) ;
// pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString
// pkg.Versions.OrderByDescending(vi => vi.CommitNId).First().FullString
foreach ( var pkg in validPkgs )
foreach ( var pkg in validPkgs )
{
{
var v = pkg . Versions . OrderByDescending ( vc = > vc . CommitNId ) . First ( ) ;
var v = pkg . Versions .
Where ( cv = > cv . CommitId = = commit . CommitId )
. OrderByDescending ( vc = > vc . CommitNId ) . First ( ) ;
var pkgref = new PackageRef
var pkgref = new PackageRef
{
{
@ -204,44 +247,5 @@ namespace isnd.Services
return false ;
return false ;
}
}
public IEnumerable < Resource > GetResources ( IUnleash unleashClient )
{
var res = new List < Resource > ( ) ;
if ( unleashClient . IsEnabled ( "pkg-push" , true ) )
res . Add (
new Resource
{
id = extApiUrl ,
type = "PackagePublish/2.0.0" ,
comment = "Package Publish service"
} ) ;
if ( unleashClient . IsEnabled ( "pkg-get" , false ) )
res . Add (
new Resource
{
id = extApiUrl ,
type = "PackageBaseAddress/3.0.0" ,
comment = "Package Base Address service"
} ) ;
if ( unleashClient . IsEnabled ( "pkg-autocomplete" , false ) )
res . Add (
new Resource
{
id = extApiUrl ,
type = "SearchAutocompleteService/3.5.0" ,
comment = "Auto complete service"
} ) ;
if ( unleashClient . IsEnabled ( "pkg-search" , false ) )
res . Add (
new Resource
{
id = extApiUrl ,
type = "SearchQueryService/3.5.0" ,
comment = "Search Query service"
} ) ;
return res ;
}
}
}
}
}