2024-03-12 16:15:15 +08:00
|
|
|
|
using CSS_Solution.Request;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.Configuration.Json;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Linq.Expressions;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using CSS_Solution.Forms;
|
|
|
|
|
namespace CSS_Solution
|
|
|
|
|
{
|
|
|
|
|
public enum Request_Type
|
|
|
|
|
{
|
|
|
|
|
get_index,
|
|
|
|
|
get_code,
|
|
|
|
|
login,
|
|
|
|
|
to_course,
|
|
|
|
|
change_class
|
|
|
|
|
}
|
2024-03-14 00:02:17 +08:00
|
|
|
|
class Initialize
|
2024-03-12 16:15:15 +08:00
|
|
|
|
{
|
|
|
|
|
#if DEBUG
|
|
|
|
|
public static readonly string settings_File_Path = "AppSettings_Debug.json";
|
|
|
|
|
#else
|
|
|
|
|
public static readonly string settings_File_Path = "AppSettings.json";
|
|
|
|
|
#endif
|
|
|
|
|
public static IConfiguration configuration = new ConfigurationBuilder().SetBasePath(AppDomain.CurrentDomain.BaseDirectory).Add(new JsonConfigurationSource { Path = settings_File_Path, ReloadOnChange = true }).Build();
|
|
|
|
|
public static ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(builder);
|
|
|
|
|
builder.AddConsole();
|
|
|
|
|
});
|
2024-03-14 00:02:17 +08:00
|
|
|
|
public static Task_handler task_Handler = new Task_handler();
|
2024-03-12 16:15:15 +08:00
|
|
|
|
public static ILogger default_logger = loggerFactory.CreateLogger("Default logger");
|
|
|
|
|
public static HttpClientPool hc_pool = new HttpClientPool();
|
|
|
|
|
public Initialize()
|
|
|
|
|
{
|
|
|
|
|
Program.exceptionHandler = new ExceptionHandler();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
internal static class Program
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The main entry point for the application.
|
|
|
|
|
/// </summary>
|
|
|
|
|
[STAThread]
|
|
|
|
|
static void Main()
|
|
|
|
|
{
|
|
|
|
|
// To customize application configuration such as set high DPI settings or default font,
|
|
|
|
|
// see https://aka.ms/applicationconfiguration.
|
|
|
|
|
if (!Init())
|
|
|
|
|
return;
|
|
|
|
|
#pragma warning disable CS8604 // 引用类型参数可能为 null。
|
|
|
|
|
#pragma warning disable CS8602 // 解引用可能出现空引用。
|
|
|
|
|
Application.ThreadException += exceptionHandler.ApplicationThreadExceptionHandler;
|
|
|
|
|
Initialize.default_logger.LogInformation($"[{DateTime.Now}] log程序和自定义对象初始化完成");
|
|
|
|
|
ApplicationConfiguration.Initialize();
|
|
|
|
|
//#region Test
|
|
|
|
|
//{
|
|
|
|
|
// bool cango = false;
|
|
|
|
|
// Task_handler.index_Task_Handler.Make_request((t) => { Console.WriteLine(t.ToString()); cango = true; });
|
|
|
|
|
// while (!cango) { }
|
|
|
|
|
// cango = false;
|
|
|
|
|
// Task_handler.login_Task_Handler.Make_request((t) => { Console.WriteLine(t.ToString()); cango = true; }, null);
|
|
|
|
|
// while (!cango) { }
|
|
|
|
|
// cango = false;
|
|
|
|
|
// Task_handler.toCourse_Task_Handler.Make_request((t) =>
|
|
|
|
|
// {
|
|
|
|
|
// Console.WriteLine(t.ToString());
|
|
|
|
|
// cango = true;
|
|
|
|
|
// }, null);
|
|
|
|
|
// while (!cango) { }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
//#endregion
|
|
|
|
|
mainForm = new MainForm();
|
|
|
|
|
Application.Run(mainForm);
|
|
|
|
|
#pragma warning restore CS8604 // 引用类型参数可能为 null。
|
|
|
|
|
#pragma warning restore CS8602 // 解引用可能出现空引用。
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
static bool Init()
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
new Initialize();
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidOperationException e)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Initialize failed");
|
|
|
|
|
Console.WriteLine($"[{DateTime.Now}] Message:\n{e.Message}\nStackTrace:\n{e.StackTrace}\n");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (exceptionHandler == null)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("exceptionHandler isn't Initlized");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (Initialize.default_logger == null)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("default_logger isn't Initlized");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public static MainForm? mainForm;
|
|
|
|
|
public static ExceptionHandler? exceptionHandler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|