Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d9243959d | ||
|
|
0b8643ac8e | ||
|
|
7d128f2b47 | ||
|
|
e32b925660 | ||
|
|
b97023f159 | ||
|
|
eb0e055573 | ||
|
|
d82749af15 | ||
|
|
e2686564b4 | ||
|
|
64aea5b068 | ||
|
|
3ce9f57e95 | ||
|
|
5fa284cad3 | ||
|
|
becd19d7e6 | ||
|
|
9be5166c83 | ||
|
|
64863cf28f | ||
|
|
907a1288d9 | ||
|
|
24f4669425 | ||
|
|
7cd8805b48 | ||
|
|
7e776299a4 | ||
|
|
c7d2071047 | ||
|
|
a2b9f7d140 | ||
|
|
0970adec91 | ||
|
|
484b69897d | ||
|
|
b600377bce | ||
|
|
0fe92f4ecc | ||
|
|
9e047cf3ff | ||
|
|
a463c27704 | ||
|
|
0532b4a490 | ||
|
|
8acf07d23c | ||
|
|
148d7e6ba3 | ||
|
|
0bc3394724 | ||
|
|
165f573465 | ||
|
|
6f982f1ae9 | ||
|
|
d709504bb6 | ||
|
|
a86d4490e4 | ||
|
|
1531c6e794 | ||
|
|
90f2c85b0b | ||
|
|
9858ba07c8 | ||
|
|
d939c0efb3 | ||
|
|
71f38f6712 | ||
|
|
f5fc6d560a | ||
|
|
036f5b9c90 | ||
|
|
a29a64b842 | ||
|
|
15949dbab4 | ||
|
|
bcb9056672 | ||
|
|
f665062b35 | ||
|
|
4fb3a15ef0 | ||
|
|
146676bfba | ||
|
|
51b631f09f | ||
|
|
bcfc89f95b | ||
|
|
0026ecbfaa | ||
|
|
f964689a0c | ||
|
|
8d03406fb7 | ||
|
|
5dc67084eb | ||
|
|
cca24399d5 | ||
|
|
46bc00ce87 |
No files matched your search
@@ -66,6 +66,7 @@ RUN \
|
|||||||
|
|
||||||
# Dotnet
|
# Dotnet
|
||||||
RUN apt-get update && apt-get install -y dotnet7
|
RUN apt-get update && apt-get install -y dotnet7
|
||||||
|
RUN apt-get update && apt-get install -y dotnet8
|
||||||
|
|
||||||
# Node
|
# Node
|
||||||
ARG node_major=18
|
ARG node_major=18
|
||||||
@@ -87,11 +88,6 @@ RUN dpkg -i /emumba/emumba-deribit-connector-3.3.1-Linux.LICENSE_DISABLED.deb \
|
|||||||
# Pcap
|
# Pcap
|
||||||
RUN apt-get update && apt-get install -y libpcap0.8-dev
|
RUN apt-get update && apt-get install -y libpcap0.8-dev
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
|
||||||
docker.io \
|
|
||||||
docker-compose \
|
|
||||||
docker-compose-v2
|
|
||||||
|
|
||||||
# Set up default executables (update-alternatives)
|
# Set up default executables (update-alternatives)
|
||||||
RUN \
|
RUN \
|
||||||
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-$clang_major 100; \
|
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-$clang_major 100; \
|
||||||
@@ -125,5 +121,3 @@ RUN \
|
|||||||
-G sudo \
|
-G sudo \
|
||||||
--password "$(openssl passwd -1 "$docker_pass")" \
|
--password "$(openssl passwd -1 "$docker_pass")" \
|
||||||
"$docker_user"
|
"$docker_user"
|
||||||
|
|
||||||
RUN usermod -aG docker "$docker_user"
|
|
||||||
@@ -18,12 +18,27 @@
|
|||||||
"runArgs": [
|
"runArgs": [
|
||||||
"--shm-size",
|
"--shm-size",
|
||||||
"2gb",
|
"2gb",
|
||||||
"--network",
|
"-p",
|
||||||
"host"
|
"5000:5000",
|
||||||
|
"-p",
|
||||||
|
"5001:5001",
|
||||||
|
"-p",
|
||||||
|
"5173:5173",
|
||||||
|
"-p",
|
||||||
|
"5174:5174",
|
||||||
|
"-p",
|
||||||
|
"8000:8000",
|
||||||
|
"-p",
|
||||||
|
"8001:8001",
|
||||||
|
"-p",
|
||||||
|
"8002:8002",
|
||||||
|
"-p",
|
||||||
|
"8003:8003",
|
||||||
|
"-p",
|
||||||
|
"12345:12345",
|
||||||
],
|
],
|
||||||
"mounts": [
|
"mounts": [
|
||||||
"source=${localEnv:HOME}/.bts/devcontainer-mounts/${devcontainerId},target=/home/bts,type=bind",
|
"source=${localEnv:HOME}/.bts/devcontainer-mounts/${devcontainerId},target=/home/bts,type=bind"
|
||||||
"source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind"
|
|
||||||
],
|
],
|
||||||
"customizations": {
|
"customizations": {
|
||||||
"vscode": {
|
"vscode": {
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
*.cmd text=auto eol=crlf
|
*.cmd text=auto eol=crlf
|
||||||
*.cs text=auto eol=crlf
|
*.cs text=auto eol=crlf
|
||||||
*.sh text=auto eol=lf
|
*.sh text=auto eol=lf
|
||||||
*.py text=auto eol=lf
|
|
||||||
Vendored
+41
-140
@@ -6,52 +6,18 @@
|
|||||||
"type": "coreclr",
|
"type": "coreclr",
|
||||||
"request": "attach"
|
"request": "attach"
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"name": "Api Server",
|
|
||||||
"type": "coreclr",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "",
|
|
||||||
"windows": {
|
|
||||||
"preLaunchTask": "Build Api Server (Debug)",
|
|
||||||
"program": "spark_api_server.exe",
|
|
||||||
"args": [
|
|
||||||
"run",
|
|
||||||
"--sparkd",
|
|
||||||
"http://127.0.0.1:8000/config"
|
|
||||||
],
|
|
||||||
"cwd": "build/Debug/bin/net7.0",
|
|
||||||
},
|
|
||||||
"stopAtEntry": false,
|
|
||||||
"console": "integratedTerminal"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Api Server (Skip Build)",
|
|
||||||
"type": "coreclr",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "",
|
|
||||||
"windows": {
|
|
||||||
"program": "spark_api_server.exe",
|
|
||||||
"args": [
|
|
||||||
"run",
|
|
||||||
"--sparkd",
|
|
||||||
"http://127.0.0.1:8000/config"
|
|
||||||
],
|
|
||||||
"cwd": "build/Debug/bin/net7.0",
|
|
||||||
},
|
|
||||||
"stopAtEntry": false,
|
|
||||||
"console": "integratedTerminal"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"name": "Bts.DataStreamWebApp.Server",
|
"name": "Bts.DataStreamWebApp.Server",
|
||||||
"type": "coreclr",
|
"type": "coreclr",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"preLaunchTask": "Build DataStream WebApp (Debug)",
|
"preLaunchTask": "Build DataStream WebApp (Debug)",
|
||||||
"program": "${workspaceFolder}/build/Debug/bin/net7.0/Bts.DataStreamWebApp.Server.dll",
|
"program": "${workspaceFolder}/build/Debug/bin/net8.0/Bts.DataStreamWebApp.Server.dll",
|
||||||
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
"args": [
|
||||||
|
"--sparkd",
|
||||||
|
"http://localhost:8000/config",
|
||||||
|
],
|
||||||
"env": {
|
"env": {
|
||||||
"ASPNETCORE_HTTP_PORT": "8080",
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "${input:dataStreamWebAppServerEnvironment}",
|
|
||||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -59,12 +25,13 @@
|
|||||||
"name": "Bts.DataStreamWebApp.Server (Skip Build)",
|
"name": "Bts.DataStreamWebApp.Server (Skip Build)",
|
||||||
"type": "coreclr",
|
"type": "coreclr",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/build/Debug/bin/net7.0/Bts.DataStreamWebApp.Server.dll",
|
"program": "${workspaceFolder}/build/Debug/bin/net8.0/Bts.DataStreamWebApp.Server.dll",
|
||||||
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
// "args": [
|
||||||
|
// "--config",
|
||||||
|
// "${workspaceFolder}/src/DataStreamSuite/Bts.DataStreamWebApp.Server/Configurations/DevServer.json",
|
||||||
|
// ],
|
||||||
"env": {
|
"env": {
|
||||||
"ASPNETCORE_HTTP_PORT": "8080",
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "${input:dataStreamWebAppServerEnvironment}",
|
|
||||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -80,9 +47,10 @@
|
|||||||
"windows": {
|
"windows": {
|
||||||
"program": "DataStreamPublisher.exe",
|
"program": "DataStreamPublisher.exe",
|
||||||
},
|
},
|
||||||
"env": {
|
"args": [
|
||||||
"DOTNET_ENVIRONMENT": "${input:dataStreamPublisherEnvironment}",
|
"--config",
|
||||||
},
|
"${workspaceFolder}/src/DataStreamSuite/DataStreamPublisher/Configurations/${input:dataStreamPublisherConfig}.json"
|
||||||
|
],
|
||||||
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal"
|
||||||
@@ -98,9 +66,10 @@
|
|||||||
"windows": {
|
"windows": {
|
||||||
"program": "DataStreamPublisher.exe",
|
"program": "DataStreamPublisher.exe",
|
||||||
},
|
},
|
||||||
"env": {
|
"args": [
|
||||||
"DOTNET_ENVIRONMENT": "${input:dataStreamPublisherEnvironment}",
|
"--config",
|
||||||
},
|
"${workspaceFolder}/src/DataStreamSuite/DataStreamPublisher/Configurations/${input:dataStreamPublisherConfig}.json"
|
||||||
|
],
|
||||||
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal"
|
||||||
@@ -137,10 +106,11 @@
|
|||||||
"windows": {
|
"windows": {
|
||||||
"program": "PubSubServer.exe",
|
"program": "PubSubServer.exe",
|
||||||
},
|
},
|
||||||
|
"args": [
|
||||||
|
"--config",
|
||||||
|
"${workspaceFolder}/src/DataStreamSuite/PubSubServer/Configurations/${input:pubSubServerConfig}.json"
|
||||||
|
],
|
||||||
"cwd": "build/Debug/bin/net7.0",
|
"cwd": "build/Debug/bin/net7.0",
|
||||||
"env": {
|
|
||||||
"DOTNET_ENVIRONMENT": "${input:pubSubServerEnvironment}",
|
|
||||||
},
|
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal"
|
||||||
},
|
},
|
||||||
@@ -155,10 +125,11 @@
|
|||||||
"windows": {
|
"windows": {
|
||||||
"program": "PubSubServer.exe",
|
"program": "PubSubServer.exe",
|
||||||
},
|
},
|
||||||
|
"args": [
|
||||||
|
"--config",
|
||||||
|
"${workspaceFolder}/src/DataStreamSuite/PubSubServer/Configurations/${input:pubSubServerConfig}.json"
|
||||||
|
],
|
||||||
"cwd": "build/Debug/bin/net7.0",
|
"cwd": "build/Debug/bin/net7.0",
|
||||||
"env": {
|
|
||||||
"DOTNET_ENVIRONMENT": "${input:pubSubServerEnvironment}",
|
|
||||||
},
|
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"console": "integratedTerminal"
|
"console": "integratedTerminal"
|
||||||
},
|
},
|
||||||
@@ -170,10 +141,6 @@
|
|||||||
"windows": {
|
"windows": {
|
||||||
"preLaunchTask": "Build Spark (Debug)",
|
"preLaunchTask": "Build Spark (Debug)",
|
||||||
"program": "Spark.exe",
|
"program": "Spark.exe",
|
||||||
"args": [
|
|
||||||
"--sparkd",
|
|
||||||
"http://127.0.0.1:8000/config"
|
|
||||||
],
|
|
||||||
"cwd": "build/Debug/bin/net7.0-windows",
|
"cwd": "build/Debug/bin/net7.0-windows",
|
||||||
},
|
},
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
@@ -198,99 +165,43 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Sparkd",
|
"name": "Sparkd",
|
||||||
"type": "cppdbg",
|
"type": "coreclr",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"preLaunchTask": "Build Sparkd (Debug | Clang)",
|
"preLaunchTask": "Build Sparkd (Debug | Clang)",
|
||||||
"program": "",
|
"program": "",
|
||||||
"linux": {
|
"linux": {
|
||||||
"program": "${workspaceFolder}/build/sparkd-debug-clang/server/sparkd",
|
"program": "sparkd",
|
||||||
},
|
},
|
||||||
"args": [
|
"args": [
|
||||||
"run"
|
"run"
|
||||||
],
|
],
|
||||||
"cwd": "${workspaceFolder}/build/sparkd-debug-clang/server",
|
"cwd": "build/sparkd-debug-clang/server",
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"externalConsole": false,
|
"console": "integratedTerminal"
|
||||||
"MIMode": "gdb",
|
|
||||||
"setupCommands": [
|
|
||||||
{
|
|
||||||
"description": "Enable pretty-printing for gdb",
|
|
||||||
"text": "-enable-pretty-printing",
|
|
||||||
"ignoreFailures": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Set Disassembly Flavor to Intel",
|
|
||||||
"text": "-gdb-set disassembly-flavor intel",
|
|
||||||
"ignoreFailures": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Sparkd (Skip Build)",
|
|
||||||
"type": "cppdbg",
|
|
||||||
"request": "launch",
|
|
||||||
"program": "",
|
|
||||||
"linux": {
|
|
||||||
"program": "${workspaceFolder}/build/sparkd-debug-clang/server/sparkd",
|
|
||||||
},
|
|
||||||
"args": [
|
|
||||||
"run"
|
|
||||||
],
|
|
||||||
"cwd": "${workspaceFolder}/build/sparkd-debug-clang/server",
|
|
||||||
"stopAtEntry": false,
|
|
||||||
"externalConsole": false,
|
|
||||||
"MIMode": "gdb",
|
|
||||||
"setupCommands": [
|
|
||||||
{
|
|
||||||
"description": "Enable pretty-printing for gdb",
|
|
||||||
"text": "-enable-pretty-printing",
|
|
||||||
"ignoreFailures": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"description": "Set Disassembly Flavor to Intel",
|
|
||||||
"text": "-gdb-set disassembly-flavor intel",
|
|
||||||
"ignoreFailures": true
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
"id": "dataStreamPublisherEnvironment",
|
"id": "dataStreamPublisherConfig",
|
||||||
"type": "pickString",
|
"type": "pickString",
|
||||||
"description": "Publisher Configuration",
|
"description": "Publisher Configuration",
|
||||||
"options": [
|
"options": [
|
||||||
"Development",
|
"MarketDataPublisher",
|
||||||
"MarketData",
|
"SimpleEchoClient",
|
||||||
"Production",
|
"SimpleTestDataPublisher",
|
||||||
"ProductionAws",
|
"TestDataPublisher",
|
||||||
"Staging",
|
|
||||||
],
|
],
|
||||||
"default": "MarketDataPublisher",
|
"default": "MarketDataPublisher",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "pubSubServerEnvironment",
|
"id": "pubSubServerConfig",
|
||||||
"type": "pickString",
|
"type": "pickString",
|
||||||
"description": "PubSub Configuration",
|
"description": "PubSub Configuration",
|
||||||
"options": [
|
"options": [
|
||||||
"Development",
|
"PubSubServer",
|
||||||
"EchoServer",
|
"SimpleEchoClient",
|
||||||
"Production",
|
|
||||||
"ProductionAws",
|
|
||||||
"Staging",
|
|
||||||
],
|
],
|
||||||
"default": "Development",
|
"default": "PubSubServer",
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "dataStreamWebAppServerEnvironment",
|
|
||||||
"type": "pickString",
|
|
||||||
"description": "DataStream WebApp Environment",
|
|
||||||
"options": [
|
|
||||||
"Development",
|
|
||||||
"Production",
|
|
||||||
"ProductionAws",
|
|
||||||
"Staging",
|
|
||||||
]
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"id": "sparkConfigServer",
|
"id": "sparkConfigServer",
|
||||||
@@ -298,15 +209,5 @@
|
|||||||
"description": "Config Server URL",
|
"description": "Config Server URL",
|
||||||
"default": "http://localhost:8000/config",
|
"default": "http://localhost:8000/config",
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id": "isSparkApiEnabled",
|
|
||||||
"type": "pickString",
|
|
||||||
"description": "Enable Spark Api (connect to sparkd)",
|
|
||||||
"options": [
|
|
||||||
"True",
|
|
||||||
"False",
|
|
||||||
],
|
|
||||||
"default": "True",
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
Vendored
-103
@@ -212,26 +212,6 @@
|
|||||||
"color": "terminal.ansiCyan"
|
"color": "terminal.ansiCyan"
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"label": "Build DataStream WebApp (Release)",
|
|
||||||
"group": "build",
|
|
||||||
"type": "process",
|
|
||||||
"command": "",
|
|
||||||
"linux": {
|
|
||||||
"command": "tools/build_data_stream_web_app.sh",
|
|
||||||
},
|
|
||||||
"windows": {
|
|
||||||
"command": "tools/build_data_stream_web_app.cmd",
|
|
||||||
},
|
|
||||||
"args": [
|
|
||||||
"--configuration",
|
|
||||||
"Release",
|
|
||||||
],
|
|
||||||
"icon": {
|
|
||||||
"id": "terminal",
|
|
||||||
"color": "terminal.ansiCyan"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"label": "Build Spark",
|
"label": "Build Spark",
|
||||||
"group": "build",
|
"group": "build",
|
||||||
@@ -607,89 +587,6 @@
|
|||||||
"color": "terminal.ansiGreen",
|
"color": "terminal.ansiGreen",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"label": "Run DataStream WebApp (Debug)",
|
|
||||||
"dependsOn": "Build DataStream WebApp (Debug)",
|
|
||||||
"command": "",
|
|
||||||
"linux": {
|
|
||||||
"command": "Bts.DataStreamWebApp.Server",
|
|
||||||
},
|
|
||||||
"windows": {
|
|
||||||
"command": "Bts.DataStreamWebApp.Server.exe",
|
|
||||||
},
|
|
||||||
"args": [
|
|
||||||
"--config",
|
|
||||||
"${workspaceFolder}/src/DataStreamSuite/Bts.DataStreamWebApp.Server/Configurations/DevServer.json",
|
|
||||||
],
|
|
||||||
"options": {
|
|
||||||
"cwd": "${workspaceFolder}/build/Debug/bin/net7.0",
|
|
||||||
"env": {
|
|
||||||
"ASPNETCORE_HTTP_PORT": "8080",
|
|
||||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
|
||||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"icon": {
|
|
||||||
"id": "run",
|
|
||||||
"color": "terminal.ansiGreen",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Run DataStream WebApp (Release)",
|
|
||||||
"dependsOn": "Build DataStream WebApp (Release)",
|
|
||||||
"command": "",
|
|
||||||
"linux": {
|
|
||||||
"command": "Bts.DataStreamWebApp.Server",
|
|
||||||
},
|
|
||||||
"windows": {
|
|
||||||
"command": "Bts.DataStreamWebApp.Server.exe",
|
|
||||||
},
|
|
||||||
"args": [
|
|
||||||
"--config",
|
|
||||||
"${workspaceFolder}/src/DataStreamSuite/Bts.DataStreamWebApp.Server/Configurations/DevServer.json",
|
|
||||||
],
|
|
||||||
"options": {
|
|
||||||
"cwd": "${workspaceFolder}/build/Release/bin/net7.0",
|
|
||||||
"env": {
|
|
||||||
"ASPNETCORE_HTTP_PORT": "8080",
|
|
||||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Production",
|
|
||||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"icon": {
|
|
||||||
"id": "run",
|
|
||||||
"color": "terminal.ansiGreen",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"label": "Run DataStream WebApp (Release | Skip Build)",
|
|
||||||
"command": "",
|
|
||||||
"linux": {
|
|
||||||
"command": "Bts.DataStreamWebApp.Server",
|
|
||||||
},
|
|
||||||
"windows": {
|
|
||||||
"command": "Bts.DataStreamWebApp.Server.exe",
|
|
||||||
},
|
|
||||||
"args": [
|
|
||||||
"--config",
|
|
||||||
"${workspaceFolder}/src/DataStreamSuite/Bts.DataStreamWebApp.Server/Configurations/DevServer.json",
|
|
||||||
],
|
|
||||||
"options": {
|
|
||||||
"cwd": "${workspaceFolder}/build/Release/bin/net7.0",
|
|
||||||
"env": {
|
|
||||||
"ASPNETCORE_HTTP_PORT": "8080",
|
|
||||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Production",
|
|
||||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"icon": {
|
|
||||||
"id": "run",
|
|
||||||
"color": "terminal.ansiGreen",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"label": "Run PubSubServer",
|
"label": "Run PubSubServer",
|
||||||
"dependsOn": "Build DataStream",
|
"dependsOn": "Build DataStream",
|
||||||
|
|||||||
+43
-15
@@ -19,9 +19,9 @@ set(
|
|||||||
# can run simultaneously without fighting over the same shm files (e.g., sparkd,
|
# can run simultaneously without fighting over the same shm files (e.g., sparkd,
|
||||||
# api server, etc.).
|
# api server, etc.).
|
||||||
set(SHARED_MEMORY_PREFIX "bts" CACHE STRING "Prefix to use when creating shared memory files")
|
set(SHARED_MEMORY_PREFIX "bts" CACHE STRING "Prefix to use when creating shared memory files")
|
||||||
set(EXTERNALS_BIN "${EXTERNALS_ROOT}/bin")
|
set(SPARK_BIN "${EXTERNALS_ROOT}/bin")
|
||||||
set(EXTERNALS_INCLUDE "${EXTERNALS_ROOT}/include")
|
set(SPARK_INCLUDE "${EXTERNALS_ROOT}/include")
|
||||||
set(EXTERNALS_LIB "${EXTERNALS_ROOT}/lib/$<CONFIG>")
|
set(SPARK_LIB "${EXTERNALS_ROOT}/lib/$<CONFIG>")
|
||||||
set(BUILD_DOCS OFF CACHE BOOL "Build documentation")
|
set(BUILD_DOCS OFF CACHE BOOL "Build documentation")
|
||||||
set(BUILD_SDK OFF CACHE BOOL "Build the sdk")
|
set(BUILD_SDK OFF CACHE BOOL "Build the sdk")
|
||||||
set(EXPORT_MD_CONSUMER OFF CACHE BOOL "Export (extern) C functions for MD consumer interop")
|
set(EXPORT_MD_CONSUMER OFF CACHE BOOL "Export (extern) C functions for MD consumer interop")
|
||||||
@@ -33,22 +33,24 @@ else()
|
|||||||
set(BUILD_ADMIN_WEB_APP ON CACHE BOOL "Build the Admin WebApp")
|
set(BUILD_ADMIN_WEB_APP ON CACHE BOOL "Build the Admin WebApp")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories(BEFORE SYSTEM ${EXTERNALS_INCLUDE} ${EXTERNALS_ROOT}/include/zlib)
|
include_directories(BEFORE SYSTEM ${SPARK_INCLUDE} ${EXTERNALS_ROOT}/include/zlib)
|
||||||
link_directories(${EXTERNALS_LIB})
|
link_directories(${SPARK_LIB})
|
||||||
|
|
||||||
add_compile_definitions(SHARED_MEMORY_PREFIX="${SHARED_MEMORY_PREFIX}")
|
add_compile_definitions(SHARED_MEMORY_PREFIX="${SHARED_MEMORY_PREFIX}")
|
||||||
if(DEFINED APP_DATA_DIR)
|
add_compile_definitions(APP_DATA_DIR="${APP_DATA_DIR}")
|
||||||
add_compile_definitions(APP_DATA_DIR="${APP_DATA_DIR}")
|
if(DEFINED APP_DATA_DIR_OVERRIDE)
|
||||||
|
add_compile_definitions(APP_DATA_DIR_OVERRIDE="${APP_DATA_DIR_OVERRIDE}")
|
||||||
endif()
|
endif()
|
||||||
add_compile_definitions(EXPORT_MD_CONSUMER="${EXPORT_MD_CONSUMER}")
|
add_compile_definitions(EXPORT_MD_CONSUMER="${EXPORT_MD_CONSUMER}")
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
# subdirs
|
# subdirs
|
||||||
add_subdirectory(src/lib_spark)
|
add_subdirectory(src/lib)
|
||||||
else()
|
else()
|
||||||
# make sparkd look for libspark.so in its directory
|
# make sparkd look for libspark.so in its directory
|
||||||
# set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
set(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||||
# set(CMAKE_INSTALL_RPATH ".")
|
set(CMAKE_INSTALL_RPATH ".")
|
||||||
# set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install/$<CONFIG>")
|
set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install")
|
||||||
|
set(SPARK_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}/$<CONFIG>")
|
||||||
|
|
||||||
if(BUILD_SPARKD)
|
if(BUILD_SPARKD)
|
||||||
# Note: All macros that begin w/ 'CCAPI' are ccapi's macros (defined and/or
|
# Note: All macros that begin w/ 'CCAPI' are ccapi's macros (defined and/or
|
||||||
@@ -109,12 +111,10 @@ else()
|
|||||||
|
|
||||||
# subdirs
|
# subdirs
|
||||||
if (BUILD_SPARKD)
|
if (BUILD_SPARKD)
|
||||||
add_subdirectory(src/app_sparkd)
|
add_subdirectory(src/server/sparkd)
|
||||||
add_subdirectory(src/data_files)
|
add_subdirectory(src/data_files)
|
||||||
add_subdirectory(src/lib_py_market_data)
|
|
||||||
# add_subdirectory(src/py_market_data_providers)
|
|
||||||
endif()
|
endif()
|
||||||
add_subdirectory(src/lib_spark)
|
add_subdirectory(src/lib)
|
||||||
if (BUILD_ADMIN_WEB_APP)
|
if (BUILD_ADMIN_WEB_APP)
|
||||||
add_subdirectory(src/Spark.Admin.WebApp)
|
add_subdirectory(src/Spark.Admin.WebApp)
|
||||||
endif()
|
endif()
|
||||||
@@ -124,4 +124,32 @@ else()
|
|||||||
if(BUILD_SDK)
|
if(BUILD_SDK)
|
||||||
add_subdirectory(src/sdk)
|
add_subdirectory(src/sdk)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(BUILD_SPARKD)
|
||||||
|
add_custom_command(
|
||||||
|
OUTPUT ${CMAKE_BINARY_DIR}/server
|
||||||
|
COMMAND mkdir -p ${CMAKE_BINARY_DIR}/server
|
||||||
|
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/src/server/sparkd/sparkd ${CMAKE_BINARY_DIR}/server
|
||||||
|
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/data_files ${CMAKE_BINARY_DIR}/server
|
||||||
|
COMMAND ln ARGS -sf ${CMAKE_BINARY_DIR}/src/lib/libspark.so ${CMAKE_BINARY_DIR}/server
|
||||||
|
COMMAND
|
||||||
|
ln ARGS -sf
|
||||||
|
${EXTERNALS_ROOT}/lib/Release/libOnixS.IceImpactMulticastPriceFeedHandlerCpp.so.3.16.0.0
|
||||||
|
${CMAKE_BINARY_DIR}/server
|
||||||
|
COMMAND ln ARGS -sf ${EXTERNALS_ROOT}/lib/Release/libACE-5.7.5.so ${CMAKE_BINARY_DIR}/server
|
||||||
|
COMMAND mkdir ARGS -p ${CMAKE_BINARY_DIR}/server/plugins
|
||||||
|
COMMENT "Creating server runtime layout"
|
||||||
|
DEPENDS sparkd data_files_dir)
|
||||||
|
|
||||||
|
add_custom_target(server_layout ALL DEPENDS ${CMAKE_BINARY_DIR}/server)
|
||||||
|
|
||||||
|
install(
|
||||||
|
DIRECTORY "${CMAKE_BINARY_DIR}/server/plugins"
|
||||||
|
DESTINATION "${SPARK_INSTALL_PREFIX}/bin")
|
||||||
|
install(
|
||||||
|
FILES
|
||||||
|
"${SPARK_LIB}/libACE-5.7.5.so"
|
||||||
|
"${SPARK_LIB}/libOnixS.IceImpactMulticastPriceFeedHandlerCpp.so.3.16.0.0"
|
||||||
|
DESTINATION "${SPARK_INSTALL_PREFIX}/bin")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
+41
-14
@@ -20,6 +20,8 @@
|
|||||||
"SPARK_CMAKE_CXX_FLAGS": "/MP /WX /wd4250 /wd4251 /wd4244 /wd4267 /wd4355 /wd4275 /wd4345 /bigobj /EHsc /DCURL_STATICLIB /D_WINSOCK_DEPRECATED_NO_WARNINGS /D__TBB_NO_IMPLICIT_LINKAGE /DBOOST_ALL_NO_LIB /std:c++20 /D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /D_WIN32_WINNT=0x0600"
|
"SPARK_CMAKE_CXX_FLAGS": "/MP /WX /wd4250 /wd4251 /wd4244 /wd4267 /wd4355 /wd4275 /wd4345 /bigobj /EHsc /DCURL_STATICLIB /D_WINSOCK_DEPRECATED_NO_WARNINGS /D__TBB_NO_IMPLICIT_LINKAGE /DBOOST_ALL_NO_LIB /std:c++20 /D_SCL_SECURE_NO_WARNINGS /D_CRT_SECURE_NO_WARNINGS /D_WIN32_WINNT=0x0600"
|
||||||
},
|
},
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
|
"APP_DATA_DIR": "${dollar}{APPDATA}/bts",
|
||||||
|
"APP_DATA_DIR_OVERRIDE": "${dollar}{SPARK_DATA_DIR}",
|
||||||
"CMAKE_CXX_FLAGS": "$env{SPARK_CMAKE_CXX_FLAGS}",
|
"CMAKE_CXX_FLAGS": "$env{SPARK_CMAKE_CXX_FLAGS}",
|
||||||
"CMAKE_CXX_FLAGS_DEBUG": "$env{SPARK_CMAKE_CXX_FLAGS} /MTd",
|
"CMAKE_CXX_FLAGS_DEBUG": "$env{SPARK_CMAKE_CXX_FLAGS} /MTd",
|
||||||
"CMAKE_CXX_FLAGS_RELEASE": "$env{SPARK_CMAKE_CXX_FLAGS} /MT",
|
"CMAKE_CXX_FLAGS_RELEASE": "$env{SPARK_CMAKE_CXX_FLAGS} /MT",
|
||||||
@@ -33,7 +35,8 @@
|
|||||||
"EXPORT_MD_CONSUMER": {
|
"EXPORT_MD_CONSUMER": {
|
||||||
"type": "BOOL",
|
"type": "BOOL",
|
||||||
"value": "ON"
|
"value": "ON"
|
||||||
}
|
},
|
||||||
|
"SHARED_MEMORY_PREFIX": "spark"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -49,9 +52,15 @@
|
|||||||
"binaryDir": "${sourceDir}/build/${presetName}",
|
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
"platform": "",
|
"platform": "",
|
||||||
|
"APP_DATA_DIR": "${dollar}{HOME}/sparkdata",
|
||||||
|
"APP_DATA_DIR_OVERRIDE": "${dollar}{SPARKD_DATA_DIR}",
|
||||||
|
"CMAKE_BUILD_WITH_INSTALL_RPATH": {
|
||||||
|
"type": "BOOL",
|
||||||
|
"value": "ON"
|
||||||
|
},
|
||||||
"CMAKE_CXX_STANDARD": "20",
|
"CMAKE_CXX_STANDARD": "20",
|
||||||
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}",
|
"CMAKE_INSTALL_RPATH": ".",
|
||||||
"CMAKE_PREFIX_PATH": "${sourceDir}/cmake/;${sourceDir}/.venv/lib/python3.10/site-packages/pybind11/share/cmake/pybind11",
|
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}/sparkd",
|
||||||
"CMAKE_EXE_LINKER_FLAGS": "-Wno-undef",
|
"CMAKE_EXE_LINKER_FLAGS": "-Wno-undef",
|
||||||
"EXTERNALS_ROOT": "${sourceDir}/externals/linux",
|
"EXTERNALS_ROOT": "${sourceDir}/externals/linux",
|
||||||
"BUILD_SDK": {
|
"BUILD_SDK": {
|
||||||
@@ -61,7 +70,8 @@
|
|||||||
"BUILD_ADMIN_WEB_APP": {
|
"BUILD_ADMIN_WEB_APP": {
|
||||||
"type": "BOOL",
|
"type": "BOOL",
|
||||||
"value": "ON"
|
"value": "ON"
|
||||||
}
|
},
|
||||||
|
"SHARED_MEMORY_PREFIX": "sparkd"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -142,7 +152,11 @@
|
|||||||
{
|
{
|
||||||
"name": "spark-api-server-windows",
|
"name": "spark-api-server-windows",
|
||||||
"inherits": "spark",
|
"inherits": "spark",
|
||||||
"displayName": "Spark Api Server (Windows)"
|
"displayName": "Spark Api Server (Windows)",
|
||||||
|
"cacheVariables": {
|
||||||
|
"APP_DATA_DIR_OVERRIDE": "${dollar}{SPARK_API_SERVER_DATA_DIR}",
|
||||||
|
"SHARED_MEMORY_PREFIX": "spark_api_server"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
@@ -151,6 +165,7 @@
|
|||||||
"displayName": "Spark Api Server (Linux)",
|
"displayName": "Spark Api Server (Linux)",
|
||||||
"generator": "Ninja Multi-Config",
|
"generator": "Ninja Multi-Config",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
|
"APP_DATA_DIR_OVERRIDE": "${dollar}{SPARK_API_SERVER_DATA_DIR}",
|
||||||
"BUILD_ADMIN_WEB_APP": {
|
"BUILD_ADMIN_WEB_APP": {
|
||||||
"type": "BOOL",
|
"type": "BOOL",
|
||||||
"value": "OFF"
|
"value": "OFF"
|
||||||
@@ -163,12 +178,9 @@
|
|||||||
"CMAKE_CXX_COMPILER": "clang++",
|
"CMAKE_CXX_COMPILER": "clang++",
|
||||||
"CMAKE_CXX_FLAGS_DEBUG": "-g -fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -DDEBUG",
|
"CMAKE_CXX_FLAGS_DEBUG": "-g -fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -DDEBUG",
|
||||||
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -fno-omit-frame-pointer -DNDEBUG -O3",
|
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -fno-omit-frame-pointer -DNDEBUG -O3",
|
||||||
"CMAKE_EXPORT_COMPILE_COMMANDS": {
|
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}",
|
||||||
"type": "BOOL",
|
|
||||||
"value": "ON"
|
|
||||||
},
|
|
||||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf",
|
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf",
|
||||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/Spark.Api.Server/$<CONFIG>/bin/net7.0",
|
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0",
|
||||||
"EXPORT_MD_CONSUMER": {
|
"EXPORT_MD_CONSUMER": {
|
||||||
"type": "BOOL",
|
"type": "BOOL",
|
||||||
"value": "ON"
|
"value": "ON"
|
||||||
@@ -206,8 +218,11 @@
|
|||||||
"description": "Data Stream utils ported over from Edge",
|
"description": "Data Stream utils ported over from Edge",
|
||||||
"binaryDir": "${sourceDir}/build/${presetName}",
|
"binaryDir": "${sourceDir}/build/${presetName}",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
|
"APP_DATA_DIR": "${dollar}{APPDATA}/bts/DataStream",
|
||||||
|
"APP_DATA_DIR_OVERRIDE": "${dollar}{DATA_STREAM_DATA_DIR}",
|
||||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf;config/profiles/data_stream/*.conf",
|
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf;config/profiles/data_stream/*.conf",
|
||||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net7.0-windows"
|
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net7.0-windows;${sourceDir}/build/$<CONFIG>/bin/net8.0",
|
||||||
|
"SHARED_MEMORY_PREFIX": "data_stream"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -223,6 +238,8 @@
|
|||||||
"inherits": "sparkd",
|
"inherits": "sparkd",
|
||||||
"generator": "Ninja Multi-Config",
|
"generator": "Ninja Multi-Config",
|
||||||
"cacheVariables": {
|
"cacheVariables": {
|
||||||
|
"APP_DATA_DIR": "${dollar}{HOME}/.local/share/DataStream",
|
||||||
|
"APP_DATA_DIR_OVERRIDE": "${dollar}{DATA_STREAM_DATA_DIR}",
|
||||||
"BUILD_ADMIN_WEB_APP": {
|
"BUILD_ADMIN_WEB_APP": {
|
||||||
"type": "BOOL",
|
"type": "BOOL",
|
||||||
"value": "OFF"
|
"value": "OFF"
|
||||||
@@ -239,13 +256,14 @@
|
|||||||
"CMAKE_CXX_COMPILER": "clang++",
|
"CMAKE_CXX_COMPILER": "clang++",
|
||||||
"CMAKE_CXX_FLAGS_DEBUG": "-g -fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -DDEBUG",
|
"CMAKE_CXX_FLAGS_DEBUG": "-g -fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -DDEBUG",
|
||||||
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -fno-omit-frame-pointer -DNDEBUG -O3",
|
"CMAKE_CXX_FLAGS_RELEASE": "-fPIC -Wall -pedantic -Wextra -Werror -Wno-missing-braces -Wno-ignored-qualifiers --std=c++20 -fdiagnostics-color -fno-omit-frame-pointer -DNDEBUG -O3",
|
||||||
|
"CMAKE_INSTALL_PREFIX": "${sourceDir}/install/${presetName}",
|
||||||
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf;config/profiles/data_stream/*.conf",
|
"CONFIG_DEFAULTS_PATH": "config/profiles/default/*.conf;config/profiles/data_stream/*.conf",
|
||||||
"CONFIG_PROFILES": "default;data_stream",
|
|
||||||
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net8.0",
|
"DOTNET_BINARY_DIR": "${sourceDir}/build/$<CONFIG>/bin/net7.0;${sourceDir}/build/$<CONFIG>/bin/net8.0",
|
||||||
"EXPORT_MD_CONSUMER": {
|
"EXPORT_MD_CONSUMER": {
|
||||||
"type": "BOOL",
|
"type": "BOOL",
|
||||||
"value": "ON"
|
"value": "ON"
|
||||||
}
|
},
|
||||||
|
"SHARED_MEMORY_PREFIX": "data_stream"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -284,7 +302,16 @@
|
|||||||
"lhs": "${hostSystemName}",
|
"lhs": "${hostSystemName}",
|
||||||
"rhs": "Linux"
|
"rhs": "Linux"
|
||||||
},
|
},
|
||||||
"hidden": true
|
"hidden": true,
|
||||||
|
"targets": [
|
||||||
|
"data_files_dir",
|
||||||
|
"admin_web_app_bundle",
|
||||||
|
"install",
|
||||||
|
"libspark",
|
||||||
|
"rapidjson_project",
|
||||||
|
"server_layout",
|
||||||
|
"sparkd"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,66 +0,0 @@
|
|||||||
function(init_executable)
|
|
||||||
set(source_dir)
|
|
||||||
if (${ARGC} EQUAL 0)
|
|
||||||
set(source_dir ${PROJECT_NAME})
|
|
||||||
elseif(${ARGC} GREATER 1)
|
|
||||||
message(FATAL_ERROR "init_shared_library received invalid arguments. Usage: init_shared_library(<OPTIONAL:source_dir>)")
|
|
||||||
else()
|
|
||||||
set(source_dir ${ARGV})
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(_options)
|
|
||||||
set(_one_value_args CXX_SOURCES CXX_HEADERS CXX_OUT_DIR)
|
|
||||||
set(_multi_value_args PROTO_INCLUDE_DIRS PROTO_SOURCES)
|
|
||||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
|
||||||
if (${_ARGS_PROTO_SOURCES} EQUAL "GLOB_RECURSIVE")
|
|
||||||
file(
|
|
||||||
GLOB_RECURSE ${PROJECT_NAME}_PROTO_SOURCES
|
|
||||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
*.proto
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
|
|
||||||
set(${PROJECT_NAME}_SOURCES PARENT_SCOPE)
|
|
||||||
file(
|
|
||||||
GLOB_RECURSE ${PROJECT_NAME}_SOURCES
|
|
||||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
${source_dir}/*.cpp
|
|
||||||
)
|
|
||||||
set(${PROJECT_NAME}_SOURCES ${${PROJECT_NAME}_SOURCES} PARENT_SCOPE)
|
|
||||||
# set(${PROJECT_NAME}_Sources ${${PROJECT_NAME}_Sources} PARENT_SCOPE)
|
|
||||||
# Note: cpp files inside 'tests' dir(s) are considered tests.
|
|
||||||
# Remove tests from main sources, and add them to test sources
|
|
||||||
set(${PROJECT_NAME}_TEST_SOURCES)
|
|
||||||
foreach(item ${${PROJECT_NAME}_SOURCES})
|
|
||||||
if(${item} MATCHES "tests/*.cpp")
|
|
||||||
list(REMOVE_ITEM ${PROJECT_NAME}_SOURCES ${item})
|
|
||||||
list(APPEND ${PROJECT_NAME}_TEST_SOURCES ${item})
|
|
||||||
endif()
|
|
||||||
set(${PROJECT_NAME}_TEST_SOURCES ${${PROJECT_NAME}_TEST_SOURCES} PARENT_SCOPE)
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# Add executable
|
|
||||||
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_SOURCES})
|
|
||||||
target_include_directories(
|
|
||||||
${PROJECT_NAME}
|
|
||||||
PUBLIC
|
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_directories(
|
|
||||||
${PROJECT_NAME}
|
|
||||||
PUBLIC
|
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add tests executable (if there are any)
|
|
||||||
if (${PROJECT_NAME}_TEST_SOURCES)
|
|
||||||
add_executable(${PROJECT_NAME}-tests ${${PROJECT_NAME}_TEST_SOURCEs})
|
|
||||||
target_link_libraries(${PROJECT_NAME}-tests PRIVATE ${PROJECT_NAME})
|
|
||||||
# Catch2
|
|
||||||
find_package(Catch2 CONFIG REQUIRED COMPONENTS Catch2WithMain)
|
|
||||||
target_link_libraries(${PROJECT_NAME}-tests PRIVATE Catch2::Catch2WithMain)
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
function(init_shared_library)
|
|
||||||
set(source_dir)
|
|
||||||
if (${ARGC} EQUAL 0)
|
|
||||||
set(source_dir ${PROJECT_NAME})
|
|
||||||
elseif(${ARGC} GREATER 1)
|
|
||||||
message(FATAL_ERROR "init_shared_library received invalid arguments. Usage: init_shared_library(<OPTIONAL:source_dir>)")
|
|
||||||
else()
|
|
||||||
set(source_dir ${ARGV})
|
|
||||||
endif()
|
|
||||||
set(${PROJECT_NAME}_Sources PARENT_SCOPE)
|
|
||||||
file(
|
|
||||||
GLOB_RECURSE ${PROJECT_NAME}_Sources
|
|
||||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
${source_dir}/*.cpp)
|
|
||||||
set(${PROJECT_NAME}_Sources ${${PROJECT_NAME}_Sources} PARENT_SCOPE)
|
|
||||||
# set(${PROJECT_NAME}_Sources ${${PROJECT_NAME}_Sources} PARENT_SCOPE)
|
|
||||||
# Note: cpp files inside 'tests' dir(s) are considered tests.
|
|
||||||
# Remove tests from main sources, and add them to test sources
|
|
||||||
set(${PROJECT_NAME}_Test_Sources)
|
|
||||||
foreach(item ${${PROJECT_NAME}_Sources})
|
|
||||||
if(${item} MATCHES "tests/*.cpp")
|
|
||||||
list(REMOVE_ITEM ${PROJECT_NAME}_Sources ${item})
|
|
||||||
list(APPEND ${PROJECT_NAME}_Test_Sources ${item})
|
|
||||||
endif()
|
|
||||||
set(${PROJECT_NAME}_Test_Sources ${${PROJECT_NAME}_Test_Sources} PARENT_SCOPE)
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
# Add main library
|
|
||||||
add_library(${PROJECT_NAME} SHARED ${${PROJECT_NAME}_Sources})
|
|
||||||
target_include_directories(
|
|
||||||
${PROJECT_NAME}
|
|
||||||
PUBLIC
|
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_directories(
|
|
||||||
${PROJECT_NAME}
|
|
||||||
PUBLIC
|
|
||||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
|
|
||||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_LIBDIR}>
|
|
||||||
)
|
|
||||||
|
|
||||||
# Add tests executable (if there are any)
|
|
||||||
if (${PROJECT_NAME}_Test_Sources)
|
|
||||||
add_executable(${PROJECT_NAME}-tests ${${PROJECT_NAME}_Test_Sources})
|
|
||||||
target_link_libraries(${PROJECT_NAME}-tests PRIVATE ${PROJECT_NAME})
|
|
||||||
# Catch2
|
|
||||||
find_package(Catch2 CONFIG REQUIRED COMPONENTS Catch2WithMain)
|
|
||||||
target_link_libraries(${PROJECT_NAME}-tests PRIVATE Catch2::Catch2WithMain)
|
|
||||||
endif()
|
|
||||||
endfunction(init_shared_library)
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
include(${CMAKE_SOURCE_DIR}/cmake/PackBasic.cmake)
|
|
||||||
|
|
||||||
function(install_basic_config)
|
|
||||||
file(
|
|
||||||
GLOB_RECURSE ${PROJECT_NAME}_HEADERS
|
|
||||||
RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}
|
|
||||||
*.h)
|
|
||||||
|
|
||||||
target_sources(${PROJECT_NAME}
|
|
||||||
PUBLIC
|
|
||||||
FILE_SET HEADERS FILES ${${PROJECT_NAME}_HEADERS})
|
|
||||||
|
|
||||||
install(
|
|
||||||
TARGETS ${PROJECT_NAME}
|
|
||||||
EXPORT ${PROJECT_NAME}Targets
|
|
||||||
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
|
||||||
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
|
||||||
FILE_SET HEADERS DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
EXPORT ${PROJECT_NAME}Targets
|
|
||||||
FILE ${PROJECT_NAME}Targets.cmake
|
|
||||||
NAMESPACE ${PROJECT_NAME}::
|
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
|
||||||
|
|
||||||
pack_basic()
|
|
||||||
endfunction()
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
include(CMakePackageConfigHelpers)
|
|
||||||
|
|
||||||
function(pack_basic)
|
|
||||||
write_basic_package_version_file(
|
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
|
||||||
VERSION ${PROJECT_VERSION}
|
|
||||||
COMPATIBILITY AnyNewerVersion
|
|
||||||
)
|
|
||||||
|
|
||||||
configure_package_config_file(
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in"
|
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
|
||||||
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}
|
|
||||||
)
|
|
||||||
|
|
||||||
install(
|
|
||||||
FILES
|
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
|
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
|
|
||||||
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})
|
|
||||||
endfunction()
|
|
||||||
+63
-85
@@ -1,23 +1,12 @@
|
|||||||
set(Protobuf_PROTOC_EXECUTABLE "${EXTERNALS_BIN}/protoc")
|
set(Protobuf_PROTOC_EXECUTABLE "${SPARK_BIN}/protoc")
|
||||||
set(PROTOBUF_INCLUDE_DIRS "${EXTERNALS_INCLUDE}")
|
set(PROTOBUF_INCLUDE_DIRS "${SPARK_INCLUDE}")
|
||||||
set(PROTOBUF_STATIC_LIB "libprotobuf")
|
set(PROTOBUF_STATIC_LIB "libprotobuf")
|
||||||
set(_protobuf_src_dir ${CMAKE_SOURCE_DIR}/src/lib_spark)
|
|
||||||
set(_protobuf_bin_dir ${CMAKE_BINARY_DIR}/src/lib_spark)
|
|
||||||
|
|
||||||
function(Protobuf_Generate_Cpp)
|
function(Protobuf_Generate_Cpp SRCS HDRS)
|
||||||
set(_options)
|
set(${SRCS})
|
||||||
set(_one_value_args CXX_SOURCES CXX_HEADERS CXX_OUT_DIR)
|
set(${HDRS})
|
||||||
set(_multi_value_args PROTO_INCLUDE_DIRS PROTO_SOURCES)
|
|
||||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
|
||||||
set(${_ARGS_CXX_SOURCES})
|
|
||||||
set(${_ARGS_CXX_HEADERS})
|
|
||||||
|
|
||||||
set(_proto_include_cli_args)
|
foreach(FIL ${ARGN})
|
||||||
foreach(_dir ${_ARGS_PROTO_INCLUDE_DIRS})
|
|
||||||
list(APPEND _proto_include_cli_args -I ${_dir})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
foreach(FIL ${_ARGS_PROTO_SOURCES})
|
|
||||||
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
||||||
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
||||||
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
|
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
|
||||||
@@ -25,59 +14,48 @@ set(_options)
|
|||||||
set(FIL_WE "${FIL_DIR}/${FIL_WE}")
|
set(FIL_WE "${FIL_DIR}/${FIL_WE}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(APPEND ${_ARGS_CXX_SOURCES} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.cc")
|
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
|
||||||
list(APPEND ${_ARGS_CXX_HEADERS} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.h")
|
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.cc"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.h"
|
|
||||||
COMMAND
|
COMMAND
|
||||||
${Protobuf_PROTOC_EXECUTABLE}
|
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${CMAKE_BINARY_DIR}/src -I
|
||||||
ARGS
|
${PROTOBUF_INCLUDE_DIRS} -I ${CMAKE_SOURCE_DIR}/src ${ABS_FIL}
|
||||||
--cpp_out=${_ARGS_CXX_OUT_DIR} ${_proto_include_cli_args} ${ABS_FIL}
|
|
||||||
DEPENDS ${ABS_FIL}
|
DEPENDS ${ABS_FIL}
|
||||||
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
|
COMMENT "Running C++ protocol buffer compiler on ${FIL}"
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
set_source_files_properties(${${_ARGS_CXX_SOURCES}} ${${_ARGS_CXX_HEADERS}} PROPERTIES GENERATED TRUE)
|
set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
|
||||||
|
|
||||||
# remove some warnings from protobuf generated files
|
# remove some warnings from protobuf generated files
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set_source_files_properties(${${_ARGS_CXX_SOURCES}} PROPERTIES COMPILE_FLAGS
|
set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS
|
||||||
"/wd4309 /wd4838")
|
"/wd4309 /wd4838")
|
||||||
else()
|
else()
|
||||||
set_source_files_properties(
|
set_source_files_properties(
|
||||||
${${_ARGS_CXX_SOURCES}}
|
${${SRCS}}
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
COMPILE_FLAGS
|
COMPILE_FLAGS
|
||||||
"-Wno-unused-parameter -Wno-effc++ -Wno-pedantic -Wno-sign-compare -Wno-uninitialized"
|
"-Wno-unused-parameter -Wno-effc++ -Wno-pedantic -Wno-sign-compare -Wno-uninitialized"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(${_ARGS_CXX_SOURCES}
|
set(${SRCS}
|
||||||
${${_ARGS_CXX_SOURCES}}
|
${${SRCS}}
|
||||||
PARENT_SCOPE)
|
PARENT_SCOPE)
|
||||||
set(${_ARGS_CXX_HEADERS}
|
set(${HDRS}
|
||||||
${${_ARGS_CXX_HEADERS}}
|
${${HDRS}}
|
||||||
PARENT_SCOPE)
|
PARENT_SCOPE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
function(Service_Compiler_Generate_Cpp)
|
function(Service_Compiler_Generate_Cpp SRCS HDRS)
|
||||||
set(_options)
|
set(${SRCS})
|
||||||
set(_one_value_args CXX_SOURCES CXX_HEADERS CXX_OUT_DIR)
|
set(${HDRS})
|
||||||
set(_multi_value_args PROTO_INCLUDE_DIRS PROTO_SOURCES)
|
|
||||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
|
||||||
set(${_ARGS_CXX_SOURCES})
|
|
||||||
set(${_ARGS_CXX_HEADERS})
|
|
||||||
|
|
||||||
set(_proto_include_cli_args)
|
foreach(FIL ${ARGN})
|
||||||
foreach(_dir ${_ARGS_PROTO_INCLUDE_DIRS})
|
|
||||||
list(APPEND _proto_include_cli_args -I ${_dir})
|
|
||||||
endforeach()
|
|
||||||
|
|
||||||
foreach(FIL ${_ARGS_PROTO_SOURCES})
|
|
||||||
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
|
||||||
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
get_filename_component(FIL_WE ${FIL} NAME_WE)
|
||||||
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
|
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
|
||||||
@@ -85,58 +63,58 @@ function(Service_Compiler_Generate_Cpp)
|
|||||||
set(FIL_WE "${FIL_DIR}/${FIL_WE}")
|
set(FIL_WE "${FIL_DIR}/${FIL_WE}")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
list(APPEND ${_ARGS_CXX_SOURCES} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.cc")
|
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
|
||||||
list(APPEND ${_ARGS_CXX_HEADERS} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.h")
|
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
|
||||||
|
|
||||||
list(APPEND ${_ARGS_CXX_SOURCES} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.cc")
|
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.cc")
|
||||||
list(APPEND ${_ARGS_CXX_HEADERS} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.h")
|
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.h")
|
||||||
|
|
||||||
list(APPEND ${_ARGS_CXX_SOURCES} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.cc")
|
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.cc")
|
||||||
list(APPEND ${_ARGS_CXX_HEADERS} "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.h")
|
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.h")
|
||||||
|
|
||||||
set(TEMPLATES
|
set(TEMPLATES
|
||||||
${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/templates/cpp/client.pb.cc
|
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/templates/cpp/client.pb.cc
|
||||||
${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/templates/cpp/client.pb.h
|
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/templates/cpp/client.pb.h
|
||||||
${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/templates/cpp/server.pb.cc
|
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/templates/cpp/server.pb.cc
|
||||||
${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/templates/cpp/server.pb.h
|
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/templates/cpp/server.pb.h
|
||||||
)
|
)
|
||||||
|
|
||||||
set(_plugin_py ${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/plugin.py)
|
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set(_plugin_cmd ${CMAKE_SOURCE_DIR}/src/lib_spark/spark/api/service_compiler/plugin.cmd)
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.cc"
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.h"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.cc"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.cc"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.h"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.h"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.cc"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.cc"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.h"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.h"
|
||||||
COMMAND SET PYTHONPATH=${SPARK_PYTHON}
|
COMMAND SET PYTHONPATH=${SPARK_PYTHON}
|
||||||
COMMAND ${CMAKE_SOURCE_DIR}/.venv/Scripts/activate.bat
|
COMMAND ${CMAKE_SOURCE_DIR}/.venv/Scripts/activate.bat
|
||||||
COMMAND
|
COMMAND
|
||||||
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${_ARGS_CXX_OUT_DIR}
|
${Protobuf_PROTOC_EXECUTABLE} ARGS --cpp_out=${CMAKE_BINARY_DIR}/src
|
||||||
--plugin=protoc-gen-service=${_plugin_cmd}
|
--plugin=protoc-gen-service=${CMAKE_SOURCE_DIR}/src/lib/api/service_compiler/plugin.cmd
|
||||||
--service_out=lang=cpp:${_ARGS_CXX_OUT_DIR} -I
|
--service_out=lang=cpp:${CMAKE_BINARY_DIR}/src -I
|
||||||
${PROTOBUF_INCLUDE_DIRS} -I ${_protobuf_src_dir} ${ABS_FIL}
|
${PROTOBUF_INCLUDE_DIRS} -I ${CMAKE_SOURCE_DIR}/src ${ABS_FIL}
|
||||||
DEPENDS ${ABS_FIL} ${TEMPLATES} ${_plugin_cmd} ${_plugin_py}
|
DEPENDS ${ABS_FIL} ${TEMPLATES}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/plugin.py
|
||||||
COMMENT "Running C++ service compiler on ${FIL}"
|
COMMENT "Running C++ service compiler on ${FIL}"
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
else()
|
else()
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT "${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.cc"
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.pb.h"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.cc"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.cc"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.client.pb.h"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.client.pb.h"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.cc"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.cc"
|
||||||
"${_ARGS_CXX_OUT_DIR}/${FIL_WE}.server.pb.h"
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.server.pb.h"
|
||||||
COMMAND ${CMAKE_SOURCE_DIR}/tools/venv_exec.sh
|
COMMAND ${CMAKE_SOURCE_DIR}/tools/venv_exec.sh
|
||||||
ARGS
|
ARGS
|
||||||
${Protobuf_PROTOC_EXECUTABLE}
|
${Protobuf_PROTOC_EXECUTABLE}
|
||||||
--cpp_out=${_ARGS_CXX_OUT_DIR}
|
--cpp_out=${CMAKE_BINARY_DIR}/src
|
||||||
--plugin=protoc-gen-service=${_plugin_py}
|
--plugin=protoc-gen-service=${CMAKE_SOURCE_DIR}/src/lib/api/service_compiler/plugin.py
|
||||||
--service_out=lang=cpp,make_file_name=${ABS_FIL}:${_ARGS_CXX_OUT_DIR}
|
--service_out=lang=cpp,make_file_name=${ABS_FIL}:${CMAKE_BINARY_DIR}/src
|
||||||
${_proto_include_cli_args} ${ABS_FIL}
|
-I ${PROTOBUF_INCLUDE_DIRS} -I ${CMAKE_SOURCE_DIR}/src ${ABS_FIL}
|
||||||
DEPENDS ${ABS_FIL} ${TEMPLATES} ${_plugin_py}
|
DEPENDS ${ABS_FIL} ${TEMPLATES}
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/api/service_compiler/plugin.py
|
||||||
COMMENT "Running C++ service compiler on ${FIL}"
|
COMMENT "Running C++ service compiler on ${FIL}"
|
||||||
VERBATIM)
|
VERBATIM)
|
||||||
endif()
|
endif()
|
||||||
@@ -145,22 +123,22 @@ function(Service_Compiler_Generate_Cpp)
|
|||||||
|
|
||||||
# remove some warnings from protobuf generated files
|
# remove some warnings from protobuf generated files
|
||||||
if(WIN32)
|
if(WIN32)
|
||||||
set_source_files_properties(${${_ARGS_CXX_SOURCES}} PROPERTIES COMPILE_FLAGS
|
set_source_files_properties(${${SRCS}} PROPERTIES COMPILE_FLAGS
|
||||||
"/wd4309 /wd4838")
|
"/wd4309 /wd4838")
|
||||||
else()
|
else()
|
||||||
set_source_files_properties(
|
set_source_files_properties(
|
||||||
${${_ARGS_CXX_SOURCES}}
|
${${SRCS}}
|
||||||
PROPERTIES
|
PROPERTIES
|
||||||
COMPILE_FLAGS
|
COMPILE_FLAGS
|
||||||
"-Wno-unused-parameter -Wno-effc++ -Wno-pedantic -Wno-sign-compare -Wno-uninitialized"
|
"-Wno-unused-parameter -Wno-effc++ -Wno-pedantic -Wno-sign-compare -Wno-uninitialized"
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(${_ARGS_CXX_SOURCES}
|
set(${SRCS}
|
||||||
${${_ARGS_CXX_SOURCES}}
|
${${SRCS}}
|
||||||
PARENT_SCOPE)
|
PARENT_SCOPE)
|
||||||
set(${_ARGS_CXX_HEADERS}
|
set(${HDRS}
|
||||||
${${_ARGS_CXX_HEADERS}}
|
${${HDRS}}
|
||||||
PARENT_SCOPE)
|
PARENT_SCOPE)
|
||||||
|
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
macro(set_first_defined RESULT CANDIDATE_VARS)
|
|
||||||
foreach(_candidate_var ${CANDIDATE_VARS})
|
|
||||||
if (DEFINED _candidate_var)
|
|
||||||
set(${RESULT} ${_candidate_var})
|
|
||||||
break()
|
|
||||||
endif()
|
|
||||||
endforeach()
|
|
||||||
endmacro()
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
function(sym_link_dir TARGET_NAME SOURCE DEST)
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${DEST}
|
|
||||||
COMMAND ln ARGS -sf ${SOURCE} ${DEST}
|
|
||||||
)
|
|
||||||
add_custom_target(
|
|
||||||
${TARGET_NAME} ALL
|
|
||||||
DEPENDS ${DEST}
|
|
||||||
)
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(sym_link_file)
|
|
||||||
set(_options)
|
|
||||||
set(_one_value_args TARGET_NAME SOURCE DEST INSTALL_DEST)
|
|
||||||
set(_multi_value_args)
|
|
||||||
cmake_parse_arguments(_ARGS "${_options}" "${_one_value_args}" "${_multi_value_args}" ${ARGN})
|
|
||||||
add_custom_command(
|
|
||||||
OUTPUT ${_ARGS_DEST}
|
|
||||||
COMMAND ln ARGS -s ${_ARGS_SOURCE} ${_ARGS_DEST}
|
|
||||||
)
|
|
||||||
add_custom_target(
|
|
||||||
${_ARGS_TARGET_NAME} ALL
|
|
||||||
DEPENDS ${_ARGS_DEST}
|
|
||||||
)
|
|
||||||
if (DEFINED _ARGS_INSTALL_DEST)
|
|
||||||
install(
|
|
||||||
FILES
|
|
||||||
${_ARGS_SOURCE}
|
|
||||||
DESTINATION ${_ARGS_INSTALL_DEST}
|
|
||||||
)
|
|
||||||
endif()
|
|
||||||
endfunction()
|
|
||||||
|
|
||||||
function(sym_link_local_lib LIB_NAME)
|
|
||||||
set(_lib_file_name "${CMAKE_SHARED_LIBRARY_PREFIX}${LIB_NAME}.so")
|
|
||||||
file(
|
|
||||||
CREATE_LINK
|
|
||||||
"${CMAKE_BINARY_DIR}/src/lib_${LIB_NAME}/${_lib_file_name}"
|
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/${_lib_file_name}"
|
|
||||||
SYMBOLIC
|
|
||||||
)
|
|
||||||
endfunction()
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
macro(set_ternary RESULT CONDITION TRUE_VALUE FALSE_VALUE)
|
|
||||||
if(${CONDITION})
|
|
||||||
set(${RESULT} ${TRUE_VALUE})
|
|
||||||
else()
|
|
||||||
set(${RESULT} ${FALSE_VALUE})
|
|
||||||
endif()
|
|
||||||
endmacro()
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
services:
|
|
||||||
sparkd:
|
|
||||||
build:
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
context: ./sparkd
|
|
||||||
command: [ "./sparkd", "run" ]
|
|
||||||
ports: [ "8000:8000", "8001:8001", "8002:8002" ]
|
|
||||||
|
|
||||||
pubsub:
|
|
||||||
build:
|
|
||||||
dockerfile: pubsub.Dockerfile
|
|
||||||
context: ./DataStream
|
|
||||||
command: [ "./PubSubServer" ]
|
|
||||||
environment:
|
|
||||||
- DOTNET_ENVIRONMENT=Production
|
|
||||||
ports:
|
|
||||||
- 22019:22019
|
|
||||||
|
|
||||||
md-publisher:
|
|
||||||
build:
|
|
||||||
dockerfile: md-publisher.Dockerfile
|
|
||||||
context: ./DataStream
|
|
||||||
depends_on:
|
|
||||||
- pubsub
|
|
||||||
- sparkd
|
|
||||||
command:
|
|
||||||
[
|
|
||||||
"dockerize",
|
|
||||||
"-wait",
|
|
||||||
"tcp://pubsub:22019",
|
|
||||||
"-wait",
|
|
||||||
"tcp://sparkd:8000",
|
|
||||||
"-timeout",
|
|
||||||
"10s",
|
|
||||||
"./DataStreamPublisher"
|
|
||||||
]
|
|
||||||
environment:
|
|
||||||
- DOTNET_ENVIRONMENT=MarketData
|
|
||||||
|
|
||||||
webapp:
|
|
||||||
ports:
|
|
||||||
- 8080:8080
|
|
||||||
- 8443:8443
|
|
||||||
build:
|
|
||||||
dockerfile: webapp.Dockerfile
|
|
||||||
context: ./DataStream
|
|
||||||
command: [ "./Bts.DataStreamWebApp.Server" ]
|
|
||||||
environment:
|
|
||||||
- ASPNETCORE_HTTP_PORT=8080
|
|
||||||
- ASPNETCORE_HTTPS_PORT=8443
|
|
||||||
- ASPNETCORE_ENVIRONMENT=Staging
|
|
||||||
@@ -1,72 +0,0 @@
|
|||||||
services:
|
|
||||||
sparkd:
|
|
||||||
build:
|
|
||||||
dockerfile: src/server/sparkd/Dockerfile
|
|
||||||
command: [ "./sparkd", "run" ]
|
|
||||||
ports: [ "8000:8000", "8001:8001", "8002:8002" ]
|
|
||||||
|
|
||||||
pubsub:
|
|
||||||
environment:
|
|
||||||
- DOTNET_ENVIRONMENT=Staging
|
|
||||||
build:
|
|
||||||
dockerfile: src/DataStreamSuite/PubSubServer/Dockerfile
|
|
||||||
ports:
|
|
||||||
- 22019:22019
|
|
||||||
command: [ "./PubSubServer" ]
|
|
||||||
|
|
||||||
md-publisher:
|
|
||||||
build:
|
|
||||||
dockerfile: src/DataStreamSuite/DataStreamPublisher/Dockerfile
|
|
||||||
depends_on:
|
|
||||||
- pubsub
|
|
||||||
- sparkd
|
|
||||||
command:
|
|
||||||
[
|
|
||||||
"dockerize",
|
|
||||||
"-wait",
|
|
||||||
"tcp://pubsub:22019",
|
|
||||||
"-wait",
|
|
||||||
"tcp://sparkd:8000",
|
|
||||||
"-timeout",
|
|
||||||
"10s",
|
|
||||||
"./DataStreamPublisher"
|
|
||||||
]
|
|
||||||
environment:
|
|
||||||
- DOTNET_ENVIRONMENT=MarketData
|
|
||||||
|
|
||||||
webapp:
|
|
||||||
ports:
|
|
||||||
- 8080:8080
|
|
||||||
- 8443:8443
|
|
||||||
build:
|
|
||||||
dockerfile: src/DataStreamSuite/Bts.DataStreamWebApp.Server/Dockerfile
|
|
||||||
command: [ "./Bts.DataStreamWebApp.Server" ]
|
|
||||||
environment:
|
|
||||||
- ASPNETCORE_ENVIRONMENT=Staging
|
|
||||||
|
|
||||||
api-server:
|
|
||||||
profiles:
|
|
||||||
- api-server
|
|
||||||
depends_on:
|
|
||||||
- sparkd
|
|
||||||
ports:
|
|
||||||
- 8008:8008
|
|
||||||
- 9443:9443
|
|
||||||
build:
|
|
||||||
dockerfile: src/client/spark_api_server/Dockerfile
|
|
||||||
command: [ "./spark_api_server", "run" ]
|
|
||||||
environment:
|
|
||||||
- ASPNETCORE_ENVIRONMENT=Staging
|
|
||||||
|
|
||||||
sparkd-ping-test:
|
|
||||||
depends_on:
|
|
||||||
- sparkd
|
|
||||||
profiles:
|
|
||||||
- ping-test
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile_inline: |
|
|
||||||
FROM bluetradingsystems/linux_dotnet7
|
|
||||||
USER "root"
|
|
||||||
RUN apt-get update && apt-get -y install iputils-ping
|
|
||||||
command: [ "ping", "sparkd" ]
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
FROM ubuntu:22.04
|
|
||||||
|
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
|
||||||
|
|
||||||
RUN apt-get update \
|
|
||||||
&& apt-get install -y pkg-config \
|
|
||||||
&& apt-get install -y locales \
|
|
||||||
&& apt-get install -y ca-certificates \
|
|
||||||
&& apt-get install -y libssh2-1-dev \
|
|
||||||
&& apt-get install -y software-properties-common \
|
|
||||||
&& apt-get install -y sudo
|
|
||||||
|
|
||||||
# GCC
|
|
||||||
ARG gcc_major=13
|
|
||||||
RUN add-apt-repository ppa:ubuntu-toolchain-r/test \
|
|
||||||
&& apt-get update \
|
|
||||||
&& apt-get install -y g++-$gcc_major
|
|
||||||
|
|
||||||
RUN apt-get update \
|
|
||||||
&& apt-get install -y dotnet7
|
|
||||||
|
|
||||||
RUN locale-gen en_US.UTF-8
|
|
||||||
|
|
||||||
ARG docker_user="bts"
|
|
||||||
ARG docker_uid="1000"
|
|
||||||
ARG docker_pass="bts"
|
|
||||||
# ARG entrypoint
|
|
||||||
|
|
||||||
RUN \
|
|
||||||
groupadd -g "$docker_uid" "$docker_user" \
|
|
||||||
&& useradd \
|
|
||||||
-m \
|
|
||||||
-u "$docker_uid" \
|
|
||||||
-g "$docker_uid" \
|
|
||||||
-G sudo \
|
|
||||||
--password "$(openssl passwd -1 "$docker_pass")" \
|
|
||||||
"$docker_user"
|
|
||||||
|
|
||||||
USER bts
|
|
||||||
WORKDIR /home/bts
|
|
||||||
File renamed without changes.
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Runtime.Versioning;
|
using System.Runtime.Versioning;
|
||||||
|
|
||||||
using Microsoft.Win32;
|
using Microsoft.Win32;
|
||||||
@@ -15,11 +16,8 @@ namespace BCG
|
|||||||
[SupportedOSPlatform("windows")]
|
[SupportedOSPlatform("windows")]
|
||||||
public static double getValue (RegistryKey rk, string name)
|
public static double getValue (RegistryKey rk, string name)
|
||||||
{
|
{
|
||||||
object v = rk.GetValue (name);
|
var str = rk.GetValue(name)?.ToString();
|
||||||
if (v != null)
|
return str is not null && double.TryParse(str, out var dbl) ? dbl : double.NaN;
|
||||||
return double.Parse (v.ToString ());
|
|
||||||
else
|
|
||||||
return double.NaN;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,19 @@
|
|||||||
namespace Bts.BooleanExpressions;
|
namespace Bts.BooleanExpressions;
|
||||||
|
|
||||||
|
using bts;
|
||||||
|
|
||||||
class BooleanExpression : IBooleanExpression {
|
class BooleanExpression : IBooleanExpression {
|
||||||
readonly Func<IDictionary<string, object?>, bool> evaluate;
|
readonly Func<IDictionary<string, object?>, bool> evaluate;
|
||||||
|
|
||||||
public BooleanExpression(Func<IDictionary<string, object?>, bool> evaluate) =>
|
public BooleanExpression(Func<IDictionary<string, object?>, bool> evaluate) =>
|
||||||
this.evaluate = evaluate;
|
this.evaluate = evaluate;
|
||||||
|
|
||||||
public bool Evaluate(IDictionary<string, object?> env) =>
|
public bool Evaluate(IDictionary<string, object?> env) {
|
||||||
evaluate(env);
|
try {
|
||||||
|
return evaluate(env);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Log.assert(false, $"BooleanExpression.Evaluate failed: {ex}");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -47,6 +47,11 @@ IsOfType '/'
|
|||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
{StringConstant} {
|
||||||
|
yylval.String = yytext.Substring(1, yytext.Length - 2).Replace(@"\'", "'");
|
||||||
|
return (int)Token.STRING_CONSTANT;
|
||||||
|
}
|
||||||
|
|
||||||
{BooleanConstant} {
|
{BooleanConstant} {
|
||||||
yylval.Boolean = yytext.ToLower() switch {
|
yylval.Boolean = yytext.ToLower() switch {
|
||||||
"true" => true,
|
"true" => true,
|
||||||
@@ -57,11 +62,6 @@ IsOfType '/'
|
|||||||
return (int)Token.BOOLEAN_CONSTANT;
|
return (int)Token.BOOLEAN_CONSTANT;
|
||||||
}
|
}
|
||||||
|
|
||||||
{StringConstant} {
|
|
||||||
yylval.String = yytext.Substring(1, yytext.Length - 2).Replace(@"\'", "'");
|
|
||||||
return (int)Token.STRING_CONSTANT;
|
|
||||||
}
|
|
||||||
|
|
||||||
{NullConstant} {
|
{NullConstant} {
|
||||||
yylval.Null = DBNull.Value;
|
yylval.Null = DBNull.Value;
|
||||||
return (int)Token.NULL_CONSTANT;
|
return (int)Token.NULL_CONSTANT;
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
VITE_DATASTREAM_WEBSOCKET_URL=wss://localhost:443
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
VITE_DATASTREAM_WEBSOCKET_URL=wss://localhost:443
|
|
||||||
@@ -12,18 +12,6 @@ module.exports = {
|
|||||||
settings: { react: { version: '18.3.1' } },
|
settings: { react: { version: '18.3.1' } },
|
||||||
plugins: ['react-refresh'],
|
plugins: ['react-refresh'],
|
||||||
rules: {
|
rules: {
|
||||||
"import/order": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
"groups": [
|
|
||||||
"builtin",
|
|
||||||
"external",
|
|
||||||
"internal",
|
|
||||||
["parent", "sibling", "index"]
|
|
||||||
],
|
|
||||||
"newlines-between": "always"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
'react-refresh/only-export-components': [
|
'react-refresh/only-export-components': [
|
||||||
'warn',
|
'warn',
|
||||||
{ allowConstantExport: true },
|
{ allowConstantExport: true },
|
||||||
|
|||||||
+1
-1277
File diff suppressed because it is too large.
Load diff
@@ -19,13 +19,9 @@
|
|||||||
"@mui/material": "^5.15.20",
|
"@mui/material": "^5.15.20",
|
||||||
"@mui/x-data-grid": "^7.7.1",
|
"@mui/x-data-grid": "^7.7.1",
|
||||||
"bulma": "^1.0.1",
|
"bulma": "^1.0.1",
|
||||||
"classnames": "^2.5.1",
|
|
||||||
"react": "^18.3.1",
|
"react": "^18.3.1",
|
||||||
"react-data-grid": "^7.0.0-beta.44",
|
|
||||||
"react-data-table-component": "^7.6.2",
|
"react-data-table-component": "^7.6.2",
|
||||||
"react-dom": "^18.3.1",
|
"react-dom": "^18.3.1",
|
||||||
"react-json-view-lite": "^1.4.0",
|
|
||||||
"react-pro-sidebar": "^1.1.0",
|
|
||||||
"react-use-websocket": "^4.8.1",
|
"react-use-websocket": "^4.8.1",
|
||||||
"rpc-websockets": "^7.11.2"
|
"rpc-websockets": "^7.11.2"
|
||||||
},
|
},
|
||||||
@@ -34,11 +30,9 @@
|
|||||||
"@types/react-dom": "^18.3.0",
|
"@types/react-dom": "^18.3.0",
|
||||||
"@vitejs/plugin-react": "^4.3.1",
|
"@vitejs/plugin-react": "^4.3.1",
|
||||||
"eslint": "^8.57.0",
|
"eslint": "^8.57.0",
|
||||||
"eslint-plugin-import": "^2.29.1",
|
|
||||||
"eslint-plugin-react": "^7.34.2",
|
"eslint-plugin-react": "^7.34.2",
|
||||||
"eslint-plugin-react-hooks": "^4.6.2",
|
"eslint-plugin-react-hooks": "^4.6.2",
|
||||||
"eslint-plugin-react-refresh": "^0.4.7",
|
"eslint-plugin-react-refresh": "^0.4.7",
|
||||||
"react-mui-sidebar": "^1.3.5",
|
|
||||||
"vite": "^5.2.13"
|
"vite": "^5.2.13"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
import { Sidebar, Menu, MenuItem, Submenu, Logo } from "react-mui-sidebar";
|
|
||||||
import './App.css';
|
|
||||||
|
|
||||||
const AnimatedSideBar = () => {
|
|
||||||
return (
|
|
||||||
<Sidebar className={"sidebar-container"} width={"270px"}>
|
|
||||||
<Logo img="https://adminmart.com/wp-content/uploads/2024/03/logo-admin-mart-news.png">
|
|
||||||
AdminMart
|
|
||||||
</Logo>
|
|
||||||
<Menu subHeading="HOME">
|
|
||||||
<MenuItem link="/" badge="true">
|
|
||||||
Modern
|
|
||||||
</MenuItem>
|
|
||||||
<MenuItem>eCommerce</MenuItem>
|
|
||||||
<MenuItem>Analytical</MenuItem>
|
|
||||||
</Menu>
|
|
||||||
<Menu subHeading="APPS">
|
|
||||||
<MenuItem>Chat</MenuItem>
|
|
||||||
<MenuItem>Calendar</MenuItem>
|
|
||||||
</Menu>
|
|
||||||
<Menu subHeading="OTHERS">
|
|
||||||
<Submenu title="Menu Level">
|
|
||||||
<MenuItem>Post</MenuItem>
|
|
||||||
<MenuItem>Details</MenuItem>
|
|
||||||
<Submenu title="Level 2">
|
|
||||||
<MenuItem>new</MenuItem>
|
|
||||||
<MenuItem>Hello</MenuItem>
|
|
||||||
</Submenu>
|
|
||||||
</Submenu>
|
|
||||||
|
|
||||||
<MenuItem>Chip</MenuItem>
|
|
||||||
<MenuItem target="_blank" link="google.com">
|
|
||||||
External Link
|
|
||||||
</MenuItem>
|
|
||||||
</Menu>
|
|
||||||
</Sidebar>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default AnimatedSideBar;
|
|
||||||
@@ -2,54 +2,6 @@
|
|||||||
@use "@material/icon-button";
|
@use "@material/icon-button";
|
||||||
@use "@material/data-table/data-table";
|
@use "@material/data-table/data-table";
|
||||||
|
|
||||||
.root-div {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: flex-start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.main-content-div {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
}
|
|
||||||
|
|
||||||
.title-div {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container-column {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.container-row {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
align-items: stretch;
|
|
||||||
}
|
|
||||||
|
|
||||||
box.query-input-form {
|
|
||||||
/* p: 2, display: "flex", flexFlow: "column", alignItems: "stretch" */
|
|
||||||
display: flex;
|
|
||||||
flex-flow: column;
|
|
||||||
align-items: stretch;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* li.ps-menuitem-root:hover {
|
|
||||||
background-color: #ff9922;
|
|
||||||
} */
|
|
||||||
|
|
||||||
.container-row-centered {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: center;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
h1#main-header {
|
h1#main-header {
|
||||||
padding: 4px 8px 4px 8px;
|
padding: 4px 8px 4px 8px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@@ -74,28 +26,3 @@ td#cell-string {
|
|||||||
td#cell-date-time {
|
td#cell-date-time {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Sidebar.css */
|
|
||||||
/* .sidebar-container {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar {
|
|
||||||
position: relative;
|
|
||||||
top: 0;
|
|
||||||
left: 0;
|
|
||||||
height: 100vh;
|
|
||||||
background-color: #333;
|
|
||||||
color: white;
|
|
||||||
overflow: hidden;
|
|
||||||
transition: transform 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar.closed {
|
|
||||||
width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar.open {
|
|
||||||
width: 250px;
|
|
||||||
} */
|
|
||||||
@@ -1,171 +1,22 @@
|
|||||||
import { ThemeProvider, CssBaseline, GlobalStyles } from '@mui/material';
|
import { createTheme, ThemeProvider, CssBaseline } from '@mui/material';
|
||||||
import QueryStatusView from './QueryStatusView';
|
|
||||||
import useMediaQuery from '@mui/material/useMediaQuery';
|
import useMediaQuery from '@mui/material/useMediaQuery';
|
||||||
import QueryControl from './QueryControl';
|
import QueryControl from './QueryControl';
|
||||||
import DataTable from './DataTable';
|
|
||||||
import { useState, useEffect, useMemo } from 'react';
|
|
||||||
import useWebSocket, { ReadyState } from 'react-use-websocket';
|
|
||||||
import Sidebar from './SideBar';
|
|
||||||
import getTheme from './Theme';
|
import getTheme from './Theme';
|
||||||
|
|
||||||
import '@fontsource/noto-sans';
|
import '@fontsource/noto-sans';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import './SideBar.css';
|
|
||||||
|
|
||||||
const webSocketUrl = import.meta.env.VITE_DATASTREAM_WEBSOCKET_URL;
|
|
||||||
// Always use the same subscription id (1), because we only show 1 table at a time.
|
|
||||||
// The server will automatically dispose the previous subscription and start a new one
|
|
||||||
// if we're currently subscribed to another query.
|
|
||||||
const subscriptionId = "1";
|
|
||||||
|
|
||||||
var rpcReqIdCounter = 1;
|
|
||||||
|
|
||||||
function subscribeReq(query) {
|
|
||||||
return {
|
|
||||||
jsonrpc: "2.0",
|
|
||||||
id: rpcReqIdCounter++,
|
|
||||||
method: "subscribe",
|
|
||||||
params: {
|
|
||||||
subscription_id: subscriptionId,
|
|
||||||
query: query
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function unsubscribeReq() {
|
|
||||||
return {
|
|
||||||
jsonrpc: "2.0",
|
|
||||||
id: rpcReqIdCounter++,
|
|
||||||
method: "unsubscribe",
|
|
||||||
params: {
|
|
||||||
subscription_id: subscriptionId,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
|
const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
|
||||||
const theme = getTheme({ mode: prefersDarkMode ? 'dark' : 'light' });
|
const theme = getTheme({ mode: prefersDarkMode ? 'dark' : 'light' });
|
||||||
const globalStyles = {
|
|
||||||
':root': {
|
|
||||||
'--primary-color': theme.palette.primary.main,
|
|
||||||
'--primary-dark-color': theme.palette.primary.dark,
|
|
||||||
'--secondary-color': theme.palette.secondary.main,
|
|
||||||
'--secondary-dark-color': theme.palette.secondary.dark,
|
|
||||||
'--background-color': theme.palette.background.default,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
const [blueTable, setBlueTable] = useState({ columns: null, rows: null });
|
|
||||||
const [queryError, setQueryError] = useState(null);
|
|
||||||
const [queryState, setQueryState] = useState("Unsubscribed");
|
|
||||||
const queryStateDetails = useMemo(() => {
|
|
||||||
if (queryState == "Unsubscribed") {
|
|
||||||
return "Enter query above, then click the play button to subscribe";
|
|
||||||
}
|
|
||||||
if (queryState == "Subscribed") {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}, [queryState]);
|
|
||||||
const [sidebarIsOpen, setSidebarIsOpen] = useState(false);
|
|
||||||
const [cannedQuery, setCannedQuery] = useState(null);
|
|
||||||
|
|
||||||
const onCannedQueryClicked = (cannedQuery) => {
|
|
||||||
console.info(`Executing canned query: ${JSON.stringify(cannedQuery)}`);
|
|
||||||
const queryText = cannedQuery.query.join("\n");
|
|
||||||
setCannedQuery({ queryText: queryText, clickTime: Date.now() });
|
|
||||||
subscribe(queryText);
|
|
||||||
};
|
|
||||||
|
|
||||||
const { sendJsonMessage, getWebSocket, readyState } = useWebSocket(
|
|
||||||
webSocketUrl,
|
|
||||||
{
|
|
||||||
onOpen: (e) => console.info(`WebSocket open. ${JSON.stringify(e)}`),
|
|
||||||
onClose: (e) => console.info(`WebSocket closed. ${JSON.stringify(e)}`),
|
|
||||||
onError: (e) => console.error(`WebSocket error: ${JSON.stringify(e)}`),
|
|
||||||
shouldReconnect: () => true,
|
|
||||||
});
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
console.info(`WebSocket readyState: ${readyState}`)
|
|
||||||
if (readyState != ReadyState.OPEN) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const ws = getWebSocket();
|
|
||||||
ws.onmessage = e => {
|
|
||||||
console.info(`Received message: ${e.data}`);
|
|
||||||
const msg = JSON.parse(e.data);
|
|
||||||
setQueryError(msg.error);
|
|
||||||
if (msg.error != null) {
|
|
||||||
setQueryState("Error");
|
|
||||||
} else if (msg.id != null) {
|
|
||||||
setQueryState(msg.result.status);
|
|
||||||
} else {
|
|
||||||
console.assert(msg.params.subscription_id == subscriptionId);
|
|
||||||
console.info(`Received rows: ${msg.params.table.all}`);
|
|
||||||
setBlueTable({ columns: msg.params.table.columns, rows: msg.params.table.all });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}, [getWebSocket, readyState]);
|
|
||||||
|
|
||||||
const subscribe = (query) => {
|
|
||||||
const req = subscribeReq(query);
|
|
||||||
console.info(`Subscribing: ${JSON.stringify(subscribeReq(query))}`);
|
|
||||||
sendJsonMessage(req);
|
|
||||||
};
|
|
||||||
|
|
||||||
const unsubscribe = () => {
|
|
||||||
const req = unsubscribeReq();
|
|
||||||
console.info(`Unsubscribing: ${JSON.stringify(req)}`);
|
|
||||||
sendJsonMessage(req);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onOpened = () => {
|
|
||||||
setSidebarIsOpen(true);
|
|
||||||
};
|
|
||||||
|
|
||||||
const onClosed = () => {
|
|
||||||
setSidebarIsOpen(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
const sidebarWidth = sidebarIsOpen ? '250px' : '65px';
|
|
||||||
return (
|
return (
|
||||||
<ThemeProvider theme={theme}>
|
<ThemeProvider theme={theme}>
|
||||||
<CssBaseline />
|
<CssBaseline />
|
||||||
<GlobalStyles styles={globalStyles} />
|
<h1 id='main-header' style={{
|
||||||
<div className='root-div'>
|
color: theme.palette.text.primary,
|
||||||
<div style={{
|
fontFamily: 'Noto Sans',
|
||||||
display: 'flex',
|
}}>BTS Cloud Streams</h1>
|
||||||
flexDirection: 'column',
|
<QueryControl websocketUrl="ws://localhost:5000/ws" theme={theme} />
|
||||||
alignItems: 'flex-start',
|
|
||||||
flexWrap: 'nowrap',
|
|
||||||
width: sidebarWidth,
|
|
||||||
transition: 'width 0.3s ease',
|
|
||||||
}}>
|
|
||||||
<Sidebar onSelection={onCannedQueryClicked} onOpened={onOpened} onClosed={onClosed} />
|
|
||||||
</div>
|
|
||||||
<div style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'column',
|
|
||||||
left: sidebarWidth,
|
|
||||||
width: '100%',
|
|
||||||
transition: 'width 0.3s ease',
|
|
||||||
}}>
|
|
||||||
<div style={{ width: '100%', display: 'flex', flexDirection: 'column', alignItems: 'flex-start', margin: theme.spacing(2, 0, 0, 0) }}>
|
|
||||||
<div style={{ width: '90%', rightMargin: '100px' }}>
|
|
||||||
<QueryControl
|
|
||||||
queryState={queryState}
|
|
||||||
queryText={cannedQuery?.queryText}
|
|
||||||
queryTextResetTime={cannedQuery?.clickTime}
|
|
||||||
subscribe={subscribe}
|
|
||||||
unsubscribe={unsubscribe} />
|
|
||||||
</div>
|
|
||||||
<div style={{ width: '90%', rightMargin: '100px' }}>
|
|
||||||
<QueryStatusView queryState={queryState} details={queryStateDetails} error={queryError} />
|
|
||||||
<DataTable columns={blueTable?.columns ?? []} rows={blueTable?.rows ?? []} />
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,53 +0,0 @@
|
|||||||
@use "@material/checkbox";
|
|
||||||
@use "@material/icon-button";
|
|
||||||
@use "@material/data-table/data-table";
|
|
||||||
|
|
||||||
.data-grid-container {
|
|
||||||
overflow: auto;
|
|
||||||
white-space: nowrap;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
.data-grid {
|
|
||||||
max-height: 1000px;
|
|
||||||
}
|
|
||||||
|
|
||||||
div[role=columnheader] {
|
|
||||||
border-top: 0px;
|
|
||||||
border-bottom: 0px;
|
|
||||||
background-color: var(--primary-dark-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* div[role=columnheader] {
|
|
||||||
border-top: 0px;
|
|
||||||
border-bottom: 0px;
|
|
||||||
background-color: var(--primary-dark-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.rdg-row {
|
|
||||||
border: 0px;
|
|
||||||
border-top: 0px;
|
|
||||||
border-bottom: 0px;
|
|
||||||
background-color: rgba(var(--primary-dark-color), 0.8);
|
|
||||||
color: var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.rdg-row-odd {
|
|
||||||
border: 0px;
|
|
||||||
border-top: 0px;
|
|
||||||
border-bottom: 0px;
|
|
||||||
background-color: var(--primary-dark-color);
|
|
||||||
color: var(--primary-color);
|
|
||||||
}
|
|
||||||
|
|
||||||
.rdg-cell {
|
|
||||||
border-bottom: 0px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.rdg-cell.even {
|
|
||||||
border-bottom: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.rdg-cell.odd {
|
|
||||||
border-bottom: 5px;
|
|
||||||
} */
|
|
||||||
@@ -1,40 +1,19 @@
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import { useTheme } from '@mui/material/styles';
|
|
||||||
import { DataGrid } from '@mui/x-data-grid';
|
import { DataGrid } from '@mui/x-data-grid';
|
||||||
import './DataGrid.css'
|
|
||||||
import { useMemo, useState } from 'react';
|
function getGridColDef(col) {
|
||||||
|
return {
|
||||||
|
field: col.name,
|
||||||
|
headerName: col.name,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export default function DataTable({ columns, rows }) {
|
export default function DataTable({ columns, rows }) {
|
||||||
const theme = useTheme();
|
|
||||||
const [columnWidths, setColumnWidths] = useState({});
|
|
||||||
|
|
||||||
const handleColumnResize = (params) => {
|
|
||||||
const newWidth = params.width;
|
|
||||||
setColumnWidths((prevWidths) => ({
|
|
||||||
...prevWidths,
|
|
||||||
[params.colDef.field]: params.width,
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
|
|
||||||
const getGridColDef = useMemo(() => {
|
|
||||||
return col => {
|
|
||||||
return {
|
|
||||||
field: col.name,
|
|
||||||
headerName: col.name,
|
|
||||||
width: columnWidths[col.name],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}, [columnWidths]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DataGrid
|
<DataGrid
|
||||||
className='data-grid-container'
|
columns={columns.map(getGridColDef)}
|
||||||
autosizeOnMount={false}
|
rows={rows}
|
||||||
columns={columns?.map(getGridColDef) ?? []}
|
|
||||||
onColumnResize={handleColumnResize}
|
|
||||||
rows={rows ?? []}
|
|
||||||
sx={{
|
sx={{
|
||||||
margin: theme.spacing(2, 0, 0, 0),
|
|
||||||
borderColor: 'primary.main',
|
borderColor: 'primary.main',
|
||||||
backgroundColor: 'primary.dark',
|
backgroundColor: 'primary.dark',
|
||||||
color: 'text.primary',
|
color: 'text.primary',
|
||||||
@@ -70,5 +49,4 @@ DataTable.propTypes = {
|
|||||||
})
|
})
|
||||||
).isRequired,
|
).isRequired,
|
||||||
rows: PropTypes.arrayOf(PropTypes.array).isRequired,
|
rows: PropTypes.arrayOf(PropTypes.array).isRequired,
|
||||||
apiRef: PropTypes.object,
|
|
||||||
};
|
};
|
||||||
@@ -1,119 +1,100 @@
|
|||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
import DataTable from './DataTable';
|
import DataTable from './DataTable';
|
||||||
import { useRef, useState, useEffect } from 'react';
|
import QueryInputForm from './QueryInputForm';
|
||||||
import { useGridApiRef } from '@mui/x-data-grid';
|
import Container from '@mui/material/Container';
|
||||||
import Box from '@mui/material/Box';
|
import React from 'react';
|
||||||
import Button from '@mui/material/Button';
|
|
||||||
import Grid from '@mui/material/Grid';
|
|
||||||
import Paper from '@mui/material/Paper';
|
|
||||||
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
|
|
||||||
import StopIcon from '@mui/icons-material/Stop';
|
|
||||||
import TextField from '@mui/material/TextField';
|
|
||||||
import Tooltip from '@mui/material/Tooltip';
|
|
||||||
|
|
||||||
const QueryControl = (props) => {
|
var rpcReqIdCounter = 1;
|
||||||
const { queryState, queryText, queryTextResetTime, subscribe, unsubscribe } = props;
|
|
||||||
// const theme = useTheme();
|
|
||||||
let textInput = useRef();
|
|
||||||
const [queryTextChangeTime, setQueryTextChangeTime] = useState(null);
|
|
||||||
useEffect(() => {
|
|
||||||
if (queryText == null || textInput.current == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Init text field (unless a non-empty string is already present, or the user has modified
|
|
||||||
// the query - we don't want to overwrite their changes).
|
|
||||||
if (queryTextChangeTime == null || queryTextResetTime > queryTextChangeTime) {
|
|
||||||
console.info(`Initializing query text: ${queryText}`)
|
|
||||||
textInput.current.value = queryText;
|
|
||||||
}
|
|
||||||
}, [queryText, queryTextChangeTime, queryTextResetTime]);
|
|
||||||
const onClearClick = () => {
|
|
||||||
textInput.current.value = '';
|
|
||||||
};
|
|
||||||
|
|
||||||
const onRunClick = () => {
|
function subscribeReq(query) {
|
||||||
subscribe(textInput.current.value);
|
return {
|
||||||
};
|
jsonrpc: "2.0",
|
||||||
|
id: rpcReqIdCounter++,
|
||||||
const onStopClick = () => {
|
method: "subscribe",
|
||||||
unsubscribe();
|
params: {
|
||||||
};
|
subscription_id: "1",
|
||||||
|
query: query
|
||||||
const onKeyDown = (e) => {
|
|
||||||
// Detect keyboard shortcuts.
|
|
||||||
// Ctrl+Enter : Run
|
|
||||||
if (e.ctrlKey && e.key === 'Enter') {
|
|
||||||
onRunClick();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
const onChange = (e) => {
|
function unsubscribeReq() {
|
||||||
// So we know not to overwrite the changes with the canned query on re-render
|
return {
|
||||||
setQueryTextChangeTime(Date.now());
|
jsonrpc: "2.0",
|
||||||
|
id: rpcReqIdCounter++,
|
||||||
|
method: "unsubscribe",
|
||||||
|
params: {
|
||||||
|
subscription_id: "1",
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
class QueryControl extends React.Component {
|
||||||
<Box sx={{ display: "flex", flexFlow: "column" }}>
|
constructor({ websocketUrl, theme }) {
|
||||||
<Paper elevation={3} sx={{ color: 'primary.main' }}>
|
super(websocketUrl);
|
||||||
<Box sx={{ p: 2 }}>
|
console.log('Connecting to WebSocket:', websocketUrl);
|
||||||
<TextField
|
this.state = {
|
||||||
fullWidth
|
rows: null,
|
||||||
multiline
|
ws: new WebSocket(websocketUrl),
|
||||||
rows={10}
|
columns: null,
|
||||||
variant="outlined"
|
isRunning: false,
|
||||||
onChange={onChange}
|
theme: theme,
|
||||||
onKeyDown={onKeyDown}
|
};
|
||||||
inputRef={textInput}
|
this.state.ws.onopen = () => {
|
||||||
placeholder="Enter Query..."
|
console.info('WebSocket open');
|
||||||
/>
|
};
|
||||||
</Box>
|
this.state.ws.onclose = () => {
|
||||||
<Box sx={{ p: 2, borderTop: 1 }}>
|
console.info('WebSocket closed');
|
||||||
<Grid container spacing={2} justifyContent="flex-start">
|
};
|
||||||
<Grid item xs>
|
this.state.ws.onmessage = e => {
|
||||||
<Tooltip title="Clear Query Text">
|
console.info(`Received message: ${e.data}`);
|
||||||
<Button onClick={onClearClick} sx={{ padding: '11px', color: 'text.dark' }}>
|
const msg = JSON.parse(e.data);
|
||||||
Clear
|
if (msg.id != null) {
|
||||||
</Button>
|
let newState = { ...this.state };
|
||||||
</Tooltip>
|
newState.isRunning = msg.result.status == 'Subscribed';
|
||||||
</Grid>
|
this.setState(newState);
|
||||||
<Grid item>
|
} else {
|
||||||
<Tooltip title="Run (Ctrl+Enter)">
|
let newState = { ...this.state };
|
||||||
<Button onClick={onRunClick} sx={{
|
newState.rows = msg.params.all;
|
||||||
color: `queryStartButton.${queryState}.color`,
|
console.info(`Received rows: ${newState.rows}`);
|
||||||
bgcolor: `queryStartButton.${queryState}.backgroundColor`,
|
newState.columns = msg.params.columns;
|
||||||
padding: '11px'
|
this.setState(newState);
|
||||||
}}>
|
}
|
||||||
<PlayArrowIcon />
|
};
|
||||||
</Button>
|
|
||||||
</Tooltip>
|
this.start = (query) => {
|
||||||
</Grid>
|
this.state.ws.send(JSON.stringify(subscribeReq(query)));
|
||||||
<Grid item>
|
};
|
||||||
<Tooltip title="Stop">
|
|
||||||
<Button onClick={onStopClick} sx={{
|
this.stop = () => {
|
||||||
color: `queryStopButton.${queryState}.color`,
|
this.state.ws.send(JSON.stringify(unsubscribeReq()));
|
||||||
bgcolor: `queryStopButton.${queryState}.backgroundColor`,
|
};
|
||||||
padding: '11px'
|
}
|
||||||
}}>
|
|
||||||
<StopIcon />
|
componentWillUnmount() {
|
||||||
</Button>
|
if (this.state.ws) {
|
||||||
</Tooltip>
|
console.warn('Closing websocket because component is unmounting');
|
||||||
</Grid>
|
this.state.ws.close();
|
||||||
</Grid>
|
}
|
||||||
</Box>
|
}
|
||||||
</Paper>
|
|
||||||
</Box>
|
render() {
|
||||||
);
|
console.info('Rendering');
|
||||||
};
|
return (
|
||||||
|
<Container>
|
||||||
|
<QueryInputForm isRunning={this.state.isRunning} onStart={this.start} onStop={this.stop} />
|
||||||
|
{
|
||||||
|
this.state.rows == null ? <p style={{ color: this.state.theme.palette.warning.main }}>No data received</p> :
|
||||||
|
<DataTable columns={this.state.columns} rows={this.state.rows} />
|
||||||
|
}
|
||||||
|
</Container>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QueryControl.propTypes = {
|
QueryControl.propTypes = {
|
||||||
columns: PropTypes.array,
|
websocketUrl: PropTypes.string.isRequired,
|
||||||
rows: PropTypes.array,
|
theme: PropTypes.object.isRequired,
|
||||||
isRunning: PropTypes.bool,
|
|
||||||
queryText: PropTypes.string,
|
|
||||||
queryTextResetTime: PropTypes.number,
|
|
||||||
queryState: PropTypes.string,
|
|
||||||
subscribe: PropTypes.func,
|
|
||||||
unsubscribe: PropTypes.func,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default QueryControl;
|
export default QueryControl;
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
import { useRef } from 'react';
|
||||||
|
import Box from '@mui/material/Box';
|
||||||
|
import Button from '@mui/material/Button';
|
||||||
|
import Grid from '@mui/material/Grid';
|
||||||
|
import Paper from '@mui/material/Paper';
|
||||||
|
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
|
||||||
|
import PropTypes from 'prop-types';
|
||||||
|
import StopIcon from '@mui/icons-material/Stop';
|
||||||
|
import TextField from '@mui/material/TextField';
|
||||||
|
import Tooltip from '@mui/material/Tooltip';
|
||||||
|
|
||||||
|
const QueryInputForm = ({ isRunning, onStart, onStop }) => {
|
||||||
|
let textInput = useRef(null);
|
||||||
|
|
||||||
|
const onClearClick = () => {
|
||||||
|
textInput.current.value = '';
|
||||||
|
};
|
||||||
|
|
||||||
|
const onRunClick = () => {
|
||||||
|
onStart(textInput.current.value);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onStopClick = () => {
|
||||||
|
onStop();
|
||||||
|
};
|
||||||
|
|
||||||
|
const onKeyDown = (e) => {
|
||||||
|
// Detect keyboard shortcuts.
|
||||||
|
// Ctrl+Enter : Run
|
||||||
|
if (e.ctrlKey && e.key === 'Enter') {
|
||||||
|
onRunClick();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box sx={{ p: 2 }}>
|
||||||
|
<Paper elevation={3} sx={{ color: 'primary.main' }}>
|
||||||
|
<Box sx={{ p: 2 }}>
|
||||||
|
<TextField
|
||||||
|
fullWidth
|
||||||
|
multiline
|
||||||
|
rows={10}
|
||||||
|
variant="outlined"
|
||||||
|
onKeyDown={onKeyDown}
|
||||||
|
inputRef={textInput}
|
||||||
|
placeholder="Enter Query..."
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ p: 2, borderTop: 1 }}>
|
||||||
|
<Grid container spacing={2} justifyContent="flex-start">
|
||||||
|
<Grid item xs>
|
||||||
|
<Tooltip title="Clear Query Text">
|
||||||
|
<Button onClick={onClearClick} sx={{ padding: '11px', color: 'text.dark' }}>
|
||||||
|
Clear
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<Tooltip title="Run (Ctrl+Enter)">
|
||||||
|
<Button onClick={onRunClick} sx={{
|
||||||
|
color: `query_start_button.${isRunning ? 'active' : 'inactive'}.color`,
|
||||||
|
bgcolor: `query_start_button.${isRunning ? 'active' : 'inactive'}.background_color`,
|
||||||
|
padding: '11px'
|
||||||
|
}}>
|
||||||
|
<PlayArrowIcon />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</Grid>
|
||||||
|
<Grid item>
|
||||||
|
<Tooltip title="Stop">
|
||||||
|
<Button onClick={onStopClick} sx={{
|
||||||
|
color: `query_stop_button.${isRunning ? 'inactive' : 'active'}.color`,
|
||||||
|
bgcolor: `query_stop_button.${isRunning ? 'inactive' : 'active'}.background_color`,
|
||||||
|
padding: '11px'
|
||||||
|
}}>
|
||||||
|
<StopIcon />
|
||||||
|
</Button>
|
||||||
|
</Tooltip>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</Box>
|
||||||
|
</Paper>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
QueryInputForm.propTypes = {
|
||||||
|
isRunning: PropTypes.bool.isRequired,
|
||||||
|
onStart: PropTypes.func.isRequired,
|
||||||
|
onStop: PropTypes.func.isRequired,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default QueryInputForm;
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { Box, Typography, Collapse } from '@mui/material';
|
|
||||||
import Alert from '@mui/material/Alert';
|
|
||||||
import AlertTitle from '@mui/material/AlertTitle';
|
|
||||||
import { useTheme } from '@mui/material/styles';
|
|
||||||
import { alpha } from '@mui/system';
|
|
||||||
|
|
||||||
const QueryStatusView = ({ queryState, details, error }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const [open, setOpen] = useState(false);
|
|
||||||
|
|
||||||
let header = queryState;
|
|
||||||
let headerContent = null;
|
|
||||||
let detailElements = [];
|
|
||||||
let severity = queryState == "Subscribed" ? "success" : "info";
|
|
||||||
let cursor = details == null ? "default" : "pointer";
|
|
||||||
if (error != null) {
|
|
||||||
severity = "error";
|
|
||||||
cursor = "pointer";
|
|
||||||
header = `Error Code: ${error.code}`;
|
|
||||||
headerContent = error.message;
|
|
||||||
detailElements.push(<Typography variant="body1">{error.data.error_message}</Typography>);
|
|
||||||
detailElements.push(<Typography variant="subtitle1">Stack Trace:</Typography>);
|
|
||||||
(error.data.stack_trace ?? []).forEach(line => detailElements.push(
|
|
||||||
<Typography variant="body2" component="pre" sx={{ whiteSpace: 'pre-wrap' }}>
|
|
||||||
{line}
|
|
||||||
</Typography>));
|
|
||||||
} else if (details != null) {
|
|
||||||
detailElements.push(<Typography variant="body1">{details}</Typography>);
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
<Box sx={{ margin: theme.spacing(2, 0, 0, 0) }}>
|
|
||||||
<Alert
|
|
||||||
severity={severity}
|
|
||||||
onClick={() => setOpen(!open)}
|
|
||||||
sx={{
|
|
||||||
margin: theme.spacing(2, 0, 0, 0),
|
|
||||||
cursor: cursor,
|
|
||||||
}}>
|
|
||||||
<AlertTitle>{header}</AlertTitle>
|
|
||||||
{headerContent}
|
|
||||||
</Alert>
|
|
||||||
{detailElements.length == 0
|
|
||||||
? null
|
|
||||||
: <Collapse in={open}>
|
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
backgroundColor: alpha(theme.palette[severity].light, 0.75),
|
|
||||||
color: theme.palette[severity].contrastText,
|
|
||||||
padding: theme.spacing(2),
|
|
||||||
marginTop: theme.spacing(0),
|
|
||||||
borderRadius: theme.shape.borderRadius,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{detailElements}
|
|
||||||
</Box>
|
|
||||||
</Collapse>}
|
|
||||||
</Box>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
QueryStatusView.propTypes = {
|
|
||||||
queryState: PropTypes.string,
|
|
||||||
details: PropTypes.string,
|
|
||||||
error: PropTypes.shape({
|
|
||||||
code: PropTypes.number,
|
|
||||||
message: PropTypes.string,
|
|
||||||
data: PropTypes.object,
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
export default QueryStatusView;
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
import 'react-data-grid/lib/styles.css';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import DataGrid from 'react-data-grid';
|
|
||||||
import './DataGrid.css';
|
|
||||||
|
|
||||||
function getGridColDef(col) {
|
|
||||||
return {
|
|
||||||
key: col.name,
|
|
||||||
name: col.name,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ReactDataGrid({columns, rows}) {
|
|
||||||
return (
|
|
||||||
<DataGrid className={"data-grid"} rows={rows} columns={columns.map(getGridColDef)} />
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
ReactDataGrid.propTypes = {
|
|
||||||
columns: PropTypes.arrayOf(
|
|
||||||
PropTypes.shape({
|
|
||||||
name: PropTypes.string.isRequired,
|
|
||||||
type: PropTypes.string.isRequired,
|
|
||||||
})
|
|
||||||
).isRequired,
|
|
||||||
rows: PropTypes.arrayOf(PropTypes.array).isRequired,
|
|
||||||
};
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
/* Sidebar.css */
|
|
||||||
.app-container {
|
|
||||||
display: flex;
|
|
||||||
width: 100%;
|
|
||||||
overflow: hidden;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: flex-start;
|
|
||||||
align-items: flex-start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: flex-start;
|
|
||||||
align-items: flex-start;
|
|
||||||
background-color: transparent;
|
|
||||||
color: white;
|
|
||||||
overflow: hidden;
|
|
||||||
transition: width 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar.open {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar.closed {
|
|
||||||
width: 0%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar-toggle-button {
|
|
||||||
border: 0px;
|
|
||||||
border-radius: 50%;
|
|
||||||
box-shadow: rgba(9, 30, 66, 0.08) 0px 0px 0px 1px, rgba(9, 30, 66, 0.08) 0px 2px 4px 1px;
|
|
||||||
color: var(--primary-color);
|
|
||||||
cursor: pointer;
|
|
||||||
height: 24px;
|
|
||||||
opacity: 1;
|
|
||||||
outline: 0px;
|
|
||||||
padding: 0px;
|
|
||||||
background-color: transparent;
|
|
||||||
transition: background-color 100ms linear 0s, color 100ms linear 0s, opacity 300ms cubic-bezier(0.2, 0, 0, 1) 0s, transform 300ms cubic-bezier(0.2, 0, 0, 1) 0s;
|
|
||||||
width: 20%;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar-toggle-button:hover {
|
|
||||||
transition: background-color 100ms linear 0s, color 100ms linear 0s, opacity 300ms cubic-bezier(0.2, 0, 0, 1) 0s, transform 300ms cubic-bezier(0.2, 0, 0, 1) 0s;
|
|
||||||
}
|
|
||||||
|
|
||||||
.main-content.open {
|
|
||||||
width: 165px;
|
|
||||||
transition: width 0.3s ease;
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.main-content.closed {
|
|
||||||
width: 0%;
|
|
||||||
/* min-width: 25px; */
|
|
||||||
transition: width 0.3s ease;
|
|
||||||
background-color: transparent;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar-menu-item {
|
|
||||||
width: 100%;
|
|
||||||
box-sizing: border-box;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar-menu-item.open {
|
|
||||||
width: 100%;
|
|
||||||
/* justify-content: flex-start; */
|
|
||||||
transition: width 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar-menu-item.closed {
|
|
||||||
width: 0%;
|
|
||||||
min-width: 0px;
|
|
||||||
/* justify-content: flex-start; */
|
|
||||||
transition: width 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar-menu-item-content.open {
|
|
||||||
width: 100%;
|
|
||||||
/* justify-content: flex-start; */
|
|
||||||
transition: width 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
.sidebar-menu-item-content.closed {
|
|
||||||
width: 0px;
|
|
||||||
/* justify-content: flex-start; */
|
|
||||||
transition: width 0.3s ease;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Ensure span can shrink */
|
|
||||||
.button-text {
|
|
||||||
display: block; /* Make span a block element */
|
|
||||||
width: 100%; /* Ensure it takes the full width of its parent */
|
|
||||||
overflow: hidden; /* Hide any overflow content */
|
|
||||||
white-space: nowrap; /* Prevent text wrapping */
|
|
||||||
}
|
|
||||||
@@ -1,109 +0,0 @@
|
|||||||
import { useState, useEffect } from 'react';
|
|
||||||
import Button from '@mui/material/Button';
|
|
||||||
import { useTheme } from '@mui/material/styles';
|
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import Tooltip from '@mui/material/Tooltip';
|
|
||||||
import ChevronLeftRounded from "@mui/icons-material/ChevronLeftRounded"
|
|
||||||
import ChevronRightRounded from '@mui/icons-material/ChevronRightRounded';
|
|
||||||
import FileCopyIcon from '@mui/icons-material/FileCopy';
|
|
||||||
import './SideBar.css';
|
|
||||||
|
|
||||||
const Sidebar = ({ onSelection, onOpened, onClosed }) => {
|
|
||||||
const theme = useTheme();
|
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
|
||||||
const [cannedQueries, setCannedQueries] = useState([]);
|
|
||||||
const Icon = isOpen ? ChevronLeftRounded : ChevronRightRounded;
|
|
||||||
|
|
||||||
const toggleIsOpen = () => {
|
|
||||||
if (isOpen) {
|
|
||||||
setIsOpen(false);
|
|
||||||
if (onClosed != null) {
|
|
||||||
onClosed();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setIsOpen(true);
|
|
||||||
if (onOpened != null) {
|
|
||||||
onOpened();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const onMenuItemClick = (event, cannedQuery) => {
|
|
||||||
console.info(`menu item clicked: ${cannedQuery.name}`);
|
|
||||||
onSelection(cannedQuery);
|
|
||||||
};
|
|
||||||
|
|
||||||
// const onMenuItemClick = async (event, cannedQuery) => {
|
|
||||||
// try {
|
|
||||||
// await navigator.clipboard.writeText(cannedQuery.query.join("\n"));
|
|
||||||
// alert(`Copied ${cannedQuery.name} to clipboard`);
|
|
||||||
// } catch (err) {
|
|
||||||
// console.error('Failed to copy query text: ', err);
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
const fetchCannedQueries = async () => {
|
|
||||||
try {
|
|
||||||
const response = await fetch('api/cannedqueries');
|
|
||||||
const data = await response.json();
|
|
||||||
setCannedQueries(data);
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error fetching WebSocket config:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fetchCannedQueries();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const mainContentClass = `main-content ${isOpen ? 'open' : 'closed'}`;
|
|
||||||
const menuItemClass = `sidebar-menu-item ${isOpen ? 'open' : 'closed'}`;
|
|
||||||
const menuItemContentClass = `sidebar-menu-item-content ${isOpen ? 'open' : 'closed'}`;
|
|
||||||
const toggleButtonTitle = `${isOpen ? 'Hide' : 'Show'} Common Queries`;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div
|
|
||||||
className={"sidebar"}
|
|
||||||
style={{
|
|
||||||
display: 'flex',
|
|
||||||
flexDirection: 'row',
|
|
||||||
justifyContent: 'flexStart',
|
|
||||||
alignItems: 'flexStart',
|
|
||||||
margin: theme.spacing(2, 0, 0, 0)
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<div className={mainContentClass}>
|
|
||||||
{cannedQueries.map(cq =>
|
|
||||||
<Button key={cq.name} className={menuItemClass} onClick={(event) => onMenuItemClick(event, cq)}>
|
|
||||||
<div className={menuItemContentClass}>
|
|
||||||
<span className='button-text'>{cq.name}</span>
|
|
||||||
</div>
|
|
||||||
</Button>)
|
|
||||||
}
|
|
||||||
{/* {cannedQueries.map(cq =>
|
|
||||||
<Button
|
|
||||||
variant="contained"
|
|
||||||
color="primary"
|
|
||||||
startIcon={<FileCopyIcon />}
|
|
||||||
onClick={onMenuItemClick}
|
|
||||||
>
|
|
||||||
<div className={menuItemContentClass}>
|
|
||||||
<span className='button-text'>{cq.name}</span>
|
|
||||||
</div>
|
|
||||||
</Button>)} */}
|
|
||||||
</div>
|
|
||||||
<Tooltip title={toggleButtonTitle}>
|
|
||||||
<Button onClick={toggleIsOpen}>
|
|
||||||
<Icon className="w-5 h-5" />
|
|
||||||
</Button>
|
|
||||||
</Tooltip>
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
export default Sidebar;
|
|
||||||
|
|
||||||
Sidebar.propTypes = {
|
|
||||||
onSelection: PropTypes.func,
|
|
||||||
onOpened: PropTypes.func,
|
|
||||||
onClosed: PropTypes.func,
|
|
||||||
};
|
|
||||||
@@ -42,56 +42,32 @@ const getDarkPalette = () => {
|
|||||||
dark: '#ffffff12',
|
dark: '#ffffff12',
|
||||||
contrastText: '#c8d4f7',
|
contrastText: '#c8d4f7',
|
||||||
},
|
},
|
||||||
action: {
|
|
||||||
hoverOpacity: 0.08
|
|
||||||
},
|
|
||||||
text: {
|
text: {
|
||||||
primary: '#eaf8f8',
|
primary: '#eaf8f8',
|
||||||
dark: '#eaf8f8a0'
|
dark: '#eaf8f8a0'
|
||||||
},
|
},
|
||||||
queryStartButton: {
|
query_start_button: {
|
||||||
Subscribed: {
|
active: {
|
||||||
color: '#33baf9',
|
color: '#33baf9',
|
||||||
backgroundColor: '#ffffff40',
|
background_color: '#ffffff40',
|
||||||
},
|
},
|
||||||
Unsubscribed: {
|
inactive: {
|
||||||
color: '#ffffff40',
|
color: '#ffffff40',
|
||||||
backgroundColor: '#ffffff00',
|
background_color: '#ffffff00',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
queryStopButton: {
|
|
||||||
Subscribed: {
|
|
||||||
color: '#ff4444a0',
|
|
||||||
backgroundColor: '#ffffff40',
|
|
||||||
},
|
|
||||||
Unsubscribed: {
|
|
||||||
color: '#ff444450',
|
|
||||||
backgroundColor: '#ffffff00',
|
|
||||||
}
|
|
||||||
},
|
|
||||||
error: {
|
|
||||||
light: '#e57373',
|
|
||||||
main: '#f44336',
|
|
||||||
dark: '#d32f2f',
|
|
||||||
contrastText: '#fff',
|
|
||||||
},
|
|
||||||
warning: {
|
warning: {
|
||||||
light: '#ffb74d',
|
main: '#c4823f'
|
||||||
main: '#ff9800',
|
|
||||||
dark: '#f57c00',
|
|
||||||
contrastText: '#000',
|
|
||||||
},
|
},
|
||||||
info: {
|
query_stop_button: {
|
||||||
light: '#64b5f6',
|
active: {
|
||||||
main: '#2196f3',
|
color: '#ff4444a0',
|
||||||
dark: '#303030',
|
background_color: '#ffffff40',
|
||||||
contrastText: '#fff',
|
},
|
||||||
},
|
inactive: {
|
||||||
success: {
|
color: '#ff444450',
|
||||||
light: '#81c784',
|
background_color: '#ffffff00',
|
||||||
main: '#4caf50',
|
}
|
||||||
dark: '#388e3c',
|
|
||||||
contrastText: '#000',
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
|
|
||||||
color-scheme: light dark;
|
color-scheme: light dark;
|
||||||
color: rgba(255, 255, 255, 0.87);
|
color: rgba(0, 0, 0, 0.87);
|
||||||
background-color: #242424;
|
background-color: #242424;
|
||||||
|
|
||||||
font-synthesis: none;
|
font-synthesis: none;
|
||||||
|
|||||||
@@ -3,5 +3,7 @@ import ReactDOM from 'react-dom/client';
|
|||||||
import App from './App';
|
import App from './App';
|
||||||
|
|
||||||
ReactDOM.createRoot(document.getElementById('root')).render(
|
ReactDOM.createRoot(document.getElementById('root')).render(
|
||||||
<App />
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>
|
||||||
)
|
)
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { fileURLToPath, URL } from 'node:url';
|
import { fileURLToPath, URL } from 'node:url';
|
||||||
import { defineConfig, loadEnv } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
import plugin from '@vitejs/plugin-react';
|
import plugin from '@vitejs/plugin-react';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
@@ -29,12 +29,13 @@ if (!fs.existsSync(certFilePath) || !fs.existsSync(keyFilePath)) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const target = env.ASPNETCORE_HTTPS_PORT
|
||||||
|
? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}`
|
||||||
|
: env.ASPNETCORE_URLS
|
||||||
|
? env.ASPNETCORE_URLS.split(';')[0]
|
||||||
|
: 'https://localhost:5001';
|
||||||
|
|
||||||
export default defineConfig(({ $$command, mode, $$isSsrBuild, $$isPreview }) => {
|
export default defineConfig(({ $$command, mode, $$isSsrBuild, $$isPreview }) => {
|
||||||
const target = env.ASPNETCORE_HTTPS_PORT
|
|
||||||
? `https://localhost:${env.ASPNETCORE_HTTPS_PORT}`
|
|
||||||
: env.ASPNETCORE_URLS
|
|
||||||
? env.ASPNETCORE_URLS.split(';')[0]
|
|
||||||
: 'https://localhost:8443';
|
|
||||||
return {
|
return {
|
||||||
plugins: [plugin()],
|
plugins: [plugin()],
|
||||||
resolve: {
|
resolve: {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<InvariantGlobalization>true</InvariantGlobalization>
|
<InvariantGlobalization>true</InvariantGlobalization>
|
||||||
@@ -12,8 +12,8 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
<PackageReference Include="CommandLineParser" Version="2.9.1" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="7.0.20" />
|
<PackageReference Include="Microsoft.AspNetCore.SpaProxy" Version="8.0.6" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="7.0.20" />
|
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="8.0.6" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
@@ -27,14 +27,10 @@
|
|||||||
<ProjectReference Include="..\..\client\spark_api\spark_api.csproj" />
|
<ProjectReference Include="..\..\client\spark_api\spark_api.csproj" />
|
||||||
<ProjectReference Include="..\..\client\spark_core\spark_core.csproj" />
|
<ProjectReference Include="..\..\client\spark_core\spark_core.csproj" />
|
||||||
<ProjectReference Include="..\..\client\spark_websocket\spark_websocket.csproj" />
|
<ProjectReference Include="..\..\client\spark_websocket\spark_websocket.csproj" />
|
||||||
|
<ProjectReference Include="..\Bts.Extensions.DependencyInjection\Bts.Extensions.DependencyInjection.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<!-- <ItemGroup>
|
||||||
<ConfigurationProfile Include="appsettings.Development.json" />
|
<Content Update="wwwroot\alt-index.html" CopyToPublishDirectory="Never" />
|
||||||
<ConfigurationProfile Include="appsettings.Production.json" />
|
</ItemGroup> -->
|
||||||
<ConfigurationProfile Include="appsettings.ProductionAws.json" />
|
|
||||||
<ConfigurationProfile Include="appsettings.Staging.json" />
|
|
||||||
<ConfigurationProfile Include="appsettings.json" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace Bts.DataStreamWebApp.Server;
|
|
||||||
|
|
||||||
public class CannedQueriesConfig {
|
|
||||||
public List<CannedQuery>? Items { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
namespace Bts.DataStreamWebApp.Server;
|
|
||||||
|
|
||||||
public class CannedQuery {
|
|
||||||
public string? Name { get; set; }
|
|
||||||
public List<string>? Query { get; set; }
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
{
|
||||||
|
"Spark": {
|
||||||
|
"ConfigServer": "http://localhost:8000/config"
|
||||||
|
},
|
||||||
|
"SparkdCredentials": {
|
||||||
|
"User": "bts",
|
||||||
|
"Password": ""
|
||||||
|
},
|
||||||
|
"MasterWorker": {
|
||||||
|
"Interval": "00:00:00.1"
|
||||||
|
},
|
||||||
|
"PubSub": {
|
||||||
|
"Routing": {
|
||||||
|
"PublisherRoutes": [
|
||||||
|
{
|
||||||
|
"Name": "default",
|
||||||
|
"ServerAddress": "bts-cloud://127.0.0.1:12345",
|
||||||
|
"TagRegExp": ".*"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"SubscriberRoutes": [
|
||||||
|
{
|
||||||
|
"Name": "default",
|
||||||
|
"ServerAddress": "bts-cloud://127.0.0.1:12345",
|
||||||
|
"TagRegExp": ".*"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ViewStreamDatabase": {
|
||||||
|
"Interval": "00:00:01"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"content_root_path": "build/Bts.DataStreamWebApp.Client/production",
|
||||||
|
"web_root_path": "dist"
|
||||||
|
}
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
namespace Bts.DataStreamWebApp.Server;
|
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
[ApiController]
|
|
||||||
[Route("api/[controller]")]
|
|
||||||
public class CannedQueriesController : ControllerBase {
|
|
||||||
readonly IConfiguration config;
|
|
||||||
|
|
||||||
public CannedQueriesController(IConfiguration config) =>
|
|
||||||
this.config = config;
|
|
||||||
|
|
||||||
[HttpGet(Name = "GetCannedQueries")]
|
|
||||||
public IEnumerable<CannedQuery>? Get() {
|
|
||||||
var cannedQueries = config.GetSection("CannedQueries").Get<List<CannedQuery>>()?.ToArray() ?? Array.Empty<CannedQuery>();
|
|
||||||
return cannedQueries;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-22
@@ -1,22 +0,0 @@
|
|||||||
// using Bts.DataStreamWebApp.Server;
|
|
||||||
|
|
||||||
// using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
// [ApiController]
|
|
||||||
// [Route("api/[controller]")]
|
|
||||||
// public class ConfigController : ControllerBase {
|
|
||||||
// private readonly IConfiguration _configuration;
|
|
||||||
|
|
||||||
// public ConfigController(IConfiguration configuration) {
|
|
||||||
// _configuration = configuration;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// [HttpGet("websocket")]
|
|
||||||
// public ActionResult<DataStreamWebSocketConfig> GetWebSocketConfig() {
|
|
||||||
// var endpoint = $"{_configuration["Kestrel:Endpoints:Http:Url"]}/ws";
|
|
||||||
// var webSocketConfig = new DataStreamWebSocketConfig {
|
|
||||||
// Endpoint = endpoint // or Https based on your setup
|
|
||||||
// };
|
|
||||||
// return Ok(webSocketConfig);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
+16
-10
@@ -1,30 +1,36 @@
|
|||||||
namespace Bts.DataStreamWebApp.Server.Controllers;
|
namespace Bts.DataStreamWebApp.Server.Controllers;
|
||||||
|
|
||||||
|
using BCG;
|
||||||
|
|
||||||
|
using bts.api.core;
|
||||||
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
|
||||||
[Route("/ws")]
|
[Route("/ws")]
|
||||||
public class DataStreamSubscriptionController : ControllerBase {
|
public class DataStreamSubscriptionController : ControllerBase {
|
||||||
readonly ILogger logger;
|
readonly ILogger logger;
|
||||||
|
readonly PrimitiveManager primitiveManager;
|
||||||
|
readonly IServiceProvider serviceProvider;
|
||||||
|
|
||||||
public DataStreamSubscriptionController(ILogger<DataStreamSubscriptionController> logger) {
|
public DataStreamSubscriptionController(ILogger<DataStreamSubscriptionController> logger, PrimitiveManager primitiveManager, IServiceProvider serviceProvider) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.primitiveManager = primitiveManager;
|
||||||
|
this.serviceProvider = serviceProvider;
|
||||||
logger.LogInformation("Creating {ControllerType}", GetType().Name);
|
logger.LogInformation("Creating {ControllerType}", GetType().Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route("/ws")]
|
[Route("/ws")]
|
||||||
public async Task Get(CancellationToken cancellationToken) {
|
public async Task Get() {
|
||||||
if (!HttpContext.WebSockets.IsWebSocketRequest) {
|
if (!HttpContext.WebSockets.IsWebSocketRequest) {
|
||||||
logger.LogError("Expected websocket request on path '{}'", HttpContext.Request.Path);
|
logger.LogError("Expected websocket request on path '{}'", HttpContext.Request.Path);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logger.LogInformation("Establishing websocket connection...");
|
logger.LogInformation("Establishing websocket connection...");
|
||||||
try {
|
using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
|
||||||
using var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync();
|
logger.LogInformation("Websocket connection established.");
|
||||||
logger.LogInformation("Websocket connection established.");
|
var context = ServiceContext.create();
|
||||||
using var server = new DataStreamWebSocketServer(webSocket, logger);
|
await context.login("bts", string.Empty);
|
||||||
await server.Run(cancellationToken);
|
var server = new DataStreamWebSocketServer(webSocket, logger, primitiveManager, serviceProvider);
|
||||||
} catch (Exception ex) {
|
await server.Run();
|
||||||
logger.LogError("DataStreamSubscriptionController.Run threw exception: {Exception}", ex);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,29 +7,27 @@ using bts.websocket_core.json_rpc;
|
|||||||
using Bts.DataStreamCore;
|
using Bts.DataStreamCore;
|
||||||
using Bts.DataStreamWebApp.Server.Messages;
|
using Bts.DataStreamWebApp.Server.Messages;
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Net.WebSockets;
|
using System.Net.WebSockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
class DataStreamSubscription : IDisposable, IHostedService {
|
class DataStreamSubscription : IDisposable {
|
||||||
public readonly ViewStream ViewStream;
|
public readonly ViewStream ViewStream;
|
||||||
public DataPacket? LastFired;
|
public DataPacket? LastFired;
|
||||||
|
public readonly string Id;
|
||||||
|
|
||||||
readonly ILogger logger;
|
readonly ILogger logger;
|
||||||
readonly WebSocket webSocket;
|
readonly WebSocket webSocket;
|
||||||
|
readonly DataPacketJsonSerializer dataPacketSerializer = new();
|
||||||
|
|
||||||
public DataStreamSubscription(string id, JsonRpcId requestId, ViewStream viewStream, WebSocket webSocket, ILogger logger) {
|
public DataStreamSubscription(string id, ViewStream viewStream, WebSocket webSocket, ILogger logger) {
|
||||||
ViewStream = viewStream;
|
ViewStream = viewStream;
|
||||||
RequestId = requestId;
|
|
||||||
Id = id;
|
Id = id;
|
||||||
this.webSocket = webSocket;
|
this.webSocket = webSocket;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Id { get; }
|
|
||||||
public JsonRpcId RequestId { get; }
|
|
||||||
public SubscriptionStatus Status { get; private set; }
|
public SubscriptionStatus Status { get; private set; }
|
||||||
|
|
||||||
public void Start() {
|
public void Start() {
|
||||||
@@ -42,12 +40,6 @@ class DataStreamSubscription : IDisposable, IHostedService {
|
|||||||
ViewStream.onChange += onChange;
|
ViewStream.onChange += onChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken cancellationToken) {
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
Start();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task Clear() {
|
public Task Clear() {
|
||||||
if (LastFired is null) {
|
if (LastFired is null) {
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
@@ -66,12 +58,6 @@ class DataStreamSubscription : IDisposable, IHostedService {
|
|||||||
ViewStream.onChange -= onChange;
|
ViewStream.onChange -= onChange;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken) {
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
|
||||||
Stop();
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose() =>
|
public void Dispose() =>
|
||||||
Stop();
|
Stop();
|
||||||
|
|
||||||
@@ -97,10 +83,7 @@ class DataStreamSubscription : IDisposable, IHostedService {
|
|||||||
IncludeCurrent = true,
|
IncludeCurrent = true,
|
||||||
UseObjectRows = true,
|
UseObjectRows = true,
|
||||||
});
|
});
|
||||||
var res = JsonRpcRequest.CreateNotification(method, new DataStreamSubscriptionUpdate() {
|
var res = JsonRpcRequest.CreateNotification(method, dp);
|
||||||
SubscriptionId = Id,
|
|
||||||
Table = dp
|
|
||||||
});
|
|
||||||
var str = serialize(res, serializerOpts);
|
var str = serialize(res, serializerOpts);
|
||||||
if (str is null) {
|
if (str is null) {
|
||||||
logger.LogError("Unsubscribing from stream early because we failed to serialize an outgoing DataPacket");
|
logger.LogError("Unsubscribing from stream early because we failed to serialize an outgoing DataPacket");
|
||||||
@@ -113,12 +96,8 @@ class DataStreamSubscription : IDisposable, IHostedService {
|
|||||||
dp.schema.columnNames.Length,
|
dp.schema.columnNames.Length,
|
||||||
str.Length);
|
str.Length);
|
||||||
var bytes = Encoding.UTF8.GetBytes(str);
|
var bytes = Encoding.UTF8.GetBytes(str);
|
||||||
try {
|
await webSocket.SendAsync(bytes, WebSocketMessageType.Text, true, CancellationToken.None);
|
||||||
await webSocket.SendAsync(bytes, WebSocketMessageType.Text, true, CancellationToken.None);
|
LastFired = dp;
|
||||||
LastFired = dp;
|
|
||||||
} catch (WebSocketException ex) {
|
|
||||||
logger.LogError($"sendDataPacket failed on webSocket.SendAsync: {ex}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string? serialize<T>(T message, JsonSerializerOptions? opts) {
|
string? serialize<T>(T message, JsonSerializerOptions? opts) {
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
namespace Bts.DataStreamWebApp.Server;
|
|
||||||
|
|
||||||
using BCG;
|
|
||||||
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
public class DataStreamSubscriptionUpdate {
|
|
||||||
[JsonPropertyName("subscription_id")]
|
|
||||||
public string? SubscriptionId { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("table")]
|
|
||||||
public DataPacket? Table { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace Bts.DataStreamWebApp.Server;
|
|
||||||
|
|
||||||
public class DataStreamWebSocketConfig {
|
|
||||||
public string? Endpoint { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
namespace Bts.DataStreamWebApp.Server.Controllers;
|
namespace Bts.DataStreamWebApp.Server.Controllers;
|
||||||
|
|
||||||
|
using BCG;
|
||||||
|
|
||||||
using bts.websocket_core.json_rpc;
|
using bts.websocket_core.json_rpc;
|
||||||
|
|
||||||
using Bts.DataStreamWebApp.Server.Messages;
|
using Bts.DataStreamWebApp.Server.Messages;
|
||||||
@@ -9,22 +11,26 @@ using System.Text;
|
|||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Text.Json.Nodes;
|
using System.Text.Json.Nodes;
|
||||||
|
|
||||||
public class DataStreamWebSocketServer : IDisposable, IAsyncDisposable {
|
public class DataStreamWebSocketServer {
|
||||||
readonly ILogger logger;
|
readonly ILogger logger;
|
||||||
readonly WebSocket webSocket;
|
readonly WebSocket webSocket;
|
||||||
readonly Dictionary<string, DataStreamSubscription> subscriptions = new();
|
readonly Dictionary<string, DataStreamSubscription> subscriptions = new();
|
||||||
|
readonly PrimitiveManager primitiveManager;
|
||||||
|
readonly IServiceProvider serviceProvider;
|
||||||
|
|
||||||
public DataStreamWebSocketServer(WebSocket webSocket, ILogger logger) {
|
public DataStreamWebSocketServer(WebSocket webSocket, ILogger logger, PrimitiveManager primitiveManager, IServiceProvider serviceProvider) {
|
||||||
this.webSocket = webSocket;
|
this.webSocket = webSocket;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
this.primitiveManager = primitiveManager;
|
||||||
|
this.serviceProvider = serviceProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<int> Run(CancellationToken cancellationToken) {
|
public async Task<int> Run() {
|
||||||
logger.LogInformation("DataStreamWebSocketServer running");
|
logger.LogInformation("DataStreamWebSocketServer running");
|
||||||
await foreach (var req in JsonRpcRequestAsyncEnumerable.Create(webSocket, logger, cancellationToken)) {
|
await foreach (var req in JsonRpcRequestAsyncEnumerable.Create(webSocket, logger)) {
|
||||||
await (req.Method switch {
|
await (req.Method switch {
|
||||||
"subscribe" => onSubscribe(req, cancellationToken),
|
"subscribe" => onSubscribe(req),
|
||||||
"unsubscribe" => onUnsubscribe(req.Deserialize<UnsubscribeRequest>(), cancellationToken),
|
"unsubscribe" => onUnsubscribe(req.Deserialize<UnsubscribeRequest>()),
|
||||||
_ => Task.CompletedTask,
|
_ => Task.CompletedTask,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -32,117 +38,56 @@ public class DataStreamWebSocketServer : IDisposable, IAsyncDisposable {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
async Task onSubscribe(JsonRpcRequest<JsonNode> req) {
|
||||||
/// Disposes internal subscriptions. To additionally notify the client of the subscription status
|
|
||||||
/// change(s), use <see cref="DisposeAsync"/>.
|
|
||||||
/// </summary>
|
|
||||||
public void Dispose() {
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
disposeSubscriptions();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Disposes internal subscriptions (like <see cref="Dispose"/>), then sends 'subscription status change'
|
|
||||||
/// notifications to the client (unlike <see cref="Dispose"/>).
|
|
||||||
/// </summary>
|
|
||||||
public async ValueTask DisposeAsync() {
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
var finalSubs = subscriptions.Values.Select(s => (s.RequestId, s.Id)).ToList();
|
|
||||||
disposeSubscriptions();
|
|
||||||
// Send a 'subscription status change' msg to the client for each one.
|
|
||||||
foreach (var (requestId, id) in finalSubs) {
|
|
||||||
await sendSubscriptionStatus(requestId, id, "unsubscribe", SubscriptionStatus.Unsubscribed, CancellationToken.None);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async Task onSubscribe(JsonRpcRequest<JsonNode> req, CancellationToken cancellationToken) {
|
|
||||||
ArgumentNullException.ThrowIfNull(req.Id);
|
ArgumentNullException.ThrowIfNull(req.Id);
|
||||||
ArgumentException.ThrowIfNullOrEmpty(req.Method);
|
ArgumentException.ThrowIfNullOrEmpty(req.Method);
|
||||||
if (!SubscribeRequest.Parse(req, out var subReq, out var parseErr, out var errCode)) {
|
if (!SubscribeRequest.ParseQuery(req, primitiveManager, out var vs, out var subId, out var errMsg, out var errCode)) {
|
||||||
logger.LogError("Invalid 'subscribe' request: {Reason}", parseErr);
|
logger.LogError("Invalid 'subscribe' request: {Reason}", errMsg);
|
||||||
var rpcError = JsonRpcResponse.CreateError<SubscriptionError>(
|
await send(new JsonRpcError<JsonNode>() {
|
||||||
req.Id, new() { Code = (long)errCode, Message = "Failed to parse subscription request", Data = parseErr });
|
Code = (long)errCode,
|
||||||
await send(rpcError, cancellationToken);
|
Message = $"{errCode}: {errMsg}",
|
||||||
return;
|
});
|
||||||
}
|
|
||||||
var subId = subReq.SubscriptionId ?? throw new InvalidOperationException("SubscriptionId is null (parse false)");
|
|
||||||
disposeSubscription(subId);
|
|
||||||
if (!subReq.ParseQuery(out var vs, out parseErr, out errCode)) {
|
|
||||||
logger.LogError("Invalid 'subscribe' request: {Reason}", parseErr);
|
|
||||||
var rpcError = JsonRpcResponse.CreateError<SubscriptionError>(
|
|
||||||
req.Id, new() { Code = (long)errCode, Message = "Failed to parse subscription request", Data = parseErr });
|
|
||||||
await send(rpcError, cancellationToken);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (subscriptions.TryGetValue(subId, out var oldSub)) {
|
if (subscriptions.TryGetValue(subId, out var oldSub)) {
|
||||||
logger.LogInformation("Disposing existing subscription with id {SubscriptionId}", subId);
|
|
||||||
oldSub.Dispose();
|
oldSub.Dispose();
|
||||||
}
|
}
|
||||||
var sub = new DataStreamSubscription(subId, req.Id.Value, vs, webSocket, logger);
|
vs.Reset(serviceProvider);
|
||||||
|
var sub = new DataStreamSubscription(subId, vs, webSocket, logger);
|
||||||
subscriptions[subId] = sub;
|
subscriptions[subId] = sub;
|
||||||
await sendSubscriptionStatus(req.Id.Value, subId, req.Method, SubscriptionStatus.Subscribed, cancellationToken);
|
await sendSubscriptionStatus(req.Id.Value, subId, req.Method, SubscriptionStatus.Subscribed);
|
||||||
vs.ErrorChanged += OnStreamError;
|
sub.Start();
|
||||||
await sub.StartAsync(cancellationToken);
|
|
||||||
|
|
||||||
async void OnStreamError(Exception exception) {
|
|
||||||
logger.LogError("Error in ViewStream (disposing subscription): {Exception}", exception);
|
|
||||||
subscriptions.Remove(sub.Id);
|
|
||||||
sub.Dispose();
|
|
||||||
var error = new SubscriptionError() {
|
|
||||||
ErrorMessage = "Error in ViewStream (disposing subscription)"
|
|
||||||
};
|
|
||||||
if (exception is not null) {
|
|
||||||
error.ErrorMessage += ". " + exception.Message;
|
|
||||||
error.StackTrace = exception.StackTrace?.Split("\n")?.ToList();
|
|
||||||
}
|
|
||||||
var rpcError = JsonRpcResponse.CreateError<SubscriptionError>(
|
|
||||||
req.Id, new() { Code = (long)ErrorCode.ViewStreamError, Message = "Error in ViewStream (disposing subscription)", Data = error });
|
|
||||||
await send(rpcError, cancellationToken);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async Task onUnsubscribe(JsonRpcRequest<UnsubscribeRequest> req, CancellationToken cancellationToken) {
|
async Task onUnsubscribe(JsonRpcRequest<UnsubscribeRequest> req) {
|
||||||
ArgumentNullException.ThrowIfNull(req.Id);
|
ArgumentNullException.ThrowIfNull(req.Id);
|
||||||
ArgumentException.ThrowIfNullOrEmpty(req.Method);
|
ArgumentException.ThrowIfNullOrEmpty(req.Method);
|
||||||
var subId = req.Params?.SubscriptionId ?? string.Empty;
|
var subId = req.Params?.SubscriptionId ?? string.Empty;
|
||||||
if (!disposeSubscription(subId)) {
|
|
||||||
logger.LogInformation("Unable to dispose subscription. Subscription with id {Id} not found.", subId);
|
|
||||||
}
|
|
||||||
await sendSubscriptionStatus(req.Id.Value, subId, "unsubscribe", SubscriptionStatus.Unsubscribed, cancellationToken);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool disposeSubscription(string subId) {
|
|
||||||
if (!subscriptions.TryGetValue(subId, out var sub)) {
|
if (!subscriptions.TryGetValue(subId, out var sub)) {
|
||||||
return false;
|
logger.LogInformation("Ignoring '{Method}' request because no subscription was found with id {Id}.", req.Method, subId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
logger.LogInformation("Disposing subscription with id {Id}", subId);
|
logger.LogInformation("Disposing subscription");
|
||||||
sub.Dispose();
|
sub.Dispose();
|
||||||
subscriptions.Remove(subId);
|
subscriptions.Remove(subId);
|
||||||
return true;
|
await sendSubscriptionStatus(req.Id.Value, subId, req.Method, SubscriptionStatus.Unsubscribed);
|
||||||
}
|
}
|
||||||
|
|
||||||
Task sendSubscriptionStatus(JsonRpcId reqId, string subId, string method, SubscriptionStatus status, CancellationToken cancellationToken) {
|
Task sendSubscriptionStatus(JsonRpcId reqId, string subId, string method, SubscriptionStatus status) {
|
||||||
logger.LogInformation("Sending {Method} ack. SubscriptionId = {SubscriptionId}", method, subId);
|
logger.LogInformation("Sending {Method} ack. SubscriptionId = {SubscriptionId}", method, subId);
|
||||||
var response = JsonRpcResponse.Create(reqId, new SubscriptionStatusMessage() {
|
return send(JsonRpcResponse.Create(reqId, new SubscriptionStatusMessage() {
|
||||||
SubscriptionId = subId,
|
SubscriptionId = subId,
|
||||||
Status = status,
|
Status = status,
|
||||||
});
|
}));
|
||||||
return send(response, cancellationToken);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Task send<T>(T message, CancellationToken cancellationToken) {
|
Task send<T>(T message) {
|
||||||
if (message is null) {
|
if (message is null) {
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
var str = JsonSerializer.Serialize(message);
|
var str = JsonSerializer.Serialize(message);
|
||||||
var bytes = Encoding.UTF8.GetBytes(str);
|
var bytes = Encoding.UTF8.GetBytes(str);
|
||||||
logger.LogTrace("Sending data. Length = {Length}", bytes.Length);
|
logger.LogTrace("Sending data. Length = {Length}", bytes.Length);
|
||||||
return webSocket.SendAsync(bytes, WebSocketMessageType.Text, true, cancellationToken);
|
return webSocket.SendAsync(bytes, WebSocketMessageType.Text, true, CancellationToken.None);
|
||||||
}
|
|
||||||
|
|
||||||
void disposeSubscriptions() {
|
|
||||||
logger.LogInformation("Disposing DataStreamWebSocketServer subscriptions. Count: {Count}", subscriptions.Count);
|
|
||||||
subscriptions.Values.DisposeAll();
|
|
||||||
subscriptions.Clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
FROM bluetradingsystems/linux_dotnet7
|
|
||||||
|
|
||||||
RUN dotnet dev-certs https --trust
|
|
||||||
COPY --chown=bts:bts "build/Release/bin/net7.0/linux-x64/publish" "bin"
|
|
||||||
COPY --chown=bts:bts "build/Bts.DataStreamWebApp.Client/production/dist" "bin/wwwroot"
|
|
||||||
COPY --chown=bts:bts "src/DataStreamSuite/Bts.DataStreamWebApp.Server/spark.conf" ".local/share/bts/Bts.DataStreamWebApp.Server/conf/spark.conf"
|
|
||||||
WORKDIR "/home/bts/bin"
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
namespace Bts.DataStreamWebApp.Server;
|
|
||||||
|
|
||||||
public class CannedQueriesResponse {
|
|
||||||
public List<CannedQuery>? Items { get; set; }
|
|
||||||
}
|
|
||||||
@@ -3,5 +3,4 @@ namespace Bts.DataStreamWebApp.Server.Messages;
|
|||||||
enum ErrorCode {
|
enum ErrorCode {
|
||||||
None = 0,
|
None = 0,
|
||||||
InvalidSubscriptionRequest,
|
InvalidSubscriptionRequest,
|
||||||
ViewStreamError,
|
|
||||||
}
|
}
|
||||||
@@ -18,52 +18,54 @@ public class SubscribeRequest {
|
|||||||
[JsonPropertyName("subscription_id")]
|
[JsonPropertyName("subscription_id")]
|
||||||
public string? SubscriptionId { get; set; }
|
public string? SubscriptionId { get; set; }
|
||||||
|
|
||||||
internal static bool Parse(JsonRpcRequest<JsonNode> req, [NotNullWhen(true)]out SubscribeRequest? subscription, [NotNullWhen(false)]out SubscriptionError? error, out ErrorCode errorCode) {
|
internal static bool ParseQuery(
|
||||||
subscription = null;
|
JsonRpcRequest<JsonNode> req,
|
||||||
|
PrimitiveManager primitiveManager,
|
||||||
|
[NotNullWhen(true)] out ViewStream? stream,
|
||||||
|
[NotNullWhen(true)] out string? subscriptionId,
|
||||||
|
[NotNullWhen(false)] out string? errorMessage,
|
||||||
|
out ErrorCode errorCode
|
||||||
|
) {
|
||||||
|
stream = null;
|
||||||
|
subscriptionId = null;
|
||||||
errorCode = ErrorCode.None;
|
errorCode = ErrorCode.None;
|
||||||
var paramsJsonObj = req.Params?.AsObject();
|
var paramsJsonObj = req.Params?.AsObject();
|
||||||
error = null;
|
|
||||||
if (paramsJsonObj is null) {
|
if (paramsJsonObj is null) {
|
||||||
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
||||||
error = new() { ErrorMessage = "'params' object not found" };
|
errorMessage = "'params' object not found";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
subscription = paramsJsonObj.Deserialize<SubscribeRequest>();
|
var subReq = paramsJsonObj.Deserialize<SubscribeRequest>();
|
||||||
if (subscription is null) {
|
if (subReq is null) {
|
||||||
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
||||||
error = new() { ErrorMessage = "'params' object invalid" };
|
errorMessage = "'params' object invalid";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
subscriptionId = subReq.SubscriptionId ?? string.Empty;
|
||||||
}
|
var query = subReq.Query;
|
||||||
|
if (query is null) {
|
||||||
internal bool ParseQuery([NotNullWhen(true)] out ViewStream? stream, [NotNullWhen(false)] out SubscriptionError? error, out ErrorCode errorCode) {
|
|
||||||
stream = null;
|
|
||||||
errorCode = ErrorCode.None;
|
|
||||||
error = null;
|
|
||||||
if (Query is null) {
|
|
||||||
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
||||||
error = new() { ErrorMessage = "'params.query' field not found (expected a string)" };
|
errorMessage = "'params.query' field not found (expected a string)";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
var exp = DataStreamExpressionsInterpreter.Evaluate(Query);
|
errorMessage = null;
|
||||||
|
var exp = DataStreamExpressionsInterpreter.Evaluate(query);
|
||||||
if (exp is null) {
|
if (exp is null) {
|
||||||
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
||||||
error = new() { ErrorMessage = "'params.query' expression has invalid syntax" };
|
errorMessage = "'params.query' expression has invalid syntax";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Exception? exception = null;
|
string? exceptionMsg = null;
|
||||||
try {
|
try {
|
||||||
stream = exp.getView(new Dictionary<string, StatementExpression>(0));
|
stream = exp.getView(new Dictionary<string, StatementExpression>(0), primitiveManager);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
exception = ex;
|
exceptionMsg = ex.ToString();
|
||||||
}
|
}
|
||||||
if (stream is null) {
|
if (stream is null) {
|
||||||
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
errorCode = ErrorCode.InvalidSubscriptionRequest;
|
||||||
error = new() { ErrorMessage = "Failed to create ViewStream from 'params.query' expression (check for typos in arguments/typenames)" };
|
errorMessage = "Failed to create ViewStream from 'params.query' expression (check for typos in arguments/typenames)";
|
||||||
if (exception is not null) {
|
if (exceptionMsg is not null) {
|
||||||
error.ErrorMessage += ". " + exception.Message;
|
errorMessage += ". Error" + exceptionMsg;
|
||||||
error.StackTrace = exception.StackTrace?.Split("\n")?.ToList();
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +0,0 @@
|
|||||||
namespace Bts.DataStreamWebApp.Server.Messages;
|
|
||||||
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
public class SubscriptionError {
|
|
||||||
[JsonPropertyName("error_message")]
|
|
||||||
public string? ErrorMessage { get; set; }
|
|
||||||
|
|
||||||
[JsonPropertyName("stack_trace")]
|
|
||||||
public List<string>? StackTrace { get; set; }
|
|
||||||
}
|
|
||||||
@@ -1,82 +1,64 @@
|
|||||||
using Bts.DataStreamCore.Services;
|
using Bts.DataStreamCore.Services;
|
||||||
using Bts.PubSub.Services;
|
using Bts.DataStreamWebApp.Server.Services;
|
||||||
|
using Bts.PubSub.Services;
|
||||||
using Spark.Api.Services;
|
|
||||||
using Spark.Core.Services;
|
using Spark.Api.Services;
|
||||||
|
using Spark.Core.Services;
|
||||||
using System.Reactive.Linq;
|
|
||||||
using System.Reflection;
|
using System.Reactive.Linq;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(new WebApplicationOptions {
|
var builder = WebApplication.CreateBuilder(new WebApplicationOptions {
|
||||||
Args = args,
|
Args = args,
|
||||||
ApplicationName = "Bts.DataStreamWebApp.Server",
|
ApplicationName = "Bts.DataStreamWebApp.Server",
|
||||||
});
|
});
|
||||||
ConfigureApp(builder.Configuration, builder.Environment.EnvironmentName);
|
ConfigureApp(builder.Configuration);
|
||||||
ConfigureServices(builder.Services, builder.Configuration);
|
ConfigureServices(builder.Services, builder.Configuration);
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
var wsOpts = new WebSocketOptions {
|
if (app.Environment.IsDevelopment()) {
|
||||||
KeepAliveInterval = TimeSpan.FromMinutes(2)
|
app.UseDirectoryBrowser();
|
||||||
};
|
}
|
||||||
if (app.Environment.IsDevelopment()) {
|
var wsOpts = new WebSocketOptions {
|
||||||
app.UseDirectoryBrowser("/browse");
|
KeepAliveInterval = TimeSpan.FromMinutes(2)
|
||||||
app.UseSwagger();
|
};
|
||||||
app.UseSwaggerUI();
|
app.UseWebSockets(wsOpts);
|
||||||
}
|
app.UseDefaultFiles();
|
||||||
app.UseHttpsRedirection();
|
app.UseStaticFiles();
|
||||||
app.UseWebSockets(wsOpts);
|
if (app.Environment.IsDevelopment()) {
|
||||||
app.UseDefaultFiles();
|
app.UseSwagger();
|
||||||
app.UseStaticFiles();
|
app.UseSwaggerUI();
|
||||||
app.UseAuthorization();
|
}
|
||||||
app.MapControllers();
|
app.UseHttpsRedirection();
|
||||||
try {
|
app.UseAuthorization();
|
||||||
Console.Write($"Starting Application");
|
app.MapControllers();
|
||||||
app.Run();
|
try {
|
||||||
Console.Write($"Application exited gracefully.");
|
Console.Write($"Starting Application");
|
||||||
} catch (Exception ex) {
|
app.Run();
|
||||||
Console.Error.Write($"Application crashed: {ex}");
|
Console.Write($"Application exited gracefully.");
|
||||||
return 1;
|
} catch (Exception ex) {
|
||||||
}
|
Console.Error.Write($"Application crashed: {ex}");
|
||||||
return 0;
|
return 1;
|
||||||
|
}
|
||||||
static void ConfigureApp(ConfigurationManager configBuilder, string environment) {
|
return 0;
|
||||||
// We prefix appsettings with the exe name because multiple exes will usually be in the build dir
|
|
||||||
// (this way, each exe can still load its own appsettings files from the current directory).
|
static void ConfigureApp(ConfigurationManager configBuilder) {
|
||||||
var exeName = Assembly.GetCallingAssembly().GetName().Name;
|
configBuilder.AddCommandLine(Environment.GetCommandLineArgs());
|
||||||
AddJsonFile($"{exeName}.appsettings.json");
|
var cfgRoot = configBuilder.GetSection("config");
|
||||||
AddJsonFile($"{exeName}.appsettings.{environment}.json");
|
if (cfgRoot?.Value is not null) {
|
||||||
|
configBuilder.AddJsonFile(cfgRoot.Value);
|
||||||
var cfg = configBuilder.GetSection("config")?.Value;
|
}
|
||||||
if (!SetBasePath(cfg)) {
|
}
|
||||||
AddJsonFile(cfg);
|
|
||||||
}
|
static void ConfigureServices(IServiceCollection services, IConfiguration config) {
|
||||||
|
services.AddDirectoryBrowser();
|
||||||
bool SetBasePath(string? path) {
|
services.AddControllers();
|
||||||
if (!Directory.Exists(path)) {
|
services.AddEndpointsApiExplorer();
|
||||||
return false;
|
services.AddSwaggerGen();
|
||||||
}
|
services.AddMasterWorker(config.GetSection("MasterWorker"));
|
||||||
configBuilder.SetBasePath(path);
|
services.AddViewStreamDatabase(config.GetSection("ViewStreamDatabase"));
|
||||||
return true;
|
services.AddPubSubClient(config.GetSection("PubSub"));
|
||||||
}
|
services.AddPrimitiveManager();
|
||||||
|
services.AddSpark(config.GetSection("Spark"));
|
||||||
bool AddJsonFile(string? path) {
|
services.AddSparkd(config.GetSection("SparkdCredentials"));
|
||||||
if (!File.Exists(path)) {
|
services.AddHostedService<DataStreamWebAppService>();
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
configBuilder.AddJsonFile(path);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void ConfigureServices(IServiceCollection services, IConfiguration config) {
|
|
||||||
services.AddDirectoryBrowser()
|
|
||||||
.AddControllers().Services
|
|
||||||
.AddEndpointsApiExplorer()
|
|
||||||
.AddSwaggerGen();
|
|
||||||
services.AddSpaStaticFiles();
|
|
||||||
services.AddSpark(config.GetSection("Spark"))
|
|
||||||
.AddSparkApi(config.GetSection("SparkApi"))
|
|
||||||
.AddMasterWorker(config.GetSection("MasterWorker"))
|
|
||||||
.AddViewStreamDatabase()
|
|
||||||
.AddPubSubClient(config.GetSection("PubSub"));
|
|
||||||
}
|
|
||||||
@@ -6,9 +6,8 @@
|
|||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"launchUrl": "swagger",
|
"launchUrl": "swagger",
|
||||||
"applicationUrl": "http://localhost:8080",
|
"applicationUrl": "http://localhost:5000",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_HTTP_PORT": "8080",
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||||
}
|
}
|
||||||
@@ -17,10 +16,8 @@
|
|||||||
"commandName": "Project",
|
"commandName": "Project",
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"launchBrowser": true,
|
"launchBrowser": true,
|
||||||
"applicationUrl": "http://localhost:8080;https://localhost:8443",
|
"applicationUrl": "http://localhost:5000;https://localhost:5001",
|
||||||
"environmentVariables": {
|
"environmentVariables": {
|
||||||
"ASPNETCORE_HTTP_PORT": "8080",
|
|
||||||
"ASPNETCORE_HTTPS_PORT": "8443",
|
|
||||||
"ASPNETCORE_ENVIRONMENT": "Development",
|
"ASPNETCORE_ENVIRONMENT": "Development",
|
||||||
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy",
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
namespace Bts.DataStreamWebApp.Server.Services;
|
||||||
|
|
||||||
|
using BCG;
|
||||||
|
using BCG.Utilities.General;
|
||||||
|
|
||||||
|
using bts;
|
||||||
|
using bts.api.core;
|
||||||
|
|
||||||
|
using Bts.DataStreamExpressions;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// An IHostedService wrapper for ViewStream publishers. It provides a way for the Application to
|
||||||
|
/// start/stop the view publishers.
|
||||||
|
/// </summary>
|
||||||
|
class DataStreamWebAppService : IHostedService {
|
||||||
|
readonly DataStreamWebAppServerConfig config;
|
||||||
|
readonly ViewStreamDatabase vsd;
|
||||||
|
readonly TaskCompletionSource taskCompletionSource = new();
|
||||||
|
readonly CancellationTokenSource cancellationTokenSource = new();
|
||||||
|
|
||||||
|
public DataStreamWebAppService(
|
||||||
|
ViewStreamDatabase vsd,
|
||||||
|
IOptions<DataStreamWebAppServerConfig> config
|
||||||
|
) {
|
||||||
|
this.vsd = vsd;
|
||||||
|
this.config = config.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StartAsync(CancellationToken cancellationToken) {
|
||||||
|
// Task.Factory.StartNew(Run, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default);
|
||||||
|
return Task.CompletedTask;
|
||||||
|
|
||||||
|
// void Run() {
|
||||||
|
// Log.Gen.info("DataStreamWebAppService STARTED");
|
||||||
|
// var defaultWaitTime = TimeSpan.FromMilliseconds(100);
|
||||||
|
// var innerCancellationToken = cancellationTokenSource.Token;
|
||||||
|
// var psConfig = config.PubSub ?? throw new InvalidOperationException("PubSub config is null");
|
||||||
|
// while (!innerCancellationToken.IsCancellationRequested) {
|
||||||
|
// vsd.doWork();
|
||||||
|
// masterWorker.doWork();
|
||||||
|
// Thread.Sleep(defaultWaitTime);
|
||||||
|
// }
|
||||||
|
// Log.Gen.info("DataStreamWebAppService STOPPED");
|
||||||
|
// taskCompletionSource.SetResult();
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task StopAsync(CancellationToken cancellationToken) {
|
||||||
|
Log.Gen.info("Stopping DataStreamWebAppService");
|
||||||
|
cancellationTokenSource.Cancel();
|
||||||
|
return Task.CompletedTask;
|
||||||
|
// return taskCompletionSource.Task;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
{
|
|
||||||
"Kestrel": {
|
|
||||||
"Endpoints": {
|
|
||||||
"Http": {
|
|
||||||
"Url": "http://localhost:8080"
|
|
||||||
},
|
|
||||||
"Https": {
|
|
||||||
"Url": "https://localhost:8443"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"PubSub": {
|
|
||||||
"Routing": {
|
|
||||||
"PublisherRoutes": [
|
|
||||||
{
|
|
||||||
"Name": "default",
|
|
||||||
"ServerAddress": "bts-cloud://localhost:22019",
|
|
||||||
"TagRegExp": ".*"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"SubscriberRoutes": [
|
|
||||||
{
|
|
||||||
"Name": "default",
|
|
||||||
"ServerAddress": "bts-cloud://localhost:22019",
|
|
||||||
"TagRegExp": ".*"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"CannedQueries": [
|
|
||||||
{
|
|
||||||
"Name": "BBO",
|
|
||||||
"Query": [
|
|
||||||
"bbo"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Trades",
|
|
||||||
"Query": [
|
|
||||||
"timesales"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Instruments",
|
|
||||||
"Query": [
|
|
||||||
"instruments"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Books",
|
|
||||||
"Query": [
|
|
||||||
"books"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Benzinga News",
|
|
||||||
"Query": [
|
|
||||||
"benzinga_news"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
{
|
{
|
||||||
"Spark": {
|
"WebServer": {
|
||||||
"ConfigServer": "http://sparkd:8000/config"
|
"ContentRootPath": "build/Bts.DataStreamWebApp.Client/production",
|
||||||
},
|
"WebRootPath": "dist"
|
||||||
"SparkApi": {
|
|
||||||
"IsEnabled": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,115 +0,0 @@
|
|||||||
{
|
|
||||||
"MasterWorker": {
|
|
||||||
"Interval": "00:00:00.1"
|
|
||||||
},
|
|
||||||
"ViewStreamDatabase": {
|
|
||||||
"Interval": "00:00:00.1"
|
|
||||||
},
|
|
||||||
"Spark": {
|
|
||||||
"ConfigServer": "http://172.30.2.181:8000/config"
|
|
||||||
},
|
|
||||||
"SparkApi": {
|
|
||||||
"Credentials": {
|
|
||||||
"User": "bts",
|
|
||||||
"Password": ""
|
|
||||||
},
|
|
||||||
"EnableAdmin": true,
|
|
||||||
"EnableOrders": true,
|
|
||||||
"EnablePosition": true
|
|
||||||
},
|
|
||||||
"PubSub": {
|
|
||||||
"HeartbeatInterval": 15000,
|
|
||||||
"MissingHeartbeatsBeforeGc": 50,
|
|
||||||
"ServerPort": 22019,
|
|
||||||
"Routing": {
|
|
||||||
"PublisherRoutes": [
|
|
||||||
{
|
|
||||||
"Name": "default",
|
|
||||||
"ServerAddress": "bts-cloud://172.30.2.181:22019",
|
|
||||||
"TagRegExp": ".*"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"SubscriberRoutes": [
|
|
||||||
{
|
|
||||||
"Name": "default",
|
|
||||||
"ServerAddress": "bts-cloud://172.30.2.181:22019",
|
|
||||||
"TagRegExp": ".*"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"TagTypeToAssemblyMap": {
|
|
||||||
"Entries": [
|
|
||||||
{
|
|
||||||
"HandlerClass": "BCG.PubSubServerTagHandler",
|
|
||||||
"Assembly": "DataStreamCore.dll"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"TagHandlerFactory": {
|
|
||||||
"Handlers": [
|
|
||||||
{
|
|
||||||
"TagType": "DataStream",
|
|
||||||
"Assembly": "DataStreamCore",
|
|
||||||
"Class": "bts.PubsubServerStreamTagHandler"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"TagType": "System_Sub",
|
|
||||||
"Assembly": "PubSub",
|
|
||||||
"Class": "BCG.SystemSubscriptionMapPublisher"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"TagType": "System_Stats",
|
|
||||||
"Assembly": "PubSub",
|
|
||||||
"Class": "BCG.SystemStatsPublisher"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"TagType": ".*",
|
|
||||||
"Assembly": "DataStreamCore",
|
|
||||||
"Class": "bts.PubsubServerGenericDataHandler"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Kestrel": {
|
|
||||||
"Endpoints": {
|
|
||||||
"Http": {
|
|
||||||
"Url": "http://172.30.2.181:8080"
|
|
||||||
},
|
|
||||||
"Https": {
|
|
||||||
"Url": "https://172.30.2.181:8443"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"CannedQueries": [
|
|
||||||
{
|
|
||||||
"Name": "BBO",
|
|
||||||
"Query": [
|
|
||||||
"bbo"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Trades",
|
|
||||||
"Query": [
|
|
||||||
"timesales"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Instruments",
|
|
||||||
"Query": [
|
|
||||||
"instruments"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Books",
|
|
||||||
"Query": [
|
|
||||||
"books"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Benzinga News",
|
|
||||||
"Query": [
|
|
||||||
"benzinga_news"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
{
|
|
||||||
"CannedQueries": [
|
|
||||||
{
|
|
||||||
"Name": "BBO",
|
|
||||||
"Query": [
|
|
||||||
"bbo"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Trades",
|
|
||||||
"Query": [
|
|
||||||
"timesales"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Instruments",
|
|
||||||
"Query": [
|
|
||||||
"instruments"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Books",
|
|
||||||
"Query": [
|
|
||||||
"books"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"Name": "Benzinga News",
|
|
||||||
"Query": [
|
|
||||||
"benzinga_news"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@@ -6,80 +6,35 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"Kestrel": {
|
"Spark": {
|
||||||
"Endpoints": {
|
"ConfigServer": "http://localhost:8000/config"
|
||||||
"Http": {
|
},
|
||||||
"Url": "http://0.0.0.0:8080"
|
"SparkdCredentials": {
|
||||||
},
|
"User": "bts",
|
||||||
"Https": {
|
"Password": ""
|
||||||
"Url": "https://0.0.0.0:8443"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"MasterWorker": {
|
"MasterWorker": {
|
||||||
"Interval": "00:00:00.1"
|
"Interval": "00:00:00.1"
|
||||||
},
|
},
|
||||||
"ViewStreamDatabase": {
|
|
||||||
"Interval": "00:00:00.1"
|
|
||||||
},
|
|
||||||
"SparkApi": {
|
|
||||||
"IsEnabled": false,
|
|
||||||
"Credentials": {
|
|
||||||
"User": "bts",
|
|
||||||
"Password": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"PubSub": {
|
"PubSub": {
|
||||||
"HeartbeatInterval": 15000,
|
|
||||||
"MissingHeartbeatsBeforeGc": 50,
|
|
||||||
"ServerPort": 22019,
|
|
||||||
"Routing": {
|
"Routing": {
|
||||||
"PublisherRoutes": [
|
"PublisherRoutes": [
|
||||||
{
|
{
|
||||||
"Name": "default",
|
"Name": "default",
|
||||||
"ServerAddress": "bts-cloud://pubsub:22019",
|
"ServerAddress": "bts-cloud://127.0.0.1:12345",
|
||||||
"TagRegExp": ".*"
|
"TagRegExp": ".*"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"SubscriberRoutes": [
|
"SubscriberRoutes": [
|
||||||
{
|
{
|
||||||
"Name": "default",
|
"Name": "default",
|
||||||
"ServerAddress": "bts-cloud://pubsub:22019",
|
"ServerAddress": "bts-cloud://127.0.0.1:12345",
|
||||||
"TagRegExp": ".*"
|
"TagRegExp": ".*"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
"TagTypeToAssemblyMap": {
|
|
||||||
"Entries": [
|
|
||||||
{
|
|
||||||
"HandlerClass": "BCG.PubSubServerTagHandler",
|
|
||||||
"Assembly": "DataStreamCore.dll"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"TagHandlerFactory": {
|
|
||||||
"Handlers": [
|
|
||||||
{
|
|
||||||
"TagType": "DataStream",
|
|
||||||
"Assembly": "DataStreamCore",
|
|
||||||
"Class": "bts.PubsubServerStreamTagHandler"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"TagType": "System_Sub",
|
|
||||||
"Assembly": "PubSub",
|
|
||||||
"Class": "BCG.SystemSubscriptionMapPublisher"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"TagType": "System_Stats",
|
|
||||||
"Assembly": "PubSub",
|
|
||||||
"Class": "BCG.SystemStatsPublisher"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"TagType": ".*",
|
|
||||||
"Assembly": "DataStreamCore",
|
|
||||||
"Class": "bts.PubsubServerGenericDataHandler"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ViewStreamDatabase": {
|
||||||
|
"Interval": "00:00:01"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
FROM bluetradingsystems/linux_dotnet7
|
|
||||||
|
|
||||||
RUN dotnet dev-certs https --trust
|
|
||||||
COPY --chown=bts:bts "bin" "bin"
|
|
||||||
COPY --chown=bts:bts "webapp.spark.conf" ".local/share/DataStream/conf/spark.conf"
|
|
||||||
WORKDIR "/home/bts/bin"
|
|
||||||
@@ -1,15 +0,0 @@
|
|||||||
Logging {
|
|
||||||
value {
|
|
||||||
console {
|
|
||||||
default_level: "Info"
|
|
||||||
}
|
|
||||||
syslog {
|
|
||||||
default_level: "Info"
|
|
||||||
}
|
|
||||||
file {
|
|
||||||
default_level: "Info"
|
|
||||||
}
|
|
||||||
initial_queue_size: 120001
|
|
||||||
max_queue_growth: 4
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
<TargetFramework>net7.0</TargetFramework>
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
namespace Bts.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This interface provides a way to move dependencies outside of the constructor (and accept them
|
||||||
|
/// via <see cref="IDependOn{T}.Reset(T?)"/> instead). It was designed to resolve circular
|
||||||
|
/// dependency issues among startup services.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of dependency</typeparam>
|
||||||
|
public interface IDependOn<T> {
|
||||||
|
void Reset(T? value);
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
#nullable enable
|
||||||
|
namespace Bts.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
public interface IDependOnKeyed<T> : IDependOn<T> {
|
||||||
|
string Key { get; }
|
||||||
|
}
|
||||||
+130
@@ -0,0 +1,130 @@
|
|||||||
|
namespace Bts.Extensions.DependencyInjection;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
public static class ServiceCollectionExtensions {
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||||
|
/// already.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="services"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IServiceCollection EnsureSingleton<T>(this IServiceCollection services) where T : class =>
|
||||||
|
services.HasService<T>()
|
||||||
|
? services
|
||||||
|
: services.AddSingleton<T>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||||
|
/// already.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T"></typeparam>
|
||||||
|
/// <param name="services"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static IServiceCollection EnsureSingleton<T>(this IServiceCollection services, Func<IServiceProvider, T> implementationFactory) where T : class =>
|
||||||
|
services.HasService<T>()
|
||||||
|
? services
|
||||||
|
: services.AddSingleton(implementationFactory);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||||
|
/// already.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||||
|
/// <typeparam name="TImplementation">The type of the implementation to use.</typeparam>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||||
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
|
public static IServiceCollection EnsureSingleton<T, TImplementation>(this IServiceCollection services) where T : class where TImplementation : class, T =>
|
||||||
|
services.HasService<T>()
|
||||||
|
? services
|
||||||
|
: services.AddSingleton<T, TImplementation>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||||
|
/// already.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||||
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
|
public static IServiceCollection EnsureSingleton<T>(this IServiceCollection services, Func<IServiceProvider, object?, T> implementationFactory) where T : class =>
|
||||||
|
services.HasService<T>()
|
||||||
|
? services
|
||||||
|
: services.AddSingleton(implementationFactory);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||||
|
/// already.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||||
|
/// <typeparam name="TImplementation">The type of the implementation to use.</typeparam>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||||
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
|
public static IServiceCollection EnsureSingleton<T, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory) where T : class where TImplementation : class, T =>
|
||||||
|
services.HasService<T>()
|
||||||
|
? services
|
||||||
|
: services.AddSingleton(implementationFactory);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||||
|
/// already.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||||
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
|
public static IServiceCollection EnsureKeyedSingleton<T>(this IServiceCollection services, object? key) where T : class =>
|
||||||
|
services.HasKeyedService<T>(key)
|
||||||
|
? services
|
||||||
|
: services.AddKeyedSingleton<T>(key);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||||
|
/// already.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||||
|
/// <param name="implementationFactory">The factory that creates the service.</param>
|
||||||
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
|
public static IServiceCollection EnsureKeyedSingleton<T>(this IServiceCollection services, object? key, Func<IServiceProvider, object?, T> implementationFactory) where T : class =>
|
||||||
|
services.HasKeyedService<T>(key)
|
||||||
|
? services
|
||||||
|
: services.AddKeyedSingleton(key, implementationFactory);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||||
|
/// already.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||||
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
|
public static IServiceCollection EnsureHostedService<T>(this IServiceCollection services) where T : class, IHostedService =>
|
||||||
|
services.HasService<T>()
|
||||||
|
? services
|
||||||
|
: services.AddHostedService<T>();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds a singleton service only if a service of type <typeparamref name="T"/> hasn't been added
|
||||||
|
/// already.
|
||||||
|
/// </summary>
|
||||||
|
/// <typeparam name="T">The type of the service to add.</typeparam>
|
||||||
|
/// <param name="services">The <see cref="IServiceCollection"/> to add the service to.</param>
|
||||||
|
/// <param name="implementationFactory">The factory that creates the service.</param>
|
||||||
|
/// <returns>A reference to this instance after the operation has completed.</returns>
|
||||||
|
public static IServiceCollection EnsureHostedService<T>(this IServiceCollection services, Func<IServiceProvider, T> implementationFactory) where T : class, IHostedService =>
|
||||||
|
services.HasService<T>()
|
||||||
|
? services
|
||||||
|
: services.AddHostedService(implementationFactory);
|
||||||
|
|
||||||
|
public static bool HasService<T>(this IServiceCollection services) =>
|
||||||
|
services.Any(s => s.ServiceType.IsAssignableTo(typeof(T)));
|
||||||
|
|
||||||
|
public static bool HasServiceImplementation<T, TImplementation>(this IServiceCollection services) =>
|
||||||
|
services.Any(s => s.ServiceType.IsAssignableTo(typeof(T)) && s.ImplementationType == typeof(TImplementation));
|
||||||
|
|
||||||
|
public static bool HasKeyedService<T>(this IServiceCollection services, object? key) =>
|
||||||
|
services.Any(s => Equals(s.ServiceKey, key) && s.ServiceType.IsAssignableTo(typeof(T)));
|
||||||
|
}
|
||||||
@@ -1,59 +0,0 @@
|
|||||||
namespace Bts.Extensions.Hosting;
|
|
||||||
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
public static class HostBuilderExtensions {
|
|
||||||
public static IHostBuilder CreateBtsBuilder(string[] args) {
|
|
||||||
// Obtain calling assembly name here, rather than in the lambda where it is actually needed,
|
|
||||||
// because want the name of the assembly that called this function, not the assembly that will eventually invoke
|
|
||||||
// the lambda...that will be the Microsoft.Extensions.Hosting assembly.
|
|
||||||
// Get the name of the assembly that called this function. That will act as the "appsettings"
|
|
||||||
// json file prefix
|
|
||||||
var exeName = GetCallingAssemblyName();
|
|
||||||
return Host.CreateDefaultBuilder(args)
|
|
||||||
.ConfigureAppConfiguration((context, configBuilder) =>
|
|
||||||
ConfigureApp(configBuilder, context.HostingEnvironment.EnvironmentName, exeName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ConfigureApp(IConfigurationBuilder configBuilder, string? environment = null, string? prefix = null) {
|
|
||||||
var baseFileName = prefix is null ? "appsettings" : $"{prefix}.appsettings";
|
|
||||||
AddJsonFile($"{baseFileName}.json");
|
|
||||||
if (environment is not null) {
|
|
||||||
AddJsonFile($"{baseFileName}.{environment}.json");
|
|
||||||
}
|
|
||||||
|
|
||||||
var cfg = configBuilder.Build().GetSection("config")?.Value;
|
|
||||||
if (!SetBasePath(cfg)) {
|
|
||||||
AddJsonFile(cfg);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool SetBasePath(string? path) {
|
|
||||||
if (!Directory.Exists(path)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
configBuilder.SetBasePath(path);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AddJsonFile(string? path) {
|
|
||||||
if (!File.Exists(path)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
configBuilder.AddJsonFile(path);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static string GetCallingAssemblyName() =>
|
|
||||||
new StackTrace()
|
|
||||||
.GetFrame(2)
|
|
||||||
?.GetMethod()
|
|
||||||
?.Module
|
|
||||||
?.Assembly
|
|
||||||
?.GetName()
|
|
||||||
?.Name
|
|
||||||
?? throw new InvalidOperationException("Failed to determine name of calling assembly (calling method is null)");
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net7.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
namespace Bts.Net;
|
|
||||||
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Provides facilities to compare hosts for equality.
|
|
||||||
/// <para>
|
|
||||||
/// This class doesn't implement IEqualityComparer because a consistent hash code cannot be
|
|
||||||
/// guarenteed for equivalent host strings. The equals impl relies on Dns.GetHostAddresses, which
|
|
||||||
/// is non-determinstic (implementations that depends on mutable properties face a similar problem).
|
|
||||||
/// </para>
|
|
||||||
/// </summary>
|
|
||||||
public class HostComparer {
|
|
||||||
public static bool Equals(string? x, string? y) {
|
|
||||||
if (x is null) {
|
|
||||||
return y is null;
|
|
||||||
}
|
|
||||||
if (y is null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return Dns.GetHostAddresses(x).Intersect(
|
|
||||||
Dns.GetHostAddresses(y), IpAddressComparer.Instance).Any();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static bool Equals(IPHostEntry x, IPHostEntry y) =>
|
|
||||||
x.AddressList.Intersect(y.AddressList, IpAddressComparer.Instance).Any();
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
namespace Bts.Net;
|
|
||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Net;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Compares ip addresses. Unlike the default comparer, v4 and equivalent v6 addresses are
|
|
||||||
/// considered equal.
|
|
||||||
/// </summary>
|
|
||||||
public class IpAddressComparer : IEqualityComparer<IPAddress> {
|
|
||||||
public static IEqualityComparer<IPAddress> Instance { get; } = new IpAddressComparer();
|
|
||||||
|
|
||||||
public bool Equals(IPAddress? x, IPAddress? y) {
|
|
||||||
if (x is null) {
|
|
||||||
return y is null;
|
|
||||||
}
|
|
||||||
if (y is null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return x.Equals(y) ||
|
|
||||||
(x.IsIPv4MappedToIPv6 && x.MapToIPv4().Equals(y)) ||
|
|
||||||
(y.IsIPv4MappedToIPv6 && y.MapToIPv4().Equals(x));
|
|
||||||
}
|
|
||||||
|
|
||||||
public int GetHashCode([DisallowNull] IPAddress address) =>
|
|
||||||
address.IsIPv4MappedToIPv6
|
|
||||||
// Return consistent hash code for v4 and equivalent v6
|
|
||||||
? address.MapToIPv4().GetHashCode()
|
|
||||||
: address.GetHashCode();
|
|
||||||
}
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
namespace Bts.Net;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
public class IpHostEntryJsonConverter : JsonConverter<IPHostEntry> {
|
|
||||||
public override IPHostEntry? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) {
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Write(Utf8JsonWriter writer, IPHostEntry value, JsonSerializerOptions options) {
|
|
||||||
writer.WriteStartObject();
|
|
||||||
// HostName
|
|
||||||
writer.WriteString(nameof(value.HostName), value.HostName);
|
|
||||||
// Aliases
|
|
||||||
writer.WritePropertyName("Aliases");
|
|
||||||
writer.WriteStartArray();
|
|
||||||
foreach (var alias in value.Aliases) {
|
|
||||||
writer.WriteStringValue(alias);
|
|
||||||
}
|
|
||||||
writer.WriteEndArray();
|
|
||||||
// Addresses
|
|
||||||
writer.WritePropertyName("Addresses");
|
|
||||||
writer.WriteStartArray();
|
|
||||||
foreach (var address in value.AddressList) {
|
|
||||||
writer.WriteStringValue(address.ToString());
|
|
||||||
}
|
|
||||||
writer.WriteEndArray();
|
|
||||||
writer.WriteEndObject();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
namespace Bts.Net;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.IO;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Json;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This class seriailzes IpHostEntry to json (string). A common buffer is used to reduce memory
|
|
||||||
/// allocations on repeated calls to <see cref="Serialize"/>. For that reason, this class is NOT
|
|
||||||
/// thread safe.
|
|
||||||
/// </summary>
|
|
||||||
public class IpHostEntryJsonSerializer {
|
|
||||||
readonly MemoryStream buffer = new();
|
|
||||||
readonly IpHostEntryJsonConverter converter;
|
|
||||||
|
|
||||||
public IpHostEntryJsonSerializer(IpHostEntryJsonConverter? converter = null) =>
|
|
||||||
this.converter = converter ?? new() { };
|
|
||||||
|
|
||||||
public string? Serialize(IPHostEntry dp, JsonSerializerOptions? opts = null) {
|
|
||||||
opts ??= JsonSerializerOptions.Default;
|
|
||||||
buffer.Position = 0;
|
|
||||||
buffer.SetLength(0);
|
|
||||||
using (var jsonWriter = new Utf8JsonWriter(buffer)) {
|
|
||||||
converter.Write(jsonWriter, dp, opts);
|
|
||||||
}
|
|
||||||
var bytes = buffer.GetBuffer();
|
|
||||||
var span = new ArraySegment<byte>(bytes, 0, (int)buffer.Length);
|
|
||||||
return Encoding.UTF8.GetString(span);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Serialize(IPHostEntry dp, Utf8JsonWriter jsonWriter, JsonSerializerOptions? opts = null) {
|
|
||||||
opts ??= JsonSerializerOptions.Default;
|
|
||||||
buffer.Position = 0;
|
|
||||||
buffer.SetLength(0);
|
|
||||||
converter.Write(jsonWriter, dp, opts);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
namespace Bts.Net;
|
|
||||||
|
|
||||||
using System.Diagnostics.CodeAnalysis;
|
|
||||||
using System.Net;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
|
|
||||||
public static partial class IpUtils {
|
|
||||||
static readonly Regex ipv4Regex = new(string.Join('.', @"(((0|1)\d)|(2\d)|\d)?\d"));
|
|
||||||
|
|
||||||
// public static void ParseUri(string str, out string? scheme, out string? host, out string? port, out string? path, out string? queryParams) {
|
|
||||||
// if (Uri.TryCreate(str, UriKind.Absolute, out var uri)) {
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static bool AreEndpointsEqual(Uri? x, Uri? y) {
|
|
||||||
// if (x is null) {
|
|
||||||
// return y is null;
|
|
||||||
// }
|
|
||||||
// if (y is null) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// if (x.IsAbsoluteUri != y.IsAbsoluteUri) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// if (x.IsAbsoluteUri) {
|
|
||||||
// if (x.Scheme != y.Scheme) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// string? xHost = null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// static string ResolveHostIpv4(Uri uri) {
|
|
||||||
// // switch (uri.HostNameType) {
|
|
||||||
// // case UriHostNameType.IPv4:
|
|
||||||
// // return uri.Host;
|
|
||||||
// // case UriHostNameType.Dns:
|
|
||||||
// // break;
|
|
||||||
// // case UriHostNameType.IPv6:
|
|
||||||
// // var addresses = Dns.GetHostAddresses(uri.Host);
|
|
||||||
// // foreach (var address in addresses) {
|
|
||||||
// // if (address.IsIPv4MappedToIPv6) {
|
|
||||||
// // return address.MapToIPv4().Address;
|
|
||||||
// // }
|
|
||||||
// // }
|
|
||||||
// // break;
|
|
||||||
// // }
|
|
||||||
// var hostAddresses = Dns.GetHostAddresses(uri.Host);
|
|
||||||
// foreach (IPAddress address in hostAddresses) {
|
|
||||||
// if (address.Equals(remoteEndPoint.Address) ||
|
|
||||||
// (address.IsIPv4MappedToIPv6 && address.MapToIPv4().Equals(remoteEndPoint.Address)) ||
|
|
||||||
// (remoteEndPoint.Address.IsIPv4MappedToIPv6 && remoteEndPoint.Address.MapToIPv4().Equals(address))) {
|
|
||||||
// isMatch = true;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public static bool AreEndpointsEqual(string? x, string? y) {
|
|
||||||
// if (x == y) {
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// if (x is null) {
|
|
||||||
// return y is null;
|
|
||||||
// }
|
|
||||||
// if (y is null) {
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// var xUri = new Uri(x);
|
|
||||||
// var yUri = new Uri(y);
|
|
||||||
// // return xUri.Equals(yUri);
|
|
||||||
// }
|
|
||||||
|
|
||||||
public static bool IsIpv4(string host) {
|
|
||||||
host = removeSchemaFromUrl(host);
|
|
||||||
host = removePortFromUrl(host);
|
|
||||||
return ipv4Regex.IsMatch(host);
|
|
||||||
}
|
|
||||||
|
|
||||||
static string removeSchemaFromUrl(string url) {
|
|
||||||
var i = url.IndexOf("://");
|
|
||||||
return i < 0 ? url : url.Substring(i + 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
static string removePortFromUrl(string url) {
|
|
||||||
var match = MyRegex().Match(url);
|
|
||||||
return match.Success
|
|
||||||
? string.Concat(url.AsSpan(0, match.Index), url.AsSpan(match.Index + match.Length))
|
|
||||||
: url;
|
|
||||||
}
|
|
||||||
|
|
||||||
[GeneratedRegex(":\\d{1,4}")]
|
|
||||||
private static partial Regex MyRegex();
|
|
||||||
}
|
|
||||||
@@ -7,11 +7,14 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Google.Protobuf" Version="3.24.3" />
|
||||||
<PackageReference Include="YaccLexTools" Version="1.2.2" />
|
<PackageReference Include="YaccLexTools" Version="1.2.2" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\DataStreamCore\DataStreamCore.csproj" />
|
||||||
<ProjectReference Include="..\ExpressionCore\ExpressionCore.csproj" />
|
<ProjectReference Include="..\ExpressionCore\ExpressionCore.csproj" />
|
||||||
|
<ProjectReference Include="..\..\client\spark_core\spark_core.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Label="ColumnMapExpression">
|
<ItemGroup Label="ColumnMapExpression">
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
<ProjectReference Include="..\DataStreamCore\DataStreamCore.csproj" />
|
<ProjectReference Include="..\DataStreamCore\DataStreamCore.csproj" />
|
||||||
<ProjectReference Include="..\DataStreamExpressions\DataStreamExpressions.csproj" />
|
<ProjectReference Include="..\DataStreamExpressions\DataStreamExpressions.csproj" />
|
||||||
<ProjectReference Include="..\..\client\spark_core\spark_core.csproj" />
|
<ProjectReference Include="..\..\client\spark_core\spark_core.csproj" />
|
||||||
|
<ProjectReference Include="..\Bts.Extensions.DependencyInjection\Bts.Extensions.DependencyInjection.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
namespace Bts.DataStream;
|
||||||
|
|
||||||
|
using BCG;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
public class BoundImportAttribute {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class DataStreamActivator {
|
||||||
|
Dictionary<string, Type> myTypeLookupTable = new();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructs and returns a ViewStream of type corresponding to the friendly name
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="friendlyName">friendly primitive name </param>
|
||||||
|
/// <param name="args">args can be null or an empty ICollection if the paramterless constructor
|
||||||
|
/// is the desired one</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public ViewStream Activate(string friendlyName, IList<object>? args) {
|
||||||
|
object[]? constructorArgs = null;
|
||||||
|
if (args != null && args.Count > 0) {
|
||||||
|
constructorArgs = new object[args.Count];
|
||||||
|
args.CopyTo(constructorArgs, 0);
|
||||||
|
}
|
||||||
|
if (!myTypeLookupTable.TryGetValue(friendlyName, out var type)) {
|
||||||
|
throw new ApplicationException(friendlyName + " is not the friendly name of any of the loaded types");
|
||||||
|
}
|
||||||
|
return constructorArgs is null ?
|
||||||
|
Activator.CreateInstance(myTypeLookupTable[friendlyName] as Type) as ViewStream :
|
||||||
|
Activator.CreateInstance(myTypeLookupTable[friendlyName] as Type, constructorArgs) as ViewStream;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace Bts.DataStream;
|
||||||
|
|
||||||
|
using BCG;
|
||||||
|
|
||||||
|
public interface IViewStreamFactory {
|
||||||
|
public ViewStream? Create();
|
||||||
|
}
|
||||||
@@ -11,11 +11,8 @@ public class PandasScriptStream : ViewStream {
|
|||||||
public PandasScriptStream(ViewStream vs, string file)
|
public PandasScriptStream(ViewStream vs, string file)
|
||||||
: this(vs, file, null) { }
|
: this(vs, file, null) { }
|
||||||
|
|
||||||
public PandasScriptStream(ViewStream vs, string file, string? pythonExe)
|
public PandasScriptStream(ViewStream vs, string file, string? pythonExe) {
|
||||||
: this(vs, file, pythonExe, ViewStreamDatabase.instance) { }
|
mySetRealSource(AttachStream<PandasStream>(new(vs, readFile(), pythonExe)));
|
||||||
|
|
||||||
public PandasScriptStream(ViewStream vs, string file, string? pythonExe, ViewStreamDatabase vsd) {
|
|
||||||
mySetRealSource(new PandasStream(vs, readFile(), pythonExe, vsd));
|
|
||||||
|
|
||||||
string readFile() {
|
string readFile() {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
namespace Bts.DataStream;
|
namespace Bts.DataStream;
|
||||||
|
|
||||||
using BCG;
|
using BCG;
|
||||||
using BCG.Extensions;
|
|
||||||
using BCG.Utilities.General;
|
using BCG.Utilities.General;
|
||||||
|
|
||||||
using bts;
|
using bts;
|
||||||
@@ -23,7 +22,6 @@ public class PandasStream : ViewStream, IWorker {
|
|||||||
readonly string inputFile = $"PandasStream_{Guid.NewGuid()}.csv";
|
readonly string inputFile = $"PandasStream_{Guid.NewGuid()}.csv";
|
||||||
readonly string outputFile = $"PandasStream_{Guid.NewGuid()}.csv";
|
readonly string outputFile = $"PandasStream_{Guid.NewGuid()}.csv";
|
||||||
readonly string pythonExe;
|
readonly string pythonExe;
|
||||||
readonly ViewStreamDatabase vsd;
|
|
||||||
readonly CSVSaverStream inputCsvStream;
|
readonly CSVSaverStream inputCsvStream;
|
||||||
readonly Lazy<string> pythonCode;
|
readonly Lazy<string> pythonCode;
|
||||||
IDictionary<int, IBlueRow>? lastRowMap = null;
|
IDictionary<int, IBlueRow>? lastRowMap = null;
|
||||||
@@ -34,12 +32,11 @@ public class PandasStream : ViewStream, IWorker {
|
|||||||
IDisposable? dispose;
|
IDisposable? dispose;
|
||||||
|
|
||||||
public PandasStream(ViewStream vs, string dataFrameExpression)
|
public PandasStream(ViewStream vs, string dataFrameExpression)
|
||||||
: this(vs, dataFrameExpression, null, ViewStreamDatabase.instance) { }
|
: this(vs, dataFrameExpression, null) { }
|
||||||
|
|
||||||
public PandasStream(ViewStream vs, string dataFrameExpression, string? pythonExe, ViewStreamDatabase vsd) {
|
public PandasStream(ViewStream vs, string dataFrameExpression, string? pythonExe) {
|
||||||
pythonExe ??= Environment.GetEnvironmentVariable("PYTHON_EXE") ?? @"C:\Users\johnc\GoogleDrive\Repos\bts\spark\.venv\Scripts\python.exe";
|
pythonExe ??= Environment.GetEnvironmentVariable("PYTHON_EXE") ?? @"C:\Users\johnc\GoogleDrive\Repos\bts\spark\.venv\Scripts\python.exe";
|
||||||
this.pythonExe = pythonExe;
|
this.pythonExe = pythonExe;
|
||||||
this.vsd = vsd;
|
|
||||||
// This should fire an update when it writes to the output file
|
// This should fire an update when it writes to the output file
|
||||||
inputCsvStream = new CSVSaverStream(vs, inputFile, true, int.MaxValue, true);
|
inputCsvStream = new CSVSaverStream(vs, inputFile, true, int.MaxValue, true);
|
||||||
pythonCode = new(getPythonCode);
|
pythonCode = new(getPythonCode);
|
||||||
@@ -59,7 +56,7 @@ import sys
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override void myOnFirstSubscriber() {
|
protected override void myOnFirstSubscriber() {
|
||||||
vsd.addWorker(this);
|
base.myOnFirstSubscriber();
|
||||||
inputCsvStream.onChange += onInputChanged;
|
inputCsvStream.onChange += onInputChanged;
|
||||||
this.dispose = Disposable.Create(dispose);
|
this.dispose = Disposable.Create(dispose);
|
||||||
|
|
||||||
@@ -68,7 +65,6 @@ import sys
|
|||||||
|
|
||||||
void dispose() {
|
void dispose() {
|
||||||
inputCsvStream.onChange -= onInputChanged;
|
inputCsvStream.onChange -= onInputChanged;
|
||||||
vsd.removeWorker(this);
|
|
||||||
deleteFile(inputFile);
|
deleteFile(inputFile);
|
||||||
deleteFile(outputFile);
|
deleteFile(outputFile);
|
||||||
}
|
}
|
||||||
@@ -85,8 +81,10 @@ import sys
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void myOnLastSubscriber() =>
|
protected override void myOnLastSubscriber() {
|
||||||
|
base.myOnLastSubscriber();
|
||||||
Disposable.dispose(ref dispose);
|
Disposable.dispose(ref dispose);
|
||||||
|
}
|
||||||
|
|
||||||
static void executePythonCode(string pythonCode, string? pythonExe = null) {
|
static void executePythonCode(string pythonCode, string? pythonExe = null) {
|
||||||
pythonExe ??= "python";
|
pythonExe ??= "python";
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ namespace BCG {
|
|||||||
}
|
}
|
||||||
private readonly string _ip;
|
private readonly string _ip;
|
||||||
private readonly int _port;
|
private readonly int _port;
|
||||||
private readonly ViewStreamDatabase _vsd;
|
|
||||||
State _state = new State();
|
State _state = new State();
|
||||||
private readonly int _msg_size;
|
private readonly int _msg_size;
|
||||||
|
|
||||||
@@ -19,13 +18,10 @@ namespace BCG {
|
|||||||
private ITCPConnection _connection = null;
|
private ITCPConnection _connection = null;
|
||||||
private byte[] _buff;
|
private byte[] _buff;
|
||||||
|
|
||||||
public TCPConnectionTestStream(string ip, int port, int msg_size, int send_period_seconds) :
|
public TCPConnectionTestStream(string ip, int port, int msg_size, int send_period_seconds) {
|
||||||
this(ip, port, msg_size, send_period_seconds, ViewStreamDatabase.instance) { }
|
|
||||||
public TCPConnectionTestStream(string ip, int port, int msg_size, int send_period_seconds, ViewStreamDatabase vsd) {
|
|
||||||
_ip = ip;
|
_ip = ip;
|
||||||
_port = port;
|
_port = port;
|
||||||
_msg_size = msg_size;
|
_msg_size = msg_size;
|
||||||
_vsd = vsd;
|
|
||||||
_schema = BlueDataUtility.form_schema("TCPClient",
|
_schema = BlueDataUtility.form_schema("TCPClient",
|
||||||
Tuple.Create("id", TypeCode.Int32),
|
Tuple.Create("id", TypeCode.Int32),
|
||||||
Tuple.Create("n_sends", TypeCode.UInt32),
|
Tuple.Create("n_sends", TypeCode.UInt32),
|
||||||
@@ -76,4 +72,4 @@ namespace BCG {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+37
-52
@@ -1,24 +1,15 @@
|
|||||||
using Bts.DataStream;
|
|
||||||
using Bts.DataStreamCore;
|
|
||||||
using Bts.DataStreamExpressions;
|
|
||||||
using Bts.PubSub;
|
|
||||||
|
|
||||||
using bts;
|
|
||||||
|
|
||||||
using Microsoft.Extensions.Hosting;
|
|
||||||
|
|
||||||
using Spark.Core.Disposables;
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Reactive.Linq;
|
|
||||||
using System.Threading;
|
using Bts.DataStreamExpressions;
|
||||||
using System.Threading.Tasks;
|
using bts;
|
||||||
|
using Bts.DataStreamCore;
|
||||||
|
using Bts.PubSub;
|
||||||
|
|
||||||
namespace BCG {
|
namespace BCG {
|
||||||
// listens to the requests posted on "cloud_streams" request table, and
|
// listens to the requests posted on "cloud_streams" request table, and
|
||||||
// if unfulfilled starts a ViewPubsliher
|
// if unfulfilled starts a ViewPubsliher
|
||||||
public class RemoteQueryManager : IHostedService {
|
public class RemoteQueryManager : IParameterizedWorker {
|
||||||
public class StreamPubUnit {
|
public class StreamPubUnit {
|
||||||
public string name;
|
public string name;
|
||||||
public string stream_expression;
|
public string stream_expression;
|
||||||
@@ -34,12 +25,13 @@ namespace BCG {
|
|||||||
view_publisher = view_publisher_;
|
view_publisher = view_publisher_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static ViewStream? build_stream(string stream_expression)
|
static ViewStream? build_stream(string stream_expression, PrimitiveManager primitiveManager, IServiceProvider serviceProvider)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var exp = DataStreamExpressionsInterpreter.Evaluate(stream_expression);
|
var exp = DataStreamExpressionsInterpreter.Evaluate(stream_expression);
|
||||||
var rv = exp.getView(new Dictionary<string, StatementExpression>(0));
|
var rv = exp.getView(new Dictionary<string, StatementExpression>(0), primitiveManager);
|
||||||
|
rv?.Reset(serviceProvider);
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
@@ -49,46 +41,31 @@ namespace BCG {
|
|||||||
}
|
}
|
||||||
private IDictionary<string, StreamPubUnit>
|
private IDictionary<string, StreamPubUnit>
|
||||||
_stream_pub_map = new Dictionary<string, StreamPubUnit>();
|
_stream_pub_map = new Dictionary<string, StreamPubUnit>();
|
||||||
|
private ViewStream _stream = new TableStream("cloud_streams");
|
||||||
readonly IPubTableBroker _broker;
|
readonly IPubTableBroker _broker;
|
||||||
readonly IManagedSubscriber _sub;
|
private readonly ManagedSubscriber _sub;
|
||||||
readonly object syncRoot = new();
|
readonly PrimitiveManager primitiveManager;
|
||||||
IDisposable? cloudStreamsSub;
|
readonly IServiceProvider serviceProvider;
|
||||||
IDisposable? remoteRequestsSub;
|
|
||||||
bool isDisposed;
|
|
||||||
|
|
||||||
|
public RemoteQueryManager(ManagedSubscriber sub, IPubTableBroker broker, PrimitiveManager primitiveManager, IServiceProvider serviceProvider) {
|
||||||
public RemoteQueryManager(IManagedSubscriber managedSubscriber, IPubTableBroker pubTableBroker) {
|
_sub = sub;
|
||||||
_sub = managedSubscriber;
|
_broker = broker;
|
||||||
_broker = pubTableBroker;
|
this.primitiveManager = primitiveManager;
|
||||||
|
this.serviceProvider = serviceProvider;
|
||||||
|
_stream.onChange += _on_str;
|
||||||
|
_sub.subscribe("RemoteRequest", (string tag, byte[] data) => {
|
||||||
|
RemoteRequest req = RemoteRequest.construct_from_bytes(data);
|
||||||
|
_spawn_remote_stream(req.published_table_name, req.stream_expression, false);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task StartAsync(CancellationToken cancellationToken) {
|
TimeSpan IParameterizedWorker.Interval => TimeSpan.FromSeconds(1);
|
||||||
lock (syncRoot) {
|
|
||||||
Log.assert(!isDisposed);
|
|
||||||
Log.isnull(cloudStreamsSub);
|
|
||||||
Log.isnull(remoteRequestsSub);
|
|
||||||
cloudStreamsSub = new TableStream("cloud_streams").AsObservable().Subscribe(_on_str);
|
|
||||||
remoteRequestsSub = _sub.Observe("RemoteRequest").Subscribe(data => {
|
|
||||||
RemoteRequest req = RemoteRequest.construct_from_bytes(data);
|
|
||||||
_spawn_remote_stream(req.published_table_name, req.stream_expression, false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task StopAsync(CancellationToken cancellationToken) {
|
private void _on_str(object obj)
|
||||||
lock (syncRoot) {
|
|
||||||
if (!isDisposed) {
|
|
||||||
isDisposed = true;
|
|
||||||
Disposable.dispose(ref cloudStreamsSub);
|
|
||||||
Disposable.dispose(ref remoteRequestsSub);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void _on_str(DataPacket dp)
|
|
||||||
{
|
{
|
||||||
|
if (obj is not DataPacket dp) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
foreach (IBlueRow r in dp.newRows)
|
foreach (IBlueRow r in dp.newRows)
|
||||||
{
|
{
|
||||||
string name = r.get<string>("name");
|
string name = r.get<string>("name");
|
||||||
@@ -102,7 +79,11 @@ namespace BCG {
|
|||||||
|
|
||||||
private void _spawn_remote_stream(string name, string stream_expression, bool persist) {
|
private void _spawn_remote_stream(string name, string stream_expression, bool persist) {
|
||||||
bts.Log.Gen.info($"CloudStreamManager.assign name: {name} stream_expression: {stream_expression}");
|
bts.Log.Gen.info($"CloudStreamManager.assign name: {name} stream_expression: {stream_expression}");
|
||||||
ViewStream stream = build_stream(stream_expression);
|
var stream = build_stream(stream_expression, primitiveManager, serviceProvider);
|
||||||
|
if (stream is null) {
|
||||||
|
Log.Gen.error($"Failed to spawn remote stream. stream_expression: {stream_expression}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
_expose_to_ws(name, stream);
|
_expose_to_ws(name, stream);
|
||||||
if (persist) {
|
if (persist) {
|
||||||
stream = new PersistorStream(stream, name, "C:\\Temp\\", 1000000); // 10MBs
|
stream = new PersistorStream(stream, name, "C:\\Temp\\", 1000000); // 10MBs
|
||||||
@@ -115,5 +96,9 @@ namespace BCG {
|
|||||||
private void _expose_to_ws(string name, ViewStream stream) {
|
private void _expose_to_ws(string name, ViewStream stream) {
|
||||||
// TODO: john
|
// TODO: john
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void doWork() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using BCG;
|
|
||||||
|
|
||||||
using bts;
|
using bts;
|
||||||
|
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace BCG {
|
namespace BCG {
|
||||||
@@ -9,7 +9,7 @@ namespace BCG {
|
|||||||
[DataStreamUserRespresentation("remoteQuery")]
|
[DataStreamUserRespresentation("remoteQuery")]
|
||||||
public class RemoteQueryStream : ViewStream {
|
public class RemoteQueryStream : ViewStream {
|
||||||
private readonly string _name, _stream_exp;
|
private readonly string _name, _stream_exp;
|
||||||
private PublisherCore _publisher_core = new PublisherCore();
|
IPublisherCore? _publisher_core_backing;
|
||||||
private ViewStream _source_str;
|
private ViewStream _source_str;
|
||||||
|
|
||||||
public RemoteQueryStream(params string[] lines) {
|
public RemoteQueryStream(params string[] lines) {
|
||||||
@@ -20,7 +20,14 @@ namespace BCG {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IPublisherCore? _publisher_core =>
|
||||||
|
_publisher_core_backing ??= ServiceProvider?.GetService<IPublisherCore>();
|
||||||
|
|
||||||
protected override void myOnFirstSubscriber() {
|
protected override void myOnFirstSubscriber() {
|
||||||
|
if (_publisher_core is null) {
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Unable to initialize PublisherStream because PublisherCore is null");
|
||||||
|
}
|
||||||
RemoteRequest rem_req = new RemoteRequest(_stream_exp, _name);
|
RemoteRequest rem_req = new RemoteRequest(_stream_exp, _name);
|
||||||
byte[] rem_req_bytes = rem_req.serialize();
|
byte[] rem_req_bytes = rem_req.serialize();
|
||||||
_publisher_core.publish("System", "RemoteRequest", rem_req_bytes);
|
_publisher_core.publish("System", "RemoteRequest", rem_req_bytes);
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace BCG {
|
|||||||
|
|
||||||
public AddColumnsStream(ViewStream vs, string col_def) {
|
public AddColumnsStream(ViewStream vs, string col_def) {
|
||||||
_new_col = parse_exp(col_def);
|
_new_col = parse_exp(col_def);
|
||||||
ViewStream rs = new MapStream(vs, (IBlueTableSchema s) => _get_schema(s), (IBlueRow r) => _map(r));
|
ViewStream rs = AttachStream(new MapStream(vs, _get_schema, _map));
|
||||||
mySetRealSource(rs);
|
mySetRealSource(rs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-5
@@ -91,10 +91,14 @@ namespace BCG
|
|||||||
}
|
}
|
||||||
_increment_values = increment_values_del;
|
_increment_values = increment_values_del;
|
||||||
_get_column_prefix = get_column_prefix_del;
|
_get_column_prefix = get_column_prefix_del;
|
||||||
if(only_fire_once)
|
if(only_fire_once) {
|
||||||
mySetRealSource(new NonIncGroupByStream(new OnlyFireOnceStream(stream), this));
|
ViewStream vs = AttachStream(new OnlyFireOnceStream(stream));
|
||||||
else
|
vs = AttachStream(new NonIncGroupByStream(vs, this));
|
||||||
mySetRealSource(new NonIncGroupByStream(stream, this));
|
mySetRealSource(vs);
|
||||||
|
} else {
|
||||||
|
ViewStream vs = AttachStream(new NonIncGroupByStream(stream, this));
|
||||||
|
mySetRealSource(vs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void _set_schema(List<string> tc_prefixes, Pair<string, Type>[] group_by_col_info, string table_name)
|
private void _set_schema(List<string> tc_prefixes, Pair<string, Type>[] group_by_col_info, string table_name)
|
||||||
@@ -241,4 +245,4 @@ namespace BCG
|
|||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@ namespace BCG
|
|||||||
public CaseChangeStream(ViewStream input, bool toUpper, params string[] columnsToChangeCase)
|
public CaseChangeStream(ViewStream input, bool toUpper, params string[] columnsToChangeCase)
|
||||||
{
|
{
|
||||||
myCaseChangingColumns = columnsToChangeCase;
|
myCaseChangingColumns = columnsToChangeCase;
|
||||||
mySetRealSource(new SuperMapStream(input, this));
|
mySetRealSource(AttachStream(new SuperMapStream(input, this)));
|
||||||
myIsUpperCase = toUpper;
|
myIsUpperCase = toUpper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -32,10 +32,10 @@ namespace BCG
|
|||||||
|
|
||||||
{
|
{
|
||||||
mySetRealSource (
|
mySetRealSource (
|
||||||
new MapStream (sourceStream,
|
AttachStream(new MapStream (sourceStream,
|
||||||
isConcatenatedDataConfined ? new ConcatenateColumnsMapperForSameDataSet (columnDefs) :
|
isConcatenatedDataConfined ? new ConcatenateColumnsMapperForSameDataSet (columnDefs) :
|
||||||
new ConcatenateColumnsMapper (columnDefs)
|
new ConcatenateColumnsMapper (columnDefs)
|
||||||
)
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace BCG
|
|||||||
public AverageCollectorStream(ViewStream stream, params string[] columnsToAverage)
|
public AverageCollectorStream(ViewStream stream, params string[] columnsToAverage)
|
||||||
{
|
{
|
||||||
myAveragingColumns = columnsToAverage;
|
myAveragingColumns = columnsToAverage;
|
||||||
mySetRealSource(new CrushingCollectorStream(stream, this));
|
mySetRealSource(AttachStream(new CrushingCollectorStream(stream, this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
private string[] myAveragingColumns;
|
private string[] myAveragingColumns;
|
||||||
|
|||||||
@@ -1,24 +1,23 @@
|
|||||||
using bts;
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
|
|
||||||
namespace BCG {
|
namespace BCG
|
||||||
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Provides a stream that with distinct rows with respect to the columns
|
/// Provides a stream that with distinct rows with respect to the columns
|
||||||
/// the user specifies in the argument
|
/// the user specifies in the argument
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataStreamUserRespresentation("distinct")]
|
[DataStreamUserRespresentation ("distinct")]
|
||||||
public class DistinctRowStream : ViewStream {
|
public class DistinctRowStream : ViewStream
|
||||||
public DistinctRowStream(ViewStream stream, params string[] cols) {
|
{
|
||||||
var g_by_eval = new DistinctRowEvaluator(cols);
|
public DistinctRowStream (ViewStream stream, params string[] cols)
|
||||||
ViewStream r = new GroupByStream(stream, g_by_eval);
|
{
|
||||||
var proj_exp = String.Empty;
|
ArrayList groupByCols = new ArrayList ();
|
||||||
foreach (var c in cols)
|
foreach (string col in cols)
|
||||||
proj_exp += $"{c} ";
|
foreach (string c in col.Split (' '))
|
||||||
proj_exp = proj_exp.Trim();
|
groupByCols.Add (c);
|
||||||
r = new NewProjectStream(r, proj_exp);
|
mySetRealSource (AttachStream(new GroupByStream (stream,
|
||||||
mySetRealSource(r);
|
new DistinctRowEvaluator (groupByCols.ToArray (typeof(string)) as string[]), false)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3,25 +3,20 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using BCG.Utilities.General;
|
using BCG.Utilities.General;
|
||||||
|
|
||||||
namespace BCG
|
namespace BCG
|
||||||
{
|
{
|
||||||
public class DateBasedFilter: IDynamicStreamFilter, IWorker
|
public class DateBasedFilter: IDynamicStreamFilter, IWorker
|
||||||
{
|
{
|
||||||
private ViewStreamDatabase myVSD;
|
|
||||||
private string myDateColumn;
|
private string myDateColumn;
|
||||||
private int myNDays;
|
private int myNDays;
|
||||||
private DateTime myReference;
|
private DateTime myReference;
|
||||||
private DateTime myTodaysDate;
|
private DateTime myTodaysDate;
|
||||||
|
|
||||||
public DateBasedFilter(string dateColumn, int nDays)
|
public DateBasedFilter(string dateColumn, int nDays)
|
||||||
: this(dateColumn, nDays, ViewStreamDatabase.instance) { }
|
|
||||||
|
|
||||||
public DateBasedFilter(string dateColumn, int nDays, ViewStreamDatabase vsd)
|
|
||||||
{
|
{
|
||||||
myDateColumn = dateColumn;
|
myDateColumn = dateColumn;
|
||||||
myNDays = nDays;
|
myNDays = nDays;
|
||||||
myVSD = vsd;
|
|
||||||
myVSD.addWorker(this);
|
|
||||||
myTodaysDate = DateTime.Today;
|
myTodaysDate = DateTime.Today;
|
||||||
myReference = myTodaysDate.AddDays(-1 * myNDays);
|
myReference = myTodaysDate.AddDays(-1 * myNDays);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
using bts;
|
using BCG.Utilities.General;
|
||||||
|
|
||||||
using Bts.DataStream;
|
using Bts.DataStream;
|
||||||
using Bts.DataStream.Primitives.Filter;
|
using Bts.PubSub;
|
||||||
|
|
||||||
using mbts.config;
|
using mbts.config;
|
||||||
|
|
||||||
|
using Spark.Core.Disposables;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
@@ -29,7 +31,6 @@ namespace BCG.StreamWorld.Addition
|
|||||||
{
|
{
|
||||||
myBaseStream = vs;
|
myBaseStream = vs;
|
||||||
myFilter = filter;
|
myFilter = filter;
|
||||||
vs.ErrorChanged += OnError;
|
|
||||||
if (filter is IDynamicStreamFilter)
|
if (filter is IDynamicStreamFilter)
|
||||||
(filter as IDynamicStreamFilter).onFilterChange += new FilterChangeDelegate(myHandleFilterChange);
|
(filter as IDynamicStreamFilter).onFilterChange += new FilterChangeDelegate(myHandleFilterChange);
|
||||||
}
|
}
|
||||||
@@ -47,50 +48,37 @@ namespace BCG.StreamWorld.Addition
|
|||||||
myStateTable.clear();
|
myStateTable.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool filterRow(IBlueRow r) {
|
|
||||||
try {
|
|
||||||
return myFilter.filter(r);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Log.Gen.error($"FilterStream delegate threw exception: {ex}");
|
|
||||||
OnError(new StreamFilterException(StreamId, StreamName, null, ex, r));
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void myHandleChanges(object newValue)
|
private void myHandleChanges(object newValue)
|
||||||
{
|
{
|
||||||
try {
|
DataPacket dp = newValue as DataPacket;
|
||||||
DataPacket dp = newValue as DataPacket;
|
if (myStateTable == null)
|
||||||
if (myStateTable == null)
|
{
|
||||||
{
|
bts.Log.assert(myBaseTable == null);
|
||||||
bts.Log.assert(myBaseTable == null);
|
myStateTable = new BlueTable(dp.schema);
|
||||||
myStateTable = new BlueTable(dp.schema);
|
myBaseTable = new BlueTable(dp.schema);
|
||||||
myBaseTable = new BlueTable(dp.schema);
|
|
||||||
}
|
|
||||||
BlueTable dels = new BlueTable(dp.schema),
|
|
||||||
adds = new BlueTable(dp.schema);
|
|
||||||
foreach (IBlueRow r in dp.deletedRows)
|
|
||||||
{
|
|
||||||
myBaseTable.deleteRow(r);
|
|
||||||
if (myStateTable.containsID((int)r["id"]))
|
|
||||||
{
|
|
||||||
dels.addRow(r);
|
|
||||||
myStateTable.deleteRow(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
foreach (IBlueRow r in dp.addedRows) {
|
|
||||||
myBaseTable.addRow(r);
|
|
||||||
if (filterRow(r)) {
|
|
||||||
adds.addRow(r);
|
|
||||||
myStateTable.addRow(r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ((dels.Count > 0 || adds.Count > 0) || (myLastValue == null)) {
|
|
||||||
myFireEvent(new DataPacket(myStateTable, adds, dels));
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
OnError(ex);
|
|
||||||
}
|
}
|
||||||
|
BlueTable dels = new BlueTable(dp.schema),
|
||||||
|
adds = new BlueTable(dp.schema);
|
||||||
|
foreach (IBlueRow r in dp.deletedRows)
|
||||||
|
{
|
||||||
|
myBaseTable.deleteRow(r);
|
||||||
|
if (myStateTable.containsID((int)r["id"]))
|
||||||
|
{
|
||||||
|
dels.addRow(r);
|
||||||
|
myStateTable.deleteRow(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (IBlueRow r in dp.addedRows)
|
||||||
|
{
|
||||||
|
myBaseTable.addRow(r);
|
||||||
|
if (myFilter.filter(r))
|
||||||
|
{
|
||||||
|
adds.addRow(r);
|
||||||
|
myStateTable.addRow(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((dels.Count > 0 || adds.Count > 0) || (myLastValue == null))
|
||||||
|
myFireEvent(new DataPacket(myStateTable, adds, dels));
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStreamFilter filter
|
public IStreamFilter filter
|
||||||
@@ -102,20 +90,9 @@ namespace BCG.StreamWorld.Addition
|
|||||||
{
|
{
|
||||||
IBlueRowCollection oldState = new BlueTable(myStateTable);
|
IBlueRowCollection oldState = new BlueTable(myStateTable);
|
||||||
myStateTable.clear();
|
myStateTable.clear();
|
||||||
// If the filter throws an exception, we can rethrow it as a StreamFilterException
|
foreach (IBlueRow r in myBaseTable)
|
||||||
// and include the 'currentRow' (for which the filter failed) to provide context.
|
if (myFilter.filter(r))
|
||||||
IBlueRow? currentRow = null;
|
myStateTable.addRow(r);
|
||||||
foreach (IBlueRow r in myBaseTable) {
|
|
||||||
try {
|
|
||||||
currentRow = r;
|
|
||||||
if (filterRow(r)) {
|
|
||||||
myStateTable.addRow(r);
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
Log.Gen.error($"FilterStream delegate threw exception: {ex}");
|
|
||||||
OnError(new StreamFilterException(StreamId, StreamName, null, ex, currentRow));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IBlueRowCollection dels, adds;
|
IBlueRowCollection dels, adds;
|
||||||
BlueDataUtility.computeDifferences(myStateTable, oldState, out dels, out adds);
|
BlueDataUtility.computeDifferences(myStateTable, oldState, out dels, out adds);
|
||||||
myFireEvent(new DataPacket(myStateTable, adds, dels));
|
myFireEvent(new DataPacket(myStateTable, adds, dels));
|
||||||
@@ -169,6 +146,7 @@ namespace BCG
|
|||||||
private BlueTable myLastFiredRows;
|
private BlueTable myLastFiredRows;
|
||||||
private IBlueRowCollection myLastReceivedRows;
|
private IBlueRowCollection myLastReceivedRows;
|
||||||
private IStreamFilter myFilter;
|
private IStreamFilter myFilter;
|
||||||
|
private IDisposable? filterWorkerSubscription;
|
||||||
private ViewStream myParentStream;
|
private ViewStream myParentStream;
|
||||||
private string myFilterString;
|
private string myFilterString;
|
||||||
private BCG.StreamWorld.Addition.FilterStream myFilterStream;
|
private BCG.StreamWorld.Addition.FilterStream myFilterStream;
|
||||||
@@ -196,7 +174,7 @@ namespace BCG
|
|||||||
if (myUseNewFilter)
|
if (myUseNewFilter)
|
||||||
{
|
{
|
||||||
myFilterStream = new BCG.StreamWorld.Addition.FilterStream(vs, filter);
|
myFilterStream = new BCG.StreamWorld.Addition.FilterStream(vs, filter);
|
||||||
mySetRealSource(myFilterStream);
|
mySetRealSource(AttachStream(myFilterStream));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -245,37 +223,37 @@ namespace BCG
|
|||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private void myHandleCallbacks(object newValue) {
|
private void myHandleCallbacks(object newValue)
|
||||||
|
{
|
||||||
DataPacket retVal;
|
DataPacket retVal;
|
||||||
DataPacket arrivedPacket = newValue as DataPacket;
|
DataPacket arrivedPacket = newValue as DataPacket;
|
||||||
myLastReceivedRows = arrivedPacket.newRows;
|
myLastReceivedRows = arrivedPacket.newRows;
|
||||||
try {
|
if (myLastFiredRows != null)
|
||||||
if (myLastFiredRows != null) {
|
{
|
||||||
retVal = new DataPacket(myLastFiredRows, new BlueTable(myLastFiredRows.schema),
|
retVal = new DataPacket(myLastFiredRows, new BlueTable(myLastFiredRows.schema),
|
||||||
new BlueTable(myLastFiredRows.schema));
|
new BlueTable(myLastFiredRows.schema));
|
||||||
foreach (IBlueRow r in arrivedPacket.deletedRows) {
|
foreach (IBlueRow r in arrivedPacket.deletedRows)
|
||||||
if (myLastFiredRows.containsID((int)r["id"])) {
|
if (myLastFiredRows.containsID((int)r["id"]))
|
||||||
myLastFiredRows.deleteRow(r);
|
{
|
||||||
(retVal.deletedRows as BlueTable).addRow(r);
|
myLastFiredRows.deleteRow(r);
|
||||||
}
|
(retVal.deletedRows as BlueTable).addRow(r);
|
||||||
}
|
}
|
||||||
foreach (IBlueRow r in arrivedPacket.addedRows) {
|
foreach (IBlueRow r in arrivedPacket.addedRows)
|
||||||
if (filterRow(r)) {
|
if (myFilter.filter(r))
|
||||||
myLastFiredRows.addRow(r);
|
{
|
||||||
(retVal.addedRows as BlueTable).addRow(r);
|
myLastFiredRows.addRow(r);
|
||||||
}
|
(retVal.addedRows as BlueTable).addRow(r);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
myLastFiredRows = new BlueTable(arrivedPacket.schema);
|
|
||||||
retVal = new DataPacket(myLastFiredRows, myLastFiredRows, new BlueTable(myLastFiredRows.schema));
|
|
||||||
foreach (IBlueRow r in arrivedPacket.newRows)
|
|
||||||
if (filterRow(r))
|
|
||||||
myLastFiredRows.addRow(r);
|
|
||||||
}
|
|
||||||
myFireEvent(retVal);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
OnError(ex);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
myLastFiredRows = new BlueTable(arrivedPacket.schema);
|
||||||
|
retVal = new DataPacket(myLastFiredRows, myLastFiredRows, new BlueTable(myLastFiredRows.schema));
|
||||||
|
foreach (IBlueRow r in arrivedPacket.newRows)
|
||||||
|
if (myFilter.filter(r))
|
||||||
|
myLastFiredRows.addRow(r);
|
||||||
|
}
|
||||||
|
myFireEvent(retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStreamFilter filter
|
public IStreamFilter filter
|
||||||
@@ -288,26 +266,25 @@ namespace BCG
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Disposable.dispose(ref filterWorkerSubscription);
|
||||||
myFilter = value;
|
myFilter = value;
|
||||||
if (numberOfSubscribers > 0)
|
if (numberOfSubscribers > 0)
|
||||||
{
|
{
|
||||||
if (myLastReceivedRows != null) {
|
if (myLastReceivedRows != null)
|
||||||
try {
|
{
|
||||||
BlueTable nRows = new BlueTable(myLastReceivedRows.schema);
|
BlueTable nRows = new BlueTable(myLastReceivedRows.schema);
|
||||||
foreach (IBlueRow r in myLastReceivedRows) {
|
foreach (IBlueRow r in myLastReceivedRows)
|
||||||
if (filterRow(r)) {
|
if (myFilter.filter(r))
|
||||||
nRows.addRow(r);
|
nRows.addRow(r);
|
||||||
}
|
IBlueRowCollection dRows = new BlueTable(nRows.schema),
|
||||||
}
|
aRows = new BlueTable(nRows.schema);
|
||||||
IBlueRowCollection dRows = new BlueTable(nRows.schema),
|
BlueDataUtility.computeDifferences(nRows, myLastFiredRows, out dRows, out aRows);
|
||||||
aRows = new BlueTable(nRows.schema);
|
myLastFiredRows = nRows;
|
||||||
BlueDataUtility.computeDifferences(nRows, myLastFiredRows, out dRows, out aRows);
|
myFireEvent(new DataPacket(nRows, aRows, dRows));
|
||||||
myLastFiredRows = nRows;
|
if (myFilter is IWorker filterWorker) {
|
||||||
myFireEvent(new DataPacket(nRows, aRows, dRows));
|
filterWorkerSubscription = ViewStreamDatabase.Subscribe(filterWorker);
|
||||||
} catch (Exception ex) {
|
}
|
||||||
OnError(ex);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -327,17 +304,17 @@ namespace BCG
|
|||||||
return GetType().ToString() + " " + myFilterString;
|
return GetType().ToString() + " " + myFilterString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnViewStreamDatabase(IWorkScheduler viewStreamDatabase) {
|
||||||
|
base.OnViewStreamDatabase(viewStreamDatabase);
|
||||||
|
var w = this as IWorker;
|
||||||
|
if (w is not null) {
|
||||||
|
filterWorkerSubscription = viewStreamDatabase.Subscribe(w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void myHandleFilterChange()
|
private void myHandleFilterChange()
|
||||||
{
|
{
|
||||||
filter = myFilter;
|
filter = myFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool filterRow(IBlueRow r) {
|
|
||||||
try {
|
|
||||||
return myFilter.filter(r);
|
|
||||||
} catch (Exception ex) {
|
|
||||||
throw new StreamFilterException(StreamId, StreamName, null, ex, r);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -4,11 +4,13 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using BCG.Utilities.General;
|
using BCG.Utilities.General;
|
||||||
|
|
||||||
|
using Bts.PubSub;
|
||||||
|
|
||||||
namespace BCG
|
namespace BCG
|
||||||
{
|
{
|
||||||
public class SlidingWindowFilter: IDynamicStreamFilter, IWorker
|
public class SlidingWindowFilter: IDynamicStreamFilter, IWorker
|
||||||
{
|
{
|
||||||
private ViewStreamDatabase myVSD;
|
private IWorkScheduler workScheduler;
|
||||||
private string myDateColumn;
|
private string myDateColumn;
|
||||||
private int myNSecs;
|
private int myNSecs;
|
||||||
private DateTime myReference;
|
private DateTime myReference;
|
||||||
@@ -17,14 +19,9 @@ namespace BCG
|
|||||||
private DateTime myLastTimeFilteredApplied;
|
private DateTime myLastTimeFilteredApplied;
|
||||||
|
|
||||||
public SlidingWindowFilter(string dateColumn, int nSecs)
|
public SlidingWindowFilter(string dateColumn, int nSecs)
|
||||||
: this(dateColumn, nSecs, ViewStreamDatabase.instance) { }
|
|
||||||
|
|
||||||
public SlidingWindowFilter(string dateColumn, int nSecs, ViewStreamDatabase vsd)
|
|
||||||
{
|
{
|
||||||
myDateColumn = dateColumn;
|
myDateColumn = dateColumn;
|
||||||
myNSecs = nSecs;
|
myNSecs = nSecs;
|
||||||
myVSD = vsd;
|
|
||||||
myVSD.addWorker(this);
|
|
||||||
myCurrentTime = DateTime.Now;
|
myCurrentTime = DateTime.Now;
|
||||||
myReference = myCurrentTime.AddSeconds(-1 * myNSecs);
|
myReference = myCurrentTime.AddSeconds(-1 * myNSecs);
|
||||||
}
|
}
|
||||||
@@ -55,5 +52,9 @@ namespace BCG
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Dispose() {
|
||||||
|
workScheduler.Remove(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
#nullable enable
|
|
||||||
namespace Bts.DataStream.Primitives.Filter;
|
|
||||||
|
|
||||||
using BCG;
|
|
||||||
|
|
||||||
using System;
|
|
||||||
|
|
||||||
public class StreamFilterException : Exception {
|
|
||||||
public StreamFilterException(Guid streamId, string streamName, string? message, Exception? innerException, IBlueRow? badRow = null)
|
|
||||||
: base(message, innerException) {
|
|
||||||
StreamId = streamId;
|
|
||||||
StreamName = streamName;
|
|
||||||
BadRow = badRow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Guid StreamId { get; }
|
|
||||||
public string StreamName { get; }
|
|
||||||
public IBlueRow? BadRow { get; }
|
|
||||||
}
|
|
||||||
@@ -4,7 +4,7 @@ using System.Text.RegularExpressions;
|
|||||||
using BCG.Utilities.General;
|
using BCG.Utilities.General;
|
||||||
|
|
||||||
namespace BCG {
|
namespace BCG {
|
||||||
public class TimeBasedFilter : IDynamicStreamFilter, IWorker, IDisposable {
|
public class TimeBasedFilter : IDynamicStreamFilter, IWorker {
|
||||||
|
|
||||||
public static TimeSpan parse_duration(string input) {
|
public static TimeSpan parse_duration(string input) {
|
||||||
int days = 0, hours = 0, minutes = 0, seconds = 0;
|
int days = 0, hours = 0, minutes = 0, seconds = 0;
|
||||||
@@ -42,28 +42,15 @@ namespace BCG {
|
|||||||
: this(col_name, parse_duration(row_time_to_live)) {
|
: this(col_name, parse_duration(row_time_to_live)) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeBasedFilter(string rowTimeColumnName, TimeSpan rowTimeToLive)
|
public TimeBasedFilter(string rowTimeColumnName, TimeSpan rowTimeToLive)
|
||||||
: this(ViewStreamDatabase.instance, rowTimeColumnName, rowTimeToLive, new TimeSpan(0, 1, 0) /* 1 minute */) {
|
: this(rowTimeColumnName, rowTimeToLive, new TimeSpan(0, 1, 0) /* 1 minute */) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeBasedFilter(string rowTimeColumnName, TimeSpan rowTimeToLive, TimeSpan filterFrequency)
|
public TimeBasedFilter(string rowTimeColumnName, TimeSpan rowTimeToLive, TimeSpan filterFrequency) {
|
||||||
: this(ViewStreamDatabase.instance, rowTimeColumnName, rowTimeToLive, filterFrequency) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public TimeBasedFilter(ViewStreamDatabase vsd, string rowTimeColumnName, TimeSpan rowTimeToLive)
|
|
||||||
: this(vsd, rowTimeColumnName, rowTimeToLive, new TimeSpan(0, 1, 0) /* 1 minute */) {
|
|
||||||
}
|
|
||||||
|
|
||||||
public TimeBasedFilter(ViewStreamDatabase vsd, string rowTimeColumnName, TimeSpan rowTimeToLive, TimeSpan filterFrequency) {
|
|
||||||
myVsd = vsd;
|
|
||||||
_time_col = rowTimeColumnName;
|
_time_col = rowTimeColumnName;
|
||||||
_ttl = rowTimeToLive;
|
_ttl = rowTimeToLive;
|
||||||
myFilterFrequency = filterFrequency;
|
myFilterFrequency = filterFrequency;
|
||||||
myNextFilter = DateTime.MinValue;
|
myNextFilter = DateTime.MinValue;
|
||||||
|
|
||||||
// add worker
|
|
||||||
myVsd.addWorker(this);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
@@ -90,36 +77,18 @@ namespace BCG {
|
|||||||
|
|
||||||
if (now > myNextFilter) {
|
if (now > myNextFilter) {
|
||||||
// fire event
|
// fire event
|
||||||
onFilterChange?.Invoke();
|
onFilterChange();
|
||||||
|
|
||||||
myNextFilter = now.Add(myFilterFrequency);
|
myNextFilter = now.Add(myFilterFrequency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region IDisposable
|
|
||||||
public void Dispose() {
|
|
||||||
// remove worker
|
|
||||||
myVsd.removeWorker(this);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region state
|
#region state
|
||||||
private ViewStreamDatabase myVsd;
|
|
||||||
private string _time_col;
|
private string _time_col;
|
||||||
private TimeSpan _ttl;
|
private TimeSpan _ttl;
|
||||||
private TimeSpan myFilterFrequency;
|
private TimeSpan myFilterFrequency;
|
||||||
private DateTime myNextFilter;
|
private DateTime myNextFilter;
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
[DataStreamUserRespresentation("timefilter")]
|
|
||||||
public class TimeBasedFilterStream : ViewStream {
|
|
||||||
public TimeBasedFilterStream(ViewStream base_stream, string time_col, string time_span)
|
|
||||||
:
|
|
||||||
this(ViewStreamDatabase.instance, base_stream, time_col, TimeBasedFilter.parse_duration(time_span)) { }
|
|
||||||
public TimeBasedFilterStream(ViewStreamDatabase vsd, ViewStream base_stream, string time_col, TimeSpan time_span) {
|
|
||||||
TimeBasedFilter filter = new TimeBasedFilter(vsd, time_col, time_span);
|
|
||||||
mySetRealSource(new FilterStream(base_stream, filter));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Loaded 100 of 2072 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user