2026-06-10 11:16:46 +08:00
|
|
|
|
using YD_TrainingCompetition_Api.Competition;
|
2026-06-02 10:30:05 +08:00
|
|
|
|
using YD_TrainingCompetition_Api.Hubs;
|
|
|
|
|
|
using YD_TrainingCompetition_Api.Options;
|
|
|
|
|
|
using YD_TrainingCompetition_Api.Protocols;
|
|
|
|
|
|
using YD_TrainingCompetition_Api.Serial;
|
|
|
|
|
|
using YD_TrainingCompetition_Api.Services;
|
|
|
|
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
2026-06-10 11:16:46 +08:00
|
|
|
|
var listenUrls = builder.Configuration["ASPNETCORE_URLS"]
|
|
|
|
|
|
?? builder.Configuration["urls"]
|
|
|
|
|
|
?? "http://*:9996";
|
|
|
|
|
|
builder.WebHost.UseUrls(listenUrls);
|
2026-06-02 10:30:05 +08:00
|
|
|
|
|
|
|
|
|
|
builder.Services.Configure<ScoringOptions>(builder.Configuration.GetSection(ScoringOptions.SectionName));
|
|
|
|
|
|
builder.Services.Configure<Serial24GOptions>(builder.Configuration.GetSection(Serial24GOptions.SectionName));
|
|
|
|
|
|
builder.Services.Configure<RosterOptions>(builder.Configuration.GetSection(RosterOptions.SectionName));
|
2026-07-02 10:05:51 +08:00
|
|
|
|
builder.Services.Configure<HikvisionOptions>(builder.Configuration.GetSection(HikvisionOptions.SectionName));
|
2026-06-02 10:30:05 +08:00
|
|
|
|
|
|
|
|
|
|
builder.Services.AddControllers();
|
|
|
|
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
|
|
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
|
|
builder.Services.AddSignalR();
|
|
|
|
|
|
|
|
|
|
|
|
builder.Services.AddCors(options =>
|
|
|
|
|
|
{
|
|
|
|
|
|
options.AddDefaultPolicy(policy =>
|
|
|
|
|
|
{
|
|
|
|
|
|
policy.AllowAnyHeader()
|
|
|
|
|
|
.AllowAnyMethod()
|
|
|
|
|
|
.SetIsOriginAllowed(_ => true)
|
|
|
|
|
|
.AllowCredentials();
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
builder.Services.AddSingleton<IDeviceStateStore, DeviceStateStore>();
|
|
|
|
|
|
builder.Services.AddSingleton<IRealtimeNotifier, SignalRRealtimeNotifier>();
|
|
|
|
|
|
builder.Services.AddSingleton<ISerialGateway, SerialGateway>();
|
|
|
|
|
|
builder.Services.AddSingleton<IJumpProtocolParser, JumpProtocolParser>();
|
|
|
|
|
|
builder.Services.AddSingleton<IRosterService, RosterService>();
|
|
|
|
|
|
builder.Services.AddSingleton<IParticipantDirectory, ParticipantDirectory>();
|
2026-06-10 11:16:46 +08:00
|
|
|
|
builder.Services.AddSingleton<ICompetitionSessionService, CompetitionSessionService>();
|
2026-07-02 10:05:51 +08:00
|
|
|
|
builder.Services.AddSingleton<IHikvisionAlarmStore, HikvisionAlarmStore>();
|
2026-06-02 10:30:05 +08:00
|
|
|
|
builder.Services.AddHostedService<SerialIngestWorker>();
|
2026-06-10 15:54:30 +08:00
|
|
|
|
builder.Services.AddHostedService<CompetitionCountdownWorker>();
|
2026-07-02 10:05:51 +08:00
|
|
|
|
builder.Services.AddHostedService<HikvisionIngestWorker>();
|
2026-06-02 10:30:05 +08:00
|
|
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
|
{
|
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-22 09:20:20 +08:00
|
|
|
|
// 提供打包后内置的前端静态资源(桌面端通过 http 加载,避免 file:// 下 fetch/绝对路径失效)。
|
|
|
|
|
|
// 使用可执行文件同级的 wwwroot 绝对路径,避免内容根/工作目录差异导致静态资源 404。
|
|
|
|
|
|
var webRootPath = Path.Combine(AppContext.BaseDirectory, "wwwroot");
|
|
|
|
|
|
var hasBundledFrontend = Directory.Exists(webRootPath);
|
|
|
|
|
|
Microsoft.Extensions.FileProviders.PhysicalFileProvider? frontendFileProvider = null;
|
|
|
|
|
|
if (hasBundledFrontend)
|
|
|
|
|
|
{
|
|
|
|
|
|
frontendFileProvider = new Microsoft.Extensions.FileProviders.PhysicalFileProvider(webRootPath);
|
|
|
|
|
|
app.UseDefaultFiles(new DefaultFilesOptions { FileProvider = frontendFileProvider });
|
|
|
|
|
|
app.UseStaticFiles(new StaticFileOptions { FileProvider = frontendFileProvider });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-02 10:30:05 +08:00
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
app.UseCors();
|
|
|
|
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
|
app.MapHub<ScoringHub>("/hubs/scoring");
|
|
|
|
|
|
|
2026-06-22 09:20:20 +08:00
|
|
|
|
// 单页应用兜底:非 API/Hub 路由回退到 index.html(仅当存在内置前端时生效)。
|
|
|
|
|
|
if (hasBundledFrontend && frontendFileProvider is not null)
|
|
|
|
|
|
{
|
|
|
|
|
|
app.MapFallbackToFile("index.html", new StaticFileOptions { FileProvider = frontendFileProvider });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-02 10:30:05 +08:00
|
|
|
|
app.Run();
|