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));
|
|
|
|
|
|
|
|
|
|
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-06-02 10:30:05 +08:00
|
|
|
builder.Services.AddHostedService<SerialIngestWorker>();
|
2026-06-10 15:54:30 +08:00
|
|
|
builder.Services.AddHostedService<CompetitionCountdownWorker>();
|
2026-06-02 10:30:05 +08:00
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
app.UseCors();
|
|
|
|
|
|
|
|
|
|
app.MapControllers();
|
|
|
|
|
app.MapHub<ScoringHub>("/hubs/scoring");
|
|
|
|
|
|
|
|
|
|
app.Run();
|