catalog index

broken/ef
Paul Schneider 3 years ago
parent f6fa7a0ec9
commit d8bfdc293d
4 changed files with 36 additions and 34 deletions

@ -14,7 +14,7 @@ namespace isnd.Data.Catalog
[JsonProperty("count")]
public int Count { get => Items.Count; }
public int Count { get => Items?.Count ?? 0; }
public string CommitId { get; set; }
public DateTime CommitTimeStamp { get; set; }

@ -32,13 +32,13 @@ namespace isnd.Data
public virtual Package Package { get; set; }
[Required][JsonIgnore]
[ForeignKey("LatestCommit")]
public long CommitNId { get; set ; }
[NotMapped]
public string CommitId { get => CommitNId.ToString(); }
[ForeignKey("CommitNId")]
public virtual Commit LatestCommit{ get; set; }
public string NugetLink => $"/package/{PackageId}/{FullString}/{PackageId}-{FullString}.nupkg";

@ -23,9 +23,9 @@ namespace isnd.Services
IOptions<IsndSettings> siteConfigOptionsOptions)
{
this.dbContext = dbContext;
isndSettings = siteConfigOptionsOptions.Value;
extApiUrl = isndSettings.ExternalUrl + "/package";
CurrentCatalogIndex = GetCatalogIndex();
pmConfigOptions = siteConfigOptionsOptions.Value;
extApiUrl = pmConfigOptions.ExternalUrl + "/package";
}
@ -138,7 +138,7 @@ namespace isnd.Services
public static CatalogIndex CurrentCatalogIndex { get; protected set; }
public static List<Page> CurrentCatalogPages { get; protected set; }
private IsndSettings pmConfigOptions;
private IsndSettings isndSettings;
private string extApiUrl;
public virtual CatalogIndex GetCatalogIndex()
@ -157,7 +157,7 @@ namespace isnd.Services
var oldPages = CurrentCatalogPages;
CurrentCatalogIndex = new CatalogIndex
{
Id = extApiUrl
};
CurrentCatalogPages = new List<Page>();
@ -165,17 +165,17 @@ namespace isnd.Services
Commit last = null;
PageRef pageRef = null;
Page page = null;
i = pmConfigOptions.CatalogPageLen;
i = isndSettings.CatalogPageLen;
foreach (var commit in scope)
{
if (i >= this.pmConfigOptions.CatalogPageLen)
if (i >= this.isndSettings.CatalogPageLen)
{
page = new Page
{
Parent = pmConfigOptions.ExternalUrl + "/package",
Parent = isndSettings.ExternalUrl + "/package",
CommitId = commit.CommitId,
CommitTimeStamp = commit.CommitTimeStamp,
Id = this.pmConfigOptions.ExternalUrl + "/package/index-" + p++
Id = this.isndSettings.ExternalUrl + "/package/index-" + p++
};
CurrentCatalogPages.Add(page);

@ -32,12 +32,20 @@ namespace isnd
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(
Configuration.GetConnectionString("DefaultConnection")));
var smtpSettingsconf = Configuration.GetSection("Smtp");
var isndSettingsconf = Configuration.GetSection("Isn");
var adminStartupListConf = Configuration.GetSection("AdminList");
var unleashConf = Configuration.GetSection("Unleash");
services.AddIdentity<ApplicationUser, IdentityRole>()
services.Configure<SmtpSettings>(smtpSettingsconf)
.Configure<IsndSettings>(isndSettingsconf)
.Configure<AdminStartupList>(adminStartupListConf)
.Configure<UnleashClientSettings>(unleashConf)
.Configure<MigrationsEndPointOptions>(o => o.Path = "~/migrate")
.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(
Configuration.GetConnectionString("DefaultConnection")))
.AddIdentity<ApplicationUser, IdentityRole>()
.AddRoles<IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddSignInManager()
@ -48,9 +56,6 @@ namespace isnd
services.AddDataProtection();
services.AddTransient<IMailer, EmailSender>();
services.AddTransient<IEmailSender, EmailSender>();
services.AddAuthorization(options =>
{
options.AddPolicy(Constants.RequireAdminPolicyName,
@ -58,26 +63,23 @@ namespace isnd
options.AddPolicy(Constants.RequireValidApiKey, policy =>
policy.Requirements.Add(new ValidApiKeyRequirement()));
});
services.AddSingleton<IAuthorizationHandler, ValidApiKeyRequirementHandler>();
services.AddSingleton<IUnleash>(s =>
})
.AddTransient<IMailer, EmailSender>()
.AddTransient<IEmailSender, EmailSender>()
.AddTransient<IPackageManager, PackageManager>()
.AddSingleton<IAuthorizationHandler, ValidApiKeyRequirementHandler>()
.AddSingleton(s =>
{
var config = s.GetRequiredService<IOptions<UnleashClientSettings>>();
if (config.Value==null)
throw new System.Exception("No unleash client settings");
if (config.Value.ApiUrl==null)
throw new System.Exception("No unleash client ApiUrl");
if (config.Value.ClientApiKey==null)
throw new System.Exception("No unleash client ClientApiKey");
return s.GetRequiredService<Microsoft.AspNetCore.Hosting.IHostingEnvironment>().CreateUnleahClient(config.Value);
});
services.AddTransient<IPackageManager, PackageManager>();
// _unleashĈlient = env.CreateUnleahClient(unleashClientSettings.Value);
var smtpSettingsconf = Configuration.GetSection("Smtp");
services.Configure<SmtpSettings>(smtpSettingsconf);
var isndSettingsconf = Configuration.GetSection("Isn");
services.Configure<IsndSettings>(isndSettingsconf);
var adminStartupListConf = Configuration.GetSection("AdminList");
services.Configure<AdminStartupList>(adminStartupListConf);
var unleashConf = Configuration.GetSection("Unleash");
services.Configure<UnleashClientSettings>(unleashConf);
services.Configure<MigrationsEndPointOptions>(o => o.Path = "~/migrate");
}

Loading…