| | 1 | | using LGDXRobotCloud.Data.DbContexts; |
| | 2 | | using LGDXRobotCloud.Data.Entities; |
| | 3 | | using LGDXRobotCloud.Data.Services; |
| | 4 | | using Microsoft.AspNetCore.Identity; |
| | 5 | | using Microsoft.EntityFrameworkCore; |
| | 6 | |
|
| | 7 | |
|
| 0 | 8 | | var builder = WebApplication.CreateBuilder(args); |
| 0 | 9 | | builder.Services.AddDbContextPool<LgdxContext>(cfg => |
| 0 | 10 | | cfg.UseNpgsql(builder.Configuration["PGSQLConnectionString"]) |
| 0 | 11 | | .LogTo(Console.WriteLine, LogLevel.Information) |
| 0 | 12 | | .EnableSensitiveDataLogging() |
| 0 | 13 | | .EnableDetailedErrors() |
| 0 | 14 | | ); |
| 0 | 15 | | builder.Services.AddIdentity<LgdxUser, LgdxRole>() |
| 0 | 16 | | .AddEntityFrameworkStores<LgdxContext>(); |
| | 17 | |
|
| 0 | 18 | | var app = builder.Build(); |
| 0 | 19 | | bool initializeData = bool.Parse(builder.Configuration["initialiseData"] ?? "false"); |
| 0 | 20 | | if (initializeData) |
| 0 | 21 | | { |
| | 22 | | // Check connfig |
| 0 | 23 | | if (string.IsNullOrEmpty(builder.Configuration["email"]) || |
| 0 | 24 | | string.IsNullOrEmpty(builder.Configuration["fullName"]) || |
| 0 | 25 | | string.IsNullOrEmpty(builder.Configuration["userName"]) || |
| 0 | 26 | | string.IsNullOrEmpty(builder.Configuration["password"])) |
| 0 | 27 | | { |
| 0 | 28 | | Console.WriteLine("Please provide the following configurations for the first user: Email, Full Name, userName, passw |
| 0 | 29 | | Environment.Exit(1); |
| 0 | 30 | | } |
| | 31 | |
|
| 0 | 32 | | using var scope = app.Services.CreateScope(); |
| 0 | 33 | | InitialiseDataRunner initialiseDataRunner = new(scope.ServiceProvider.GetRequiredService<LgdxContext>()!, scope.Servic |
| 0 | 34 | | await initialiseDataRunner.StartAsync(CancellationToken.None); |
| 0 | 35 | | } |