using Microsoft.AspNetCore.Builder; using Microsoft.Data.SqlClient; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; // Real authentication, controllers, stored procedures and SignalR, loopback only. // Never starts import, mail, AI, retention or other background workers. internal static class SharedFocusBrowserHost { public static async Task Run() { var line=File.ReadLines("/etc/plotdirector/plotdirector.env").Single(s=>s.StartsWith("ConnectionStrings__DefaultConnection=")); var value=line[(line.IndexOf('=')+1)..].Trim().Trim('"','\''); var sql=new SqlConnectionStringBuilder(value); if(sql.InitialCatalog!="PlotDirector_Development")throw new Exception("Development only"); await using(var db=new SqlConnection(value)){await db.OpenAsync();using var command=db.CreateCommand();command.CommandText="SELECT DB_NAME()";if((string?)await command.ExecuteScalarAsync()!="PlotDirector_Development")throw new Exception("Wrong effective database");} Environment.SetEnvironmentVariable("ConnectionStrings__DefaultConnection",value); var app=PlotLine.Program.BuildApplication(["--environment=Development","--applicationName=PlotLine","--contentRoot="+Path.GetFullPath("PlotLine"),"--DataProtection:KeysPath=/tmp/shared-focus-test-keys"],builder=>{ foreach(var item in builder.Services.Where(s=>s.ServiceType==typeof(IHostedService)).ToArray())builder.Services.Remove(item); builder.Configuration["SqlDiagnostics:Enabled"]="false"; }); app.Urls.Clear();app.Urls.Add("http://127.0.0.1:5258");await app.RunAsync(); } }