public async Task <IActionResult> OnPostCalcAsync() { var timer = System.Diagnostics.Stopwatch.StartNew(); var guild = await CheckUserPrivilege(); if (guild is null) { return(RedirectToPage("/Home/Index")); } Console.WriteLine($"validate {timer.ElapsedMilliseconds} ms"); var imGuild = await _context.GetGuildAsync(guild.GuildID); //1. Refresh users' combo lists. var comboCalculator = new FindAllCombos(); await comboCalculator.UpdateGuildAsync(_context, guild.GuildID, imGuild); Console.WriteLine($"user combo refresh {timer.ElapsedMilliseconds} ms"); //2. Calculate values. await CalcComboValues.RunAllAsync(_context.DbContext, guild, imGuild); Console.WriteLine($"value calculation {timer.ElapsedMilliseconds} ms"); return(RedirectToPage("/Home/Index")); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env, InMemoryStorageContext dataContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); app.UseMigrationsEndPoint(); } 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(); app.UseAuthentication(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapRazorPages(); }); var supportedCultures = new[] { "zh-CN" }; var localizationOptions = new RequestLocalizationOptions() .SetDefaultCulture(supportedCultures[0]) .AddSupportedCultures(supportedCultures) .AddSupportedUICultures(supportedCultures); app.UseRequestLocalization(localizationOptions); dataContext.DbContext.Database.Migrate(); if (LoadIMContext) { Console.WriteLine("Loading IM context"); var guilds = dataContext.DbContext.Guilds.ToList(); var comboCalculator = new FindAllCombos(); foreach (var g in guilds) { var imGuild = dataContext.GetGuildAsync(g.GuildID).Result; comboCalculator.UpdateGuildAsync(dataContext, g.GuildID, imGuild).Wait(); CalcComboValues.RunAllAsync(dataContext.DbContext, g, imGuild).Wait(); } Console.WriteLine("IM context loaded."); } }
public async Task <IActionResult> OnPostAsync() { var timer = System.Diagnostics.Stopwatch.StartNew(); var guild = await CheckUserPrivilege(); if (guild is null) { return(RedirectToPage("/Home/Index")); } Console.WriteLine($"validate {timer.ElapsedMilliseconds} ms"); var imGuild = await _context.GetGuildAsync(guild.GuildID); guild.DamageCoefficient = PlanRatio; //TODO cache var stages = await _context.DbContext.BattleStages.OrderBy(s => s.StartLap).ToListAsync(); FirstLapForStages = stages.Select(s => s.StartLap).ToArray(); BossNames = new(); foreach (var s in stages) { var bosses = await _context.DbContext.Bosses .Where(b => b.BattleStageID == s.BattleStageID) .Select(b => (string)null) //We only need count for boss index conversion. .ToListAsync(); BossNames.Add(bosses); } //1. Update guild status. var newBossIndex = ConvLap(CurrentLap - 1, CurrentBoss - 1); if (!newBossIndex.HasValue) { return(RedirectToPage()); } if (CurrentBossRatio < 0 || CurrentBossRatio >= 1) { return(RedirectToPage()); } guild.BossIndex = newBossIndex.Value; guild.BossDamageRatio = CurrentBossRatio; //This is the only save we need for this request. await _context.DbContext.SaveChangesAsync(); Console.WriteLine($"guild progress update {timer.ElapsedMilliseconds} ms"); //2. Refresh users' combo lists. var comboCalculator = new FindAllCombos(); await comboCalculator.UpdateGuildAsync(_context, guild.GuildID, imGuild); Console.WriteLine($"user combo refresh {timer.ElapsedMilliseconds} ms"); //3. Calculate values. await CalcComboValues.RunAllAsync(_context.DbContext, guild, imGuild); Console.WriteLine($"value calculation {timer.ElapsedMilliseconds} ms"); return(RedirectToPage("/Home/Index")); }