using Microsoft.AspNetCore.DataProtection.KeyManagement; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System.Diagnostics; using System.Globalization; using System.Timers; using static Jobini; var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddRazorPages(); var app = builder.Build(); string filePath = "Setting.txt"; string scoreDbPath = "Score.txt"; Jobini settingini = new(filePath); Jobini scoreDBini = new(scoreDbPath); //Dictionary settingValues = []; //Dictionary scoreDB = []; // Configure the HTTP request pipeline. if (!app.Environment.IsDevelopment()) { app.UseExceptionHandler("/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.Use(async (context, next) => //{ // context.Response.Headers.Append("Content-Security-Policy", "base-uri 'self'; default-src 'self'; img-src data: https:; object-src 'none'; script-src 'self'; style-src 'self'; upgrade-insecure-requests;"); // await next(); //}); //Dictionary scoreDB= []; //±â·ÏÇϱâ app.MapPost("submit", (string name, int score) => { var dbKey = scoreDBini.IniRead(name); if (dbKey != null) { int value = int.Parse(dbKey); if (value < score) { scoreDBini.IniWrite(name, score.ToString()); } return Results.Ok(new { Message = "A" }); } else { scoreDBini.IniWrite(name, score.ToString()); //scoreDB[name] = score; return Results.Ok(new { Message = "¾î¿¹" }); } }); List weekArrow = []; //weekly Jobs (dbReset, WeekArrowGen...) System.Timers.Timer resetTimer = new System.Timers.Timer(1000); // 10000ms = 10 seconds => 1week = ?ms mol ra si bal resetTimer.Elapsed += (sender, e) => { TimeOnly curTime = new(DateTime.Now.Hour, DateTime.Now.Minute); TimeOnly tarTime = new(0, 0); //¾Æ¸¶ ¿ÀÀü 12½Ã? if (System.TimeOnly.Equals(curTime, tarTime)) { weekArrow.Clear(); } //weekArrow.Clear(); // Log reset actio var logger = app.Services.GetRequiredService>(); logger.LogInformation("doWeekJobs"); // Clear the scoreDB scoreDBini.Clear(); Random random = new(); for (int i = 0; i < random.NextInt64(int.Parse(scoreDBini.NotNullableiniRead("minArrowNum")), int.Parse(scoreDBini.NotNullableiniRead("maxArrowNum"))); i++) { int rngNum = (int)random.NextInt64(0, 4); weekArrow.Add(rngNum/*(int)random.NextInt64(0, 4)*/); //logger.LogInformation(rngNum.ToString()); } }; Random random = new(); for (int i = 0; i < random.NextInt64(int.Parse(scoreDBini.NotNullableiniRead("minArrowNum")), int.Parse(scoreDBini.NotNullableiniRead("maxArrowNum"))); i++) { int rngNum = (int)random.NextInt64(0, 4); weekArrow.Add(rngNum/*(int)random.NextInt64(0, 4)*/); //logger.LogInformation(rngNum.ToString()); }//ÀÚ±â ÀÚ½ÅÀÌ ÀаíÀÖ´Ù°í ¸ø ÀÐÀ¸¸é ³­ ¹¹ ¾î¶»°Ô ¹Þ¾Æµé¿©¾ßÇÔ? resetTimer.Start(); //±â·ÏµÈ Á¡¼ö ¾ò±â app.MapGet("/", () => scoreDBini.ReadDictionary); app.MapGet("WeekArrow", () => weekArrow ); //app.UseHttpsRedirection(); app.UseStaticFiles(); //app.UseRouting(); app.UseAuthorization(); app.UseRouting(); app.MapRazorPages(); app.Run("http://localhost:5000");