feat: add scientific planning dashboard
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
|
||||
namespace TrajectoryPlanningVisualization;
|
||||
|
||||
public static class EmbeddedWebAssets
|
||||
{
|
||||
private const string ResourcePrefix = "TrajectoryPlanningVisualization.Web.";
|
||||
|
||||
public static string ReadText(string fileName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
{
|
||||
throw new ArgumentException("A web asset file name is required.", nameof(fileName));
|
||||
}
|
||||
|
||||
Assembly assembly = typeof(EmbeddedWebAssets).Assembly;
|
||||
using Stream stream = assembly.GetManifestResourceStream(ResourcePrefix + fileName)
|
||||
?? throw new InvalidOperationException("Embedded web asset was not found: " + fileName);
|
||||
using var reader = new StreamReader(stream, new UTF8Encoding(false), true);
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
}
|
||||
@@ -162,9 +162,32 @@ internal sealed class LoopbackVisualizationServer : IDisposable
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.Path == "/")
|
||||
{
|
||||
string page = EmbeddedWebAssets.ReadText("index.html").Replace("__SESSION_TOKEN__", token);
|
||||
WriteResponse(stream, 200, "OK", "text/html; charset=utf-8", page);
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.Path == "/app.css")
|
||||
{
|
||||
WriteResponse(stream, 200, "OK", "text/css; charset=utf-8", EmbeddedWebAssets.ReadText("app.css"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.Path == "/app.js")
|
||||
{
|
||||
WriteResponse(stream, 200, "OK", "application/javascript; charset=utf-8", EmbeddedWebAssets.ReadText("app.js"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (request.Path == "/api/bootstrap")
|
||||
{
|
||||
WriteResponse(stream, 200, "OK", "application/json; charset=utf-8", VisualizationJson.Serialize(staticSnapshot));
|
||||
WriteResponse(stream, 200, "OK", "application/json; charset=utf-8", VisualizationJson.Serialize(new
|
||||
{
|
||||
staticSnapshot,
|
||||
refreshRateHz = options.RefreshRateHz
|
||||
}));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user