using Bts.DataStreamCore.Services; using Bts.PubSub.Services; using Spark.Api.Services; using System.Reactive.Linq; var builder = WebApplication.CreateBuilder(new WebApplicationOptions { Args = args, ApplicationName = "Bts.DataStreamWebApp.Server", }); ConfigureApp(builder.Configuration); ConfigureServices(builder.Services, builder.Configuration); var app = builder.Build(); if (app.Environment.IsDevelopment()) { app.UseDirectoryBrowser(); } var wsOpts = new WebSocketOptions { KeepAliveInterval = TimeSpan.FromMinutes(2) }; app.UseWebSockets(wsOpts); app.UseDefaultFiles(); app.UseStaticFiles(); if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(); } app.UseHttpsRedirection(); app.UseAuthorization(); app.MapControllers(); try { Console.Write($"Starting Application"); app.Run(); Console.Write($"Application exited gracefully."); } catch (Exception ex) { Console.Error.Write($"Application crashed: {ex}"); return 1; } return 0; static void ConfigureApp(ConfigurationManager configBuilder) { configBuilder.AddCommandLine(Environment.GetCommandLineArgs()); var cfgRoot = configBuilder.GetSection("config"); if (cfgRoot?.Value is not null) { configBuilder.AddJsonFile(cfgRoot.Value); } } static void ConfigureServices(IServiceCollection services, IConfiguration config) { services.AddDirectoryBrowser(); services.AddControllers(); services.AddEndpointsApiExplorer(); services.AddSwaggerGen(); services.AddMasterWorker(config.GetSection("MasterWorker")); services.AddViewStreamDatabase(config.GetSection("ViewStreamDatabase")); services.AddPubSubClient(config.GetSection("PubSub")); services.AddSparkd(config.GetSection("Sparkd")); }