feat: Add DataStream WebApp
Included in DataStreamSuite.sln, but not DataStreamQueryAnalyzer.sln
This commit is contained in:
1 parent
a62ea64c5e
commit
1531a57bc5
65 files changed
+8690
-63
No files matched your search
@@ -0,0 +1,73 @@
|
||||
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<DataStreamWebAppServerConfig>(args).
|
||||
MapResult(Run, errors => Task.FromResult(1));
|
||||
|
||||
async Task<int> 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;
|
||||
}
|
||||
Reference in new issue
Block a user