89 lines
2.1 KiB
C#
89 lines
2.1 KiB
C#
#pragma warning disable SYSLIB1045
|
|
using BITKit;
|
|
using BITKit.Net;
|
|
using CAICT.IDIS.Service;
|
|
using CN.CAICT.IDIS;
|
|
using IDIS.Model;
|
|
using Net.BITKit.Teleport;
|
|
using Newtonsoft.Json;
|
|
|
|
await BITAppForNet.InitializeAsync("CN.CAICT.IDIS");
|
|
|
|
var config = Path.Combine(Environment.CurrentDirectory,"appsettings.json");
|
|
if (File.Exists(config))
|
|
{
|
|
var json = File.ReadAllText(config);
|
|
DataParser.Set(json);
|
|
}
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
var cancellationTokenSource = new System.Threading.CancellationTokenSource();
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen(x =>
|
|
{
|
|
var currentDirectory = AppContext.BaseDirectory;
|
|
x.IncludeXmlComments(currentDirectory + "/CN.CAICT.IDIS.xml",true);
|
|
});
|
|
|
|
builder.Services.AddSingleton<NetProviderService>();
|
|
builder.Services.AddSingleton<INetServer, ENetServer>();
|
|
builder.Services.AddSingleton<INetProvider>(x => x.GetRequiredService<INetServer>().NetProvider);
|
|
|
|
builder.Services.AddTransient<IDIS_Service, IDIS_Service_SqlSugar>();
|
|
builder.Services.AddTransient<IDIS_EnterpriseService, IDIS_EnterpriseService_SqlSugar>();
|
|
builder.Services.AddTransient<IDIS_TemplateService, IDIS_TemplateService_Sugar>();
|
|
|
|
var app = builder.Build();
|
|
|
|
var server = app.Services.GetRequiredService<INetServer>();
|
|
|
|
server.StartServer(29755);
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.MapGet("/", () => "Hello World!");
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
new Thread(Tick).Start();
|
|
|
|
|
|
await app.RunAsync();
|
|
|
|
return;
|
|
async void Tick()
|
|
{
|
|
app.Services.QueryComponents(out ILogger<INetServer> logger);
|
|
while (true)
|
|
{
|
|
try
|
|
{
|
|
server.NetProvider.Tick();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
logger.LogCritical(exception,exception.Message);
|
|
}
|
|
|
|
//logger.LogInformation("wait next frame");
|
|
await Task.Delay(16);
|
|
}
|
|
|
|
logger.LogCritical("程序已退出,不应该出现");
|
|
} |