添加项目文件。

This commit is contained in:
2025-02-25 22:28:49 +08:00
parent 07e26cc93e
commit 1a7bdb585a
32 changed files with 1601 additions and 0 deletions

68
Program.cs Normal file
View File

@@ -0,0 +1,68 @@
using System.Diagnostics;
using System.Reflection;
using MegghysAPI.Attributes;
using MegghysAPI.Components;
using Microsoft.FluentUI.AspNetCore.Components;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddFluentUIComponents();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// 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.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.MapControllers();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> AutoInitAttribute <20><><EFBFBD><EFBFBD>
// <20><>ȡ<EFBFBD><C8A1>ǰAssembly
var inits = new List<MethodInfo>();
Assembly.GetExecutingAssembly()
.GetTypes()
.ForEach(t => t.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)
.Where(m => m.GetCustomAttribute<AutoInitAttribute>() is { }).ForEach(m => inits.Add(m)));
inits = [.. inits.OrderBy(m => m.GetCustomAttribute<AutoInitAttribute>().Order)];
inits.ForEach(m =>
{
var sw = new Stopwatch();
sw.Start();
var attr = m.GetCustomAttribute<AutoInitAttribute>();
if (attr.LogMessage is not null)
Logs.Info(attr.LogMessage);
if (attr.Async)
{
Task.Run(() =>
{
m.Invoke(null, null);
attr.PostInit?.Invoke();
Logs.Info($"[{sw.ElapsedMilliseconds} ms] Async <{m.DeclaringType.Name}.{m.Name}> => Inited.");
});
}
else
{
m.Invoke(null, null);
attr.PostInit?.Invoke();
Logs.Info($"[{sw.ElapsedMilliseconds} ms] <{m.DeclaringType.Name}.{m.Name}> => Inited.");
}
});
app.Run();