// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHostApplicationLifetime lifeTime, IndexMaintainer maintainer, MusicConfiguration musicConfiguration, ILogger <Startup> logger) { Logger = logger; if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } app.UseHttpsRedirection(); app.UseStaticFiles(); app.UseRouting(); // Register the Swagger generator and the Swagger UI middlewares app.UseOpenApi(); app.UseSwaggerUi3(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); }); // on exit // lifeTime.ApplicationStopping.Register(OnShutdown); AppDomain.CurrentDomain.ProcessExit += CurrentDomain_ProcessExit; Maintainer = maintainer; if (!Maintainer.IndexExist()) { Task.Run(async() => { await Maintainer.InitIndex(CancellationTokenSource.Token); }); } Task.Run(async() => { while (!CancellationTokenSource.Token.IsCancellationRequested) { Logger.LogInformation("Auto SaveResults start, will run after {AutoSaveIndexSeconds} seconds", musicConfiguration.AutoSaveIndexSeconds); await Task.Delay(musicConfiguration.AutoSaveIndexSeconds * 1000, CancellationTokenSource.Token); Logger.LogInformation("Auto SaveResults start"); await Maintainer.SaveResults(CancellationTokenSource.Token); Logger.LogInformation("Auto SaveResults finished"); } }, CancellationTokenSource.Token); }
public async Task <MaintainMusicInfoResult> SaveSongIndex() { await IndexMaintainer.SaveResults(CancellationToken.None); return(new MaintainMusicInfoResult { ResultCode = ResultCode.Successful }); }
public async Task <MaintainMusicInfoResult> RebuildAllIndex() { await IndexMaintainer.DeleteAllIndex(CancellationToken.None); await IndexMaintainer.InitIndex(CancellationToken.None); await IndexMaintainer.SaveResults(CancellationToken.None); return(new MaintainMusicInfoResult { ResultCode = ResultCode.Successful }); }