From d8bfdc293db8d7b1c16b40096a15d4dad99f83aa Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sat, 28 Aug 2021 21:26:39 +0100 Subject: [PATCH] catalog index --- src/isnd/Data/Catalog/CatalogIndex.cs | 2 +- src/isnd/Data/PackageVersion.cs | 2 +- src/isnd/Services/PackageManager.cs | 16 ++++----- src/isnd/Startup.cs | 50 ++++++++++++++------------- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/src/isnd/Data/Catalog/CatalogIndex.cs b/src/isnd/Data/Catalog/CatalogIndex.cs index f68f3fb..1890351 100644 --- a/src/isnd/Data/Catalog/CatalogIndex.cs +++ b/src/isnd/Data/Catalog/CatalogIndex.cs @@ -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; } diff --git a/src/isnd/Data/PackageVersion.cs b/src/isnd/Data/PackageVersion.cs index 0355706..04f9108 100644 --- a/src/isnd/Data/PackageVersion.cs +++ b/src/isnd/Data/PackageVersion.cs @@ -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"; diff --git a/src/isnd/Services/PackageManager.cs b/src/isnd/Services/PackageManager.cs index 7d6214e..852dd27 100644 --- a/src/isnd/Services/PackageManager.cs +++ b/src/isnd/Services/PackageManager.cs @@ -23,9 +23,9 @@ namespace isnd.Services IOptions 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 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(); @@ -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); diff --git a/src/isnd/Startup.cs b/src/isnd/Startup.cs index a1d158f..2b8efbf 100644 --- a/src/isnd/Startup.cs +++ b/src/isnd/Startup.cs @@ -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(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() + services.Configure(smtpSettingsconf) + .Configure(isndSettingsconf) + .Configure(adminStartupListConf) + .Configure(unleashConf) + .Configure(o => o.Path = "~/migrate") + .AddDbContext(options => + options.UseNpgsql( + Configuration.GetConnectionString("DefaultConnection"))) + .AddIdentity() .AddRoles() .AddEntityFrameworkStores() .AddSignInManager() @@ -45,12 +53,9 @@ namespace isnd .AddDefaultTokenProviders(); services.AddMvc(); - + services.AddDataProtection(); - services.AddTransient(); - services.AddTransient(); - 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(); - services.AddSingleton(s => + }) + .AddTransient() + .AddTransient() + .AddTransient() + .AddSingleton() + .AddSingleton(s => { var config = s.GetRequiredService>(); + 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().CreateUnleahClient(config.Value); }); - services.AddTransient(); - // _unleashĈlient = env.CreateUnleahClient(unleashClientSettings.Value); - var smtpSettingsconf = Configuration.GetSection("Smtp"); - services.Configure(smtpSettingsconf); - var isndSettingsconf = Configuration.GetSection("Isn"); - services.Configure(isndSettingsconf); - var adminStartupListConf = Configuration.GetSection("AdminList"); - services.Configure(adminStartupListConf); - var unleashConf = Configuration.GetSection("Unleash"); - services.Configure(unleashConf); - services.Configure(o => o.Path = "~/migrate"); }