using Microsoft.AspNetCore.DataProtection.KeyManagement; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; using System.Diagnostics; using System.Globalization; using System.Net.Sockets; 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"; //iniŬ·¡½º¶ó ÇØ³õ°í Á¤ÀÛ ÆÄÀÏ È®ÀåÀÚ´Â 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(); } //cspÀ̽´ °íÃľßÇÔ ºê¶ó¿ìÀú¿¡¼­ csp¶§¹®¿¡ ½ÅÈ£ ÀÚü¸¦ ¾Èº¸³¿ ´ÙÇàÈ÷ À¯´ÏƼ¿¡¼­ º¸³»´Â°ÍÀº cspüũ°¡ ²¨Á®Àִµí //±×·¡¼­ ¾î¶»°Ô °íħ? //´ëÃæ ÇÁ·ÐÆ®¿£µå ¹®Á¦¶ó ÇÏ°í ¶°³Ñ±âÁÒ? //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(); //}); //scoreDB = []; //±â·ÏÇϱâ app.MapPost("submit", (string name, int score) => { var dbKey = scoreDBini.IniRead(name); if (dbKey != null)//scoreDB.ContainsKey(name)) { int value = int.Parse(dbKey); if (value < score)//scoreDB[name] < score) { //scoreDB[name ] = 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(43200000); // 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("do every 12hour Jobs"); // Clear the scoreDB scoreDBini.Clear(); weekArrow.Clear(); Random random = new(); for (int i = 0; i < random.NextInt64(int.Parse(settingini.NotNullableiniRead("minArrowNum","10")), int.Parse(settingini.NotNullableiniRead("maxArrowNum","30"))/*10,30*/); 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(10,30/*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°¡ ¸ÞÀÎ ½º·¹µå°¡ ¾Æ´Ñ ´Ù¸¥ ½º·¹µå¿¡¼­ µ¿ÀÛÇÑ´Ù´Â Ä«´õ¶ó°¡ ÀÖÀ½ => jobiniŬ·¡½º¿¡¼­ ¸Þ¼­µå Çϳª »©¸Ô¾ú´Ù°í »ý±ä ¹®Á¦Àεí? ¾Æ¸¶ ÇØ°áµÊ resetTimer.Start(); //±â·ÏµÈ Á¡¼ö ¾ò±â app.MapGet("/", () => /*scoreDB);*/scoreDB = scoreDBini.ReadDictionary());//scoreDBini.ReadDictionary); app.MapGet("WeekArrow", ()=> weekArrow); //app.UseHttpsRedirection(); app.UseStaticFiles(); //app.UseRouting(); app.UseAuthorization(); app.UseRouting(); app.MapRazorPages(); //À̹Ìminio¿¡¼­ 8000~8001»ç¿ëÁß => ±Ùµ¥ ¿Ö 8004¾¸? ±×³É app.Run("http://localhost:8004");