2023-10-12 07:15:34 +00:00
|
|
|
#pragma warning disable AV1500
|
2023-08-12 21:02:59 +00:00
|
|
|
using System.Net;
|
2023-08-09 14:23:41 +00:00
|
|
|
using System.Reflection;
|
|
|
|
using MassTransit;
|
2023-08-14 11:49:27 +00:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-08-14 19:45:00 +00:00
|
|
|
using Microsoft.Extensions.Configuration;
|
2023-08-09 14:23:41 +00:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2022-12-31 13:31:42 +00:00
|
|
|
using Microsoft.Extensions.Logging;
|
2023-08-10 08:47:35 +00:00
|
|
|
using Server.DB;
|
|
|
|
using Server.Services;
|
2022-12-31 13:31:42 +00:00
|
|
|
|
2023-08-09 14:23:41 +00:00
|
|
|
var builder = Host.CreateApplicationBuilder();
|
2023-08-14 19:45:00 +00:00
|
|
|
#if DEBUG
|
|
|
|
builder.Environment.EnvironmentName = "Development";
|
|
|
|
#endif
|
|
|
|
builder.Configuration.AddJsonFile("settings.json", true, true)
|
2023-08-14 20:54:22 +00:00
|
|
|
.AddJsonFile($"settings.{builder.Environment.EnvironmentName}.json", true)
|
2023-08-14 19:45:00 +00:00
|
|
|
.AddEnvironmentVariables().Build();
|
2023-08-10 08:47:35 +00:00
|
|
|
builder.Services.AddLogging();
|
2023-08-14 19:30:32 +00:00
|
|
|
builder.Logging.AddFile("Logs/Server-{Date}.log", LogLevel.Trace);
|
|
|
|
builder.Logging.AddFile("Logs/Server-{Date}.json.log", LogLevel.Trace, isJson: true);
|
2023-08-14 11:49:27 +00:00
|
|
|
builder.Services.AddEntityFrameworkNpgsql();
|
|
|
|
builder.Services.AddDbContext<WonderkingContext>();
|
2023-08-09 14:23:41 +00:00
|
|
|
builder.Services.AddSingleton<PacketDistributorService>();
|
2023-08-14 19:30:32 +00:00
|
|
|
builder.Services.AddHostedService(provider =>
|
2023-08-09 14:23:41 +00:00
|
|
|
provider.GetService<PacketDistributorService>() ?? throw new InvalidOperationException());
|
|
|
|
builder.Services.AddMassTransit(x =>
|
2022-12-31 13:31:42 +00:00
|
|
|
{
|
2023-08-12 21:02:59 +00:00
|
|
|
x.UsingInMemory((context, configurator) => configurator.ConfigureEndpoints(context));
|
|
|
|
x.AddMediator(cfg => cfg.AddConsumers(Assembly.GetExecutingAssembly()));
|
2022-12-31 13:31:42 +00:00
|
|
|
});
|
2023-08-14 19:30:32 +00:00
|
|
|
builder.Services.AddHostedService(provider => new WonderkingAuthServer(IPAddress.Any, 10001,
|
2023-08-09 14:23:41 +00:00
|
|
|
provider.GetService<ILogger<WonderkingAuthServer>>() ?? throw new InvalidOperationException(),
|
2023-08-10 08:47:35 +00:00
|
|
|
provider.GetService<IServiceProvider>() ?? throw new InvalidOperationException()));
|
2022-12-31 13:31:42 +00:00
|
|
|
|
2023-08-11 09:31:30 +00:00
|
|
|
using var host = builder.Build();
|
2023-08-14 11:49:27 +00:00
|
|
|
await using (var scope = host.Services.CreateAsyncScope())
|
|
|
|
{
|
|
|
|
var db = scope.ServiceProvider.GetRequiredService<WonderkingContext>();
|
2023-10-12 07:15:34 +00:00
|
|
|
await db.Database.MigrateAsync().ConfigureAwait(true);
|
2023-08-14 11:49:27 +00:00
|
|
|
}
|
|
|
|
|
2023-10-12 07:15:34 +00:00
|
|
|
await host.RunAsync().ConfigureAwait(true);
|
2023-08-12 21:02:59 +00:00
|
|
|
#pragma warning restore AV1500
|