using BCG; using bts.api.core; using Bts.DataStreamWebApp.Server; using Bts.PubSub; using CommandLine; using mbts.config; using System.Reactive.Linq; var parser = new Parser(ps => { ps.CaseInsensitiveEnumValues = true; ps.HelpWriter = Console.Out; }); await parser.ParseArguments(args). MapResult(Run, errors => Task.FromResult(1)); async Task Run(DataStreamWebAppServerConfig opts) { Configuration.initialize(); PubSubConfig.SetGlobalConfig(PubSubConfig.Default()); using var context = ServiceContext.create(opts.Sparkd); await context.login(opts.User ?? "bts", opts.Password ?? string.Empty); var vsWorkLoop = Observable.Interval(TimeSpan.FromMilliseconds(200)).Subscribe(_ => { ViewStreamDatabase.instance.doWork(); MasterWorker.getInstance(false).doWork(); }); var builder = WebApplication.CreateBuilder(new WebApplicationOptions { Args = args, ApplicationName = "Bts.DataStreamWebApp.Server", }); if (opts.WebRootPath is not null) { builder.WebHost.UseWebRoot(opts.WebRootPath); } if (opts.ContentRootPath is not null) { builder.WebHost.UseContentRoot(opts.ContentRootPath); } if (opts.EnvironmentName is not null) { builder.WebHost.UseEnvironment(opts.EnvironmentName); } builder.Services.AddDirectoryBrowser(); builder.Services.AddControllers(); builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); 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 { app.Run(); } catch (Exception ex) { Console.WriteLine($"Exception on DataStreamWebsocketServer thread: {ex}"); return 1; } Spark.Core.Disposables.Disposable.dispose(ref vsWorkLoop); return 0; }