refactor: Use HostBuilder to launch spark w/ streams

This commit is contained in:
John Colvin committed 2025-11-19 13:55:43 -05:00
1 parent e2b3e543ea
commit 4397df4628
28 files changed
+780 -314

No files matched your search

+1
View File
@@ -55,6 +55,7 @@ trace_data/
.cache/
/src/Spark.Admin.WebApp/tsconfig.*.g.json
/src/Spark.Admin.WebApp/src/bin/
/src/client/**/*appsettings.Local.json
**/CMakeDeps.cmake
**/CMakeDeps_win.cmake
.devcontainer/
+16
View File
@@ -236,6 +236,9 @@
"preLaunchTask": "Build Spark (Debug)",
"program": "Spark.exe",
"cwd": "build/Debug/bin/net8.0-windows",
"env": {
"DOTNET_ENVIRONMENT": "${input:sparkEnvironment}",
}
},
"stopAtEntry": false,
"console": "integratedTerminal"
@@ -248,6 +251,9 @@
"windows": {
"program": "Spark.exe",
"cwd": "build/Debug/bin/net8.0-windows",
"env": {
"DOTNET_ENVIRONMENT": "${input:sparkEnvironment}",
}
},
"stopAtEntry": false,
"console": "integratedTerminal"
@@ -406,6 +412,16 @@
],
"default": "Development",
},
{
"id": "sparkEnvironment",
"type": "pickString",
"description": "Spark Configuration",
"options": [
"Development",
"Local",
],
"default": "Development",
},
{
"id": "sparkConfigServer",
"type": "promptString",
+164 -143
View File
@@ -1,143 +1,164 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32922.545
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_api", "src\client\spark_api\spark_api.csproj", "{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spark", "src\client\spark\Spark.csproj", "{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spark.Console", "src\client\Spark.Console\Spark.Console.csproj", "{387566C6-C6F6-412C-A30C-9855BBCB4816}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_core", "src\client\spark_core\spark_core.csproj", "{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_sdk", "src\client\spark_sdk\spark_sdk.csproj", "{6963C314-83C4-4667-B0D0-C2F7AE208C29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_test", "src\client\spark_test\spark_test.csproj", "{ECD78CC5-138F-4809-A764-2358C2AC2E82}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_websocket", "src\client\spark_websocket\spark_websocket.csproj", "{3201359D-C071-4089-9EDE-B04D759F1508}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_api_server", "src\client\spark_api_server\spark_api_server.csproj", "{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStreamCore", "src\DataStreamSuite\DataStreamCore\DataStreamCore.csproj", "{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStream", "src\DataStreamSuite\DataStream\DataStream.csproj", "{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedStreams", "src\DataStreamSuite\SharedStreams\SharedStreams.csproj", "{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PubSub", "src\DataStreamSuite\PubSub\PubSub.csproj", "{51C40BA9-F226-4A35-939D-1ED6F5FF7299}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
MinSizeRel|x64 = MinSizeRel|x64
Release|x64 = Release|x64
RelWithDebInfo|x64 = RelWithDebInfo|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Debug|x64.ActiveCfg = Debug|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Debug|x64.Build.0 = Debug|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.MinSizeRel|x64.ActiveCfg = Release|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.MinSizeRel|x64.Build.0 = Release|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Release|x64.ActiveCfg = Release|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Release|x64.Build.0 = Release|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x64.Build.0 = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x64.ActiveCfg = Debug|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x64.Build.0 = Debug|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|x64.ActiveCfg = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|x64.Build.0 = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Release|x64.ActiveCfg = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Release|x64.Build.0 = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.RelWithDebInfo|x64.Build.0 = Release|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.Debug|x64.ActiveCfg = Debug|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.Debug|x64.Build.0 = Debug|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.MinSizeRel|x64.ActiveCfg = Debug|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.MinSizeRel|x64.Build.0 = Debug|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.Release|x64.ActiveCfg = Release|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.Release|x64.Build.0 = Release|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.RelWithDebInfo|x64.Build.0 = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Debug|x64.ActiveCfg = Debug|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Debug|x64.Build.0 = Debug|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.MinSizeRel|x64.ActiveCfg = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.MinSizeRel|x64.Build.0 = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Release|x64.ActiveCfg = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Release|x64.Build.0 = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x64.Build.0 = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.Debug|x64.ActiveCfg = Debug|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.Debug|x64.Build.0 = Debug|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.MinSizeRel|x64.ActiveCfg = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.MinSizeRel|x64.Build.0 = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.Release|x64.ActiveCfg = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.Release|x64.Build.0 = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.RelWithDebInfo|x64.Build.0 = Release|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.Debug|x64.ActiveCfg = Debug|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.Debug|x64.Build.0 = Debug|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.MinSizeRel|x64.ActiveCfg = Debug|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.MinSizeRel|x64.Build.0 = Debug|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.Release|x64.ActiveCfg = Release|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.Release|x64.Build.0 = Release|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.RelWithDebInfo|x64.Build.0 = Release|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.Debug|x64.ActiveCfg = Debug|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.Debug|x64.Build.0 = Debug|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.MinSizeRel|x64.ActiveCfg = Debug|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.MinSizeRel|x64.Build.0 = Debug|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.Release|x64.ActiveCfg = Release|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.Release|x64.Build.0 = Release|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.RelWithDebInfo|x64.Build.0 = Release|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.Debug|x64.ActiveCfg = Debug|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.Debug|x64.Build.0 = Debug|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.MinSizeRel|x64.ActiveCfg = Debug|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.MinSizeRel|x64.Build.0 = Debug|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.Release|x64.ActiveCfg = Release|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.Release|x64.Build.0 = Release|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.RelWithDebInfo|x64.Build.0 = Release|x64
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.Debug|x64.ActiveCfg = Debug|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.Debug|x64.Build.0 = Debug|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.Release|x64.ActiveCfg = Release|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.Release|x64.Build.0 = Release|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.Debug|x64.ActiveCfg = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.Debug|x64.Build.0 = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.Release|x64.ActiveCfg = Release|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.Release|x64.Build.0 = Release|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.Debug|x64.ActiveCfg = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.Debug|x64.Build.0 = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.Release|x64.ActiveCfg = Release|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.Release|x64.Build.0 = Release|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.Debug|x64.ActiveCfg = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.Debug|x64.Build.0 = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.Release|x64.ActiveCfg = Release|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.Release|x64.Build.0 = Release|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {422D1620-0166-4C26-9A81-CA8A2EB1AB58}
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
EndGlobal
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32922.545
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_api", "src\client\spark_api\spark_api.csproj", "{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spark", "src\client\spark\Spark.csproj", "{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Spark.Console", "src\client\Spark.Console\Spark.Console.csproj", "{387566C6-C6F6-412C-A30C-9855BBCB4816}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_core", "src\client\spark_core\spark_core.csproj", "{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_sdk", "src\client\spark_sdk\spark_sdk.csproj", "{6963C314-83C4-4667-B0D0-C2F7AE208C29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_test", "src\client\spark_test\spark_test.csproj", "{ECD78CC5-138F-4809-A764-2358C2AC2E82}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_websocket", "src\client\spark_websocket\spark_websocket.csproj", "{3201359D-C071-4089-9EDE-B04D759F1508}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "spark_api_server", "src\client\spark_api_server\spark_api_server.csproj", "{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStreamCore", "src\DataStreamSuite\DataStreamCore\DataStreamCore.csproj", "{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStream", "src\DataStreamSuite\DataStream\DataStream.csproj", "{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedStreams", "src\DataStreamSuite\SharedStreams\SharedStreams.csproj", "{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PubSub", "src\DataStreamSuite\PubSub\PubSub.csproj", "{51C40BA9-F226-4A35-939D-1ED6F5FF7299}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4564E677-343A-46CB-AF02-AFC4E38BF94B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "client", "client", "{56A8A70A-DA03-4CED-A144-EC10F1379FD8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "DataStreamSuite", "DataStreamSuite", "{915EF238-CA0D-4E73-AF50-88CB3F29C7AD}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bts.Extensions.Hosting", "src\DataStreamSuite\Bts.Extensions.Hosting\Bts.Extensions.Hosting.csproj", "{4E0E51AA-7B59-4808-B7CC-9EAEDF397460}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
MinSizeRel|x64 = MinSizeRel|x64
Release|x64 = Release|x64
RelWithDebInfo|x64 = RelWithDebInfo|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Debug|x64.ActiveCfg = Debug|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Debug|x64.Build.0 = Debug|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.MinSizeRel|x64.ActiveCfg = Release|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.MinSizeRel|x64.Build.0 = Release|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Release|x64.ActiveCfg = Release|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.Release|x64.Build.0 = Release|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{DC9A8975-8211-4FC9-A9BA-C8B9D26AD481}.RelWithDebInfo|x64.Build.0 = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x64.ActiveCfg = Debug|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Debug|x64.Build.0 = Debug|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|x64.ActiveCfg = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.MinSizeRel|x64.Build.0 = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Release|x64.ActiveCfg = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.Release|x64.Build.0 = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{9A4D4D07-1AB6-4B2B-B111-A4F34D6C267E}.RelWithDebInfo|x64.Build.0 = Release|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.Debug|x64.ActiveCfg = Debug|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.Debug|x64.Build.0 = Debug|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.MinSizeRel|x64.ActiveCfg = Debug|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.MinSizeRel|x64.Build.0 = Debug|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.Release|x64.ActiveCfg = Release|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.Release|x64.Build.0 = Release|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{387566C6-C6F6-412C-A30C-9855BBCB4816}.RelWithDebInfo|x64.Build.0 = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Debug|x64.ActiveCfg = Debug|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Debug|x64.Build.0 = Debug|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.MinSizeRel|x64.ActiveCfg = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.MinSizeRel|x64.Build.0 = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Release|x64.ActiveCfg = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.Release|x64.Build.0 = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{6E449EB6-20AC-4FA6-B8D9-10F4BB7E1FEE}.RelWithDebInfo|x64.Build.0 = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.Debug|x64.ActiveCfg = Debug|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.Debug|x64.Build.0 = Debug|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.MinSizeRel|x64.ActiveCfg = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.MinSizeRel|x64.Build.0 = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.Release|x64.ActiveCfg = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.Release|x64.Build.0 = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{6963C314-83C4-4667-B0D0-C2F7AE208C29}.RelWithDebInfo|x64.Build.0 = Release|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.Debug|x64.ActiveCfg = Debug|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.Debug|x64.Build.0 = Debug|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.MinSizeRel|x64.ActiveCfg = Debug|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.MinSizeRel|x64.Build.0 = Debug|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.Release|x64.ActiveCfg = Release|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.Release|x64.Build.0 = Release|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{ECD78CC5-138F-4809-A764-2358C2AC2E82}.RelWithDebInfo|x64.Build.0 = Release|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.Debug|x64.ActiveCfg = Debug|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.Debug|x64.Build.0 = Debug|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.MinSizeRel|x64.ActiveCfg = Debug|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.MinSizeRel|x64.Build.0 = Debug|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.Release|x64.ActiveCfg = Release|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.Release|x64.Build.0 = Release|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{3201359D-C071-4089-9EDE-B04D759F1508}.RelWithDebInfo|x64.Build.0 = Release|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.Debug|x64.ActiveCfg = Debug|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.Debug|x64.Build.0 = Debug|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.MinSizeRel|x64.ActiveCfg = Debug|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.MinSizeRel|x64.Build.0 = Debug|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.Release|x64.ActiveCfg = Release|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.Release|x64.Build.0 = Release|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{2B8C5D01-FF78-4BFA-B332-5E430586DAF9}.RelWithDebInfo|x64.Build.0 = Release|x64
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.Debug|x64.ActiveCfg = Debug|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.Debug|x64.Build.0 = Debug|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.Release|x64.ActiveCfg = Release|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.Release|x64.Build.0 = Release|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{4E4F491F-C688-43C4-88DA-AC92BC5FA1B8}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.Debug|x64.ActiveCfg = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.Debug|x64.Build.0 = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.Release|x64.ActiveCfg = Release|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.Release|x64.Build.0 = Release|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{2AC54ADC-3246-427E-9CA9-FEA2DBCB9432}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.Debug|x64.ActiveCfg = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.Debug|x64.Build.0 = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.Release|x64.ActiveCfg = Release|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.Release|x64.Build.0 = Release|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{4E96E5CC-7791-40B3-A8A1-C34FBB736B3B}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.Debug|x64.ActiveCfg = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.Debug|x64.Build.0 = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.Release|x64.ActiveCfg = Release|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.Release|x64.Build.0 = Release|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{51C40BA9-F226-4A35-939D-1ED6F5FF7299}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
{4E0E51AA-7B59-4808-B7CC-9EAEDF397460}.Debug|x64.ActiveCfg = Debug|Any CPU
{4E0E51AA-7B59-4808-B7CC-9EAEDF397460}.Debug|x64.Build.0 = Debug|Any CPU
{4E0E51AA-7B59-4808-B7CC-9EAEDF397460}.MinSizeRel|x64.ActiveCfg = Debug|Any CPU
{4E0E51AA-7B59-4808-B7CC-9EAEDF397460}.MinSizeRel|x64.Build.0 = Debug|Any CPU
{4E0E51AA-7B59-4808-B7CC-9EAEDF397460}.Release|x64.ActiveCfg = Release|Any CPU
{4E0E51AA-7B59-4808-B7CC-9EAEDF397460}.Release|x64.Build.0 = Release|Any CPU
{4E0E51AA-7B59-4808-B7CC-9EAEDF397460}.RelWithDebInfo|x64.ActiveCfg = Debug|Any CPU
{4E0E51AA-7B59-4808-B7CC-9EAEDF397460}.RelWithDebInfo|x64.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {422D1620-0166-4C26-9A81-CA8A2EB1AB58}
EndGlobalSection
GlobalSection(Performance) = preSolution
HasPerformanceSessions = true
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{56A8A70A-DA03-4CED-A144-EC10F1379FD8} = {4564E677-343A-46CB-AF02-AFC4E38BF94B}
{915EF238-CA0D-4E73-AF50-88CB3F29C7AD} = {4564E677-343A-46CB-AF02-AFC4E38BF94B}
{4E0E51AA-7B59-4808-B7CC-9EAEDF397460} = {915EF238-CA0D-4E73-AF50-88CB3F29C7AD}
EndGlobalSection
EndGlobal
@@ -10,15 +10,15 @@ using HtmlAgilityPack;
namespace BCG {
class Program {
static void Main() {
string url = "http://quotes.toscrape.com";
List<string> quotes = ScrapeQuotes(url);
// static void Main() {
// string url = "http://quotes.toscrape.com";
// List<string> quotes = ScrapeQuotes(url);
Console.WriteLine("Quotes from http://quotes.toscrape.com:");
foreach (var quote in quotes) {
Console.WriteLine(quote);
}
}
// Console.WriteLine("Quotes from http://quotes.toscrape.com:");
// foreach (var quote in quotes) {
// Console.WriteLine(quote);
// }
// }
static List<string> ScrapeQuotes(string url) {
List<string> quotes = new List<string>();
+1 -1
View File
@@ -11,7 +11,7 @@ namespace bts.spark {
readonly ShellDiagnosticsServiceServer _service;
[ImportingConstructor]
public DiagnosticDaemon(ServiceContext context, CompositionContext container) {
public DiagnosticDaemon([Import("internal")]ServiceContext context, CompositionContext container) {
_service = new ShellDiagnosticsServiceServer(container, context);
}
}
+5
View File
@@ -38,6 +38,7 @@ namespace bts {
readonly TimeSpan _relay_throttle;
readonly TimeSpan _output_throttle;
readonly List<IDisposable> _resources = new(2);
readonly Lazy<MarketDataClient> client;
[ImportingConstructor]
public MDDaemon(
@@ -72,6 +73,7 @@ namespace bts {
_output_throttle = output_throttle;
_security_metadata = security_metadata;
_md_source_backing = new(() => new(UserDataPermissions.Create(_user.Value), _relay_throttle, _output_throttle));
client = new(() => new(_md_source));
}
public int priority => 55;
@@ -79,6 +81,9 @@ namespace bts {
[Export]
public MDConsumer consumer => _md_source.consumer;
[Export]
public Lazy<MarketDataClient> Client => client;
MDSource _md_source => _md_source_backing.Value;
IBus _bus => _bus_backing.Value;
+44 -18
View File
@@ -12,55 +12,81 @@ using bts.md;
using bts.metrics;
using bts.support;
using Spark.Core.Services;
using System.Composition;
namespace Spark {
[Export]
class ShellServices {
public ShellServices([Import("config_source")]string config_source) =>
context = new(new SparkConfigLoader(new SparkConfigLoaderOpts() { ConfigServer = config_source }));
PersistenceService genericSettingsService;
PersistenceService settingsService;
ErrorReportService errorReportService;
OrderService orderService;
AdminService adminService;
MarketDataRelay marketDataRelay;
PositionService positionService;
AnalyticsService analyticsService;
SyntheticSecurityService syntheticSecurityService;
AlgoDefinitionService algoDefinitionService;
MarketDataAuxiliaryService marketDataAuxiliaryService;
ShellLatencyService shellLatencyService;
MBOService mboService;
[Export("internal")]
public ServiceContext InternalServiceContext { get; set; }
[Export]
public ServiceContext context { get; }
public Api.IServiceProvider ServiceProvider { get; set; }
[Export("settings")]
public PersistenceService settings_service => context.locate<PersistenceService>("settings");
public PersistenceService SettingsService =>
settingsService ??= ServiceProvider.GetService<PersistenceService>("settings");
[Export]
public PersistenceService generic_settings => context.locate<PersistenceService>();
public PersistenceService GenericSettingsService =>
genericSettingsService ??= ServiceProvider.GetService<PersistenceService>();
[Export]
public ErrorReportService error_service => context.locate<ErrorReportService>();
public ErrorReportService ErrorReportService =>
errorReportService ??= ServiceProvider.GetService<ErrorReportService>();
[Export]
public OrderService order_service => context.locate<OrderService>();
public OrderService OrderService =>
orderService ??= ServiceProvider.GetService<OrderService>();
[Export]
public AdminService admin_service => context.locate<AdminService>();
public AdminService AdminService =>
adminService ??= ServiceProvider.GetService<AdminService>();
[Export]
public SyntheticSecurityService synthetic_security_service => context.locate<SyntheticSecurityService>();
public SyntheticSecurityService SyntheticSecurityService =>
syntheticSecurityService ??= ServiceProvider.GetService<SyntheticSecurityService>();
[Export]
public ShellLatencyService shell_latency_service => context.locate<ShellLatencyService>();
public ShellLatencyService ShellLatencyService =>
shellLatencyService ??= ServiceProvider.GetService<ShellLatencyService>();
[Export]
public PositionService position_service => context.locate<PositionService>();
public PositionService PositionService =>
positionService ??= ServiceProvider.GetService<PositionService>();
[Export]
public MarketDataAuxiliaryService md_auxiliary_service => context.locate<MarketDataAuxiliaryService>();
public MarketDataAuxiliaryService MarketDataAuxiliaryService =>
marketDataAuxiliaryService ??= ServiceProvider.GetService<MarketDataAuxiliaryService>();
[Export]
public MarketDataRelay md_replay => context.locate<MarketDataRelay>();
public MarketDataRelay MarketDataRelay =>
marketDataRelay ??= ServiceProvider.GetService<MarketDataRelay>();
[Export]
public AlgoDefinitionService algo_definition_service => context.locate<AlgoDefinitionService>();
public AlgoDefinitionService AlgoDefinitionService =>
algoDefinitionService ??= ServiceProvider.GetService<AlgoDefinitionService>();
[Export]
public MBOService mbo_service => context.locate<MBOService>();
public MBOService MboService =>
mboService ??= ServiceProvider.GetService<MBOService>();
[Export]
public AnalyticsService analytics_service => context.locate<AnalyticsService>();
public AnalyticsService AnalyticsService =>
analyticsService ??= ServiceProvider.GetService<AnalyticsService>();
}
}
+16 -9
View File
@@ -1,14 +1,21 @@
namespace Spark;
using Bts.Extensions.Hosting;
using mbts.ui.shell;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Spark.Services;
using System;
static class Program {
[STAThread]
public static int Main(string[] args) {
var app = new SparkApp();
app.InitializeComponent();
return app.Run();
}
var host = HostBuilderExtensions.CreateBtsBuilder(args)
.ConfigureServices(ConfigureServices)
.Build();
try {
host.Run();
} catch (Exception ex) {
Console.Error.WriteLine($"Host.Run threw an exception: {ex}");
Environment.Exit(1);
}
static void ConfigureServices(HostBuilderContext context, IServiceCollection services) =>
services.AddSparkApp(context.Configuration);
@@ -0,0 +1,16 @@
#nullable enable
namespace Spark.Services;
using bts.api;
using bts.api.core;
using Spark.Api.Services;
using System.Threading.Tasks;
public interface ISparkLoginGuiService : ISparkdLoginService {
new ValueTask<(LoginResult Result, AuthTokenImmutable? Token, string? Workspace)> LoginAsync();
async ValueTask<LoginResult> ISparkdLoginService.LoginAsync() =>
(await LoginAsync()).Result;
}
@@ -0,0 +1,73 @@
#nullable enable
namespace Spark.Services;
using bts.api.core;
using Bts.DataStreamCore;
using mbts.ui.shell;
using Microsoft.Extensions.Hosting;
using Spark.Core;
using Spark.Core.Services;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
class SparkAppService : IHostedService {
readonly ISparkConfigLoader sparkConfigLoader;
readonly List<IDataStreamFactory> streamFactories;
readonly ISparkLoginGuiService loginService;
readonly Api.IServiceProvider serviceProvider;
readonly ServiceContext internalServiceContext;
SparkApp? sparkApp;
public SparkAppService(
ISparkConfigLoader sparkConfigLoader, ISparkLoginGuiService loginService, Api.IServiceProvider serviceProvider, ServiceContext internalServiceContext, IEnumerable<IDataStreamFactory> streamFactories) {
this.sparkConfigLoader = sparkConfigLoader;
this.loginService = loginService;
this.serviceProvider = serviceProvider;
this.internalServiceContext = internalServiceContext;
this.streamFactories = new(streamFactories);
}
public async Task StartAsync(CancellationToken cancellationToken) {
var (loginResult, token, workspace) = await loginService.LoginAsync();
var sparkAppThread = new Thread(RunSparkApp) {
Name = "SparkApp",
};
sparkAppThread.SetApartmentState(ApartmentState.STA);
sparkAppThread.Start();
void RunSparkApp() {
int exitCode = 0;
try {
sparkApp = new() {
ConfigLoader = sparkConfigLoader,
StreamFactories = streamFactories,
ServiceProvider = serviceProvider,
InternalServiceContext = internalServiceContext,
UserTuple = loginResult.user.assert_value(),
Workspace = workspace,
Token = token,
};
exitCode = sparkApp.Run();
} catch (Exception ex) {
Console.Error.WriteLine($"SparkApp.Run threw an exception: {ex}");
}
if (exitCode != 0) {
throw new Exception($"SparkApp.Run returned non-zero exit code ({exitCode})");
}
}
}
public async Task StopAsync(CancellationToken cancellationToken) {
var disp = sparkApp?.Dispatcher;
if (disp is not null) {
await disp.InvokeAsync(() => sparkApp?.Shutdown());
}
}
}
@@ -0,0 +1,66 @@
#nullable enable
namespace Spark.Services;
using bts.api;
using bts.api.core;
using mbts;
using mbts.ui.shell;
using Microsoft.Extensions.Hosting;
using Spark.Core.Services;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
class SparkLoginGuiService : IHostedService, ISparkLoginGuiService {
readonly ISparkConfigLoader configLoader;
readonly TaskCompletionSource<(LoginResult Result, AuthTokenImmutable? Token, string? Workspace)> loginTcs = new();
readonly ServiceContext serviceProvider;
public SparkLoginGuiService(ISparkConfigLoader configLoader, ServiceContext serviceProvider) {
this.configLoader = configLoader;
this.serviceProvider = serviceProvider;
}
public async ValueTask<(LoginResult Result, AuthTokenImmutable? Token, string? Workspace)> LoginAsync() =>
await loginTcs.Task;
public async Task StartAsync(CancellationToken cancellationToken) {
await configLoader.InitializeAsync(CancellationToken.None);
var model = new LoginModel();
model.provide_services(serviceProvider);
var loginGuiThread = new Thread(RunLoginGui) {
IsBackground = true,
Name = "Login"
};
loginGuiThread.SetApartmentState(ApartmentState.STA);
loginGuiThread.Start();
model.await_login();
void RunLoginGui() {
var vm = new LoginViewModel(model, Dispatcher.CurrentDispatcher);
var view = new LoginView(vm);
vm.LoggedIn += OnLoggedIn;
model.init().ignore();
view.ShowDialog();
// ShowDialog returns when the window is closed. If the login is successful,
// the result will already be set and TrySetCancel will do nothing. If not,
// it will signal the login failed to all services waiting for an auth token.
loginTcs.TrySetException(new LoginException("Login failed"));
void OnLoggedIn() {
var (userName, userId, token) = model.get_user();
var workspace = model.get_workspace();
loginTcs.SetResult((new LoginResult() { user = new(userId, userName), success = true }, token, workspace));
view.Close();
}
}
}
public Task StopAsync(CancellationToken cancellationToken) {
throw new System.NotImplementedException();
}
}
@@ -0,0 +1,38 @@
#nullable enable
namespace Spark.Services;
using Bts.DataStream.Services;
using Bts.DataStreamCore.Services;
using Bts.PubSub.Services;
using Bts.SharedStreams.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Spark.Api.Services;
using Spark.Core.Services;
using System;
public static class SparkServices {
public static IServiceCollection AddSparkLoginGui(this IServiceCollection services) =>
services.AddSingleton<SparkLoginGuiService>()
.AddSingleton<ISparkdLoginService, SparkLoginGuiService>(sp => sp.GetRequiredService<SparkLoginGuiService>())
.AddSingleton<ISparkLoginGuiService, SparkLoginGuiService>(sp => sp.GetRequiredService<SparkLoginGuiService>())
.AddHostedService(sp => sp.GetRequiredService<SparkLoginGuiService>());
public static IServiceCollection AddSparkApp(this IServiceCollection services, IConfiguration configurationSection) =>
services
.AddSpark(configurationSection.GetSection("Spark"))
.AddSparkApi(configurationSection.GetSection("SparkApi"))
.AddSparkLoginGui()
.AddMasterWorker(configurationSection.GetSection("MasterWorker"))
.AddViewStreamDatabase()
.AddPubSubClient(configurationSection.GetSection("PubSub"))
.AddPubTableBroker()
.AddRemoteQueryManager()
.AddPrimitiveStreams(configurationSection.GetSection("PrimitiveStream"))
.AddMarketDataStreams()
.AddGarbageCollector(configurationSection.GetSection("GarbageCollector"))
.AddHostedService<SparkAppService>();
}
+23 -10
View File
@@ -1,12 +1,18 @@
namespace mbts.ui.shell {
using bts;
using bts.api;
using bts.api.core;
using Bts.DataStreamCore;
using mbts.config;
using mbts.ui.extensions;
using Spark.Core.Disposables;
using Spark.Core.Services;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Runtime.InteropServices;
using System.Threading;
@@ -19,7 +25,6 @@
/// and the collection of open windows) and displaying them.
/// </summary>
class ShellBootstrapper : IDisposable {
readonly string _config_source;
ShellModel _model;
Window _login;
@@ -28,6 +33,14 @@
Dispatcher.CurrentDispatcher.UnhandledException += CurrentDispatcher_HandleClipboardError;
}
public ISparkConfigLoader ConfigLoader { get; set; }
public IEnumerable<IDataStreamFactory> StreamFactories { get; set; }
public ServiceContext InternalServiceContext { get; set; }
public Spark.Api.IServiceProvider ServiceProvider { get; set; }
public UserTuple UserTuple { get; set; }
public AuthTokenImmutable? Token { get; set; }
public string Workspace { get; set; }
public static void CurrentDispatcher_HandleClipboardError(object sender, DispatcherUnhandledExceptionEventArgs e) {
// Dont' allow clipboard failure to bring down the shell
if (e.Exception is COMException com_exeption && com_exeption.ErrorCode == -2147221040) {
@@ -43,13 +56,7 @@
}
}
public ShellBootstrapper(
string user = null,
string password = null,
string config_source = null,
bool? restore_workspace = null
) {
_config_source = config_source;
public void LaunchLoginGui(string config_source = null, string user = null, string password = null, bool? restore_workspace = null) {
// Get the LoginModel instance on this thread to make sure it performs syncronous config initialization.
var login_model = LoginModel.init(config_source);
// Show the dialog on a background thread so animations aren't blocked during the main application startup
@@ -121,8 +128,14 @@
}
public void Run() {
_model = new ShellModel();
_model.Initialize(_config_source);
_model = new ShellModel() {
UserTuple_Export = new(() => UserTuple),
Token_Export = new(() => Token.Value),
Workspace = Workspace,
ConfigLoader = ConfigLoader,
StreamFactories = StreamFactories,
};
_model.Initialize(ServiceProvider, InternalServiceContext);
if (Configuration.get<bts.config.ShellRenderMode>().SoftwareOnly) {
System.Windows.Media.RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
}
+6
View File
@@ -53,6 +53,7 @@
<ProjectReference Include="..\spark_api\spark_api.csproj" />
<ProjectReference Include="..\spark_core\spark_core.csproj" />
<ProjectReference Include="..\..\DataStreamSuite\SharedStreams\SharedStreams.csproj" />
<ProjectReference Include="..\..\DataStreamSuite\Bts.Extensions.Hosting\Bts.Extensions.Hosting.csproj" />
</ItemGroup>
<ItemGroup>
@@ -80,4 +81,9 @@
<Target Name="diagnostic" AfterTargets="PreBuildEvent" />
<ItemGroup>
<ConfigurationProfile Include="appsettings.json" />
<ConfigurationProfile Include="appsettings.Local.json" Condition="Exists('appsettings.Local.json')" />
</ItemGroup>
</Project>
+48 -38
View File
@@ -1,35 +1,49 @@
namespace mbts.ui.shell {
using bts;
using bts.utils;
using CommandLine;
using Bts.DataStreamCore;
using mbts.ui.native;
using Spark.Cli;
using Spark.Core.Services;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
public partial class SparkApp : Application {
static readonly Mutex _mutex;
internal static readonly Mutex Mutex;
readonly bool allowMultipleShells;
ShellBootstrapper _runtime;
SparkCmdOpts _opts;
static SparkApp() {
// Don't let the designer take the mutex.
if (!_is_in_designer) {
_mutex = new Mutex(true, "5BA5BA1C-9AAC-4844-B7E5-094691CD5105");
if (!IsInDesigner) {
Mutex = new Mutex(true, "5BA5BA1C-9AAC-4844-B7E5-094691CD5105");
}
}
static bool _is_in_designer =>
public SparkApp()
: this(false) { }
public SparkApp(bool allowMultipleShells) {
this.allowMultipleShells = allowMultipleShells;
InitializeComponent();
}
public ISparkConfigLoader ConfigLoader { get; set; }
public IEnumerable<IDataStreamFactory> StreamFactories { get; set; }
public bts.api.core.ServiceContext InternalServiceContext { get; set; }
public Spark.Api.IServiceProvider ServiceProvider { get; set; }
public UserTuple UserTuple { get; set; }
public bts.api.AuthTokenImmutable? Token { get; set; }
public string Workspace { get; set; }
internal static bool IsInDesigner =>
#if DEBUG
(bool)DependencyPropertyDescriptor.FromProperty(
DesignerProperties.IsInDesignModeProperty,
@@ -39,32 +53,21 @@ namespace mbts.ui.shell {
#endif
public new int Run() {
var argv = SparkCmdOpts.conform_opts(Environment.GetCommandLineArgs().Skip(1));
int exit_code = 1;
Parser.Default.ParseArguments<SparkCmdOpts>(argv).WithParsed(opts => {
_opts = opts;
var opt_desc = TableFormatter.fmt_table(
typeof(SparkCmdOpts).GetProperties()
.Select(p => (p.Name, p.GetValue(opts))), field_separator: "\n\t");
Log.Ui.info($"Running spark_client with options:\n\t{opt_desc}");
try {
if (_mutex is not null && !_mutex.WaitOne(TimeSpan.Zero, true) && !opts.allow_multiple_shells) {
// Second instance. Activate the main window and return
NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, NativeMethods.WM_SHOWME, IntPtr.Zero, IntPtr.Zero);
Log.Ui.info("Bringing running shell to the foreground...");
exit_code = 0;
return;
}
exit_code = base.Run();
} catch (AbandonedMutexException ame) {
Log.Ui.warn($"Shell mutex was abandoned. Releasing the mutex and trying again. \n{ame}");
_mutex.ReleaseMutex();
// Keep trying until stack overflow
exit_code = Run();
try {
if (Mutex is not null && !Mutex.WaitOne(TimeSpan.Zero, true) && !allowMultipleShells) {
// Second instance. Activate the main window and return
NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, NativeMethods.WM_SHOWME, IntPtr.Zero, IntPtr.Zero);
Log.Ui.info("Bringing running shell to the foreground...");
return 0;
} else {
return base.Run();
}
});
return exit_code;
} catch (AbandonedMutexException ame) {
Log.Ui.warn($"Shell mutex was abandoned. Releasing the mutex and trying again. \n{ame}");
Mutex.ReleaseMutex();
// Keep trying until stack overflow
return Run();
}
}
protected override void OnStartup(StartupEventArgs e) {
@@ -76,8 +79,15 @@ namespace mbts.ui.shell {
CultureInfo.DefaultThreadCurrentUICulture = us_culture;
base.OnStartup(e);
_runtime = new ShellBootstrapper(
_opts?.user, _opts?.password, _opts?.sparkd, _opts?.restore_workspace);
_runtime = new ShellBootstrapper {
ConfigLoader = ConfigLoader,
StreamFactories = StreamFactories,
InternalServiceContext = InternalServiceContext,
ServiceProvider = ServiceProvider,
UserTuple = UserTuple,
Workspace = Workspace,
Token = Token,
};
_runtime.Run();
// Select text on tab in
+104
View File
@@ -0,0 +1,104 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Spark": {
"ConfigServer": "http://127.0.0.1:8000/config"
},
"SparkApi": {
"Credentials": {
"User": "bts",
"Password": ""
},
"EnableAdmin": true,
"EnableOrders": true,
"EnablePosition": true
},
"MasterWorker": {
"Interval": "00:00:00.1"
},
"ViewStreamDatabase": {
"Interval": "00:00:00.1"
},
"PrimitiveStream": {
"Assemblies": [
"DataStream.dll",
"SharedStreams.dll"
],
"ExcludedTypes": [
"SettlementPriceStream",
"OHLCVStream"
]
},
"PubSub": {
"HeartbeatInterval": 15000,
"MissingHeartbeatsBeforeGc": 50,
"DisposedConnectionCheckPeriod": 1000,
"ServerPort": 22019,
"Routing": {
"PublisherRoutes": [
{
"Name": "default",
"ServerAddress": "bts-cloud://127.0.0.1:22019",
"TagRegExp": ".*"
}
],
"SubscriberRoutes": [
{
"Name": "default",
"ServerAddress": "bts-cloud://127.0.0.1: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"
}
]
}
},
"DataStreamPublisher": {
"PublisherNodes": [
{
"Name": "test_data",
"Streams": [
{
"Name": "test_literal",
"Expression": "literal(\"x\", \"420.0\")",
"IsOnWebsocket": true
}
]
}
]
}
}
@@ -22,7 +22,10 @@ namespace bts.api.diagnostic {
class ShellDiagnosticsServiceServer : ShellDiagnosticServiceBase {
readonly ServiceContext _context;
readonly List<ShellScriptServer> _hosts = new List<ShellScriptServer>();
public ShellDiagnosticsServiceServer(CompositionContext container, ServiceContext context) : base(context, Environment.MachineName) {
[ImportingConstructor]
public ShellDiagnosticsServiceServer(CompositionContext container, [Import("internal")]ServiceContext context)
: base(context, Environment.MachineName) {
Console.WriteLine($"Started {Environment.MachineName}");
_context = context;
this.container = container;
@@ -22,7 +22,7 @@ namespace mbts.ui.controls {
_find_style(typeof(Button));
Style _find_style(object key) =>
Application.Current.TryFindResource(key) as Style;
Application.Current?.TryFindResource(key) as Style;
}
return _dialog_button_style_backing;
}
@@ -1,4 +1,4 @@
using bts;
using bts;
using bts.api;
using bts.api.core;
using bts.api.persistence;
@@ -15,39 +15,6 @@ using System.Threading.Tasks;
using System.Windows.Threading;
namespace mbts.ui.shell {
// The LoginContainer participates in the startup Import/Export dependency system
// Since the login form should not depend on *anything* it will be shown before this is created
// Once this is created it access the global LoginModel and retrieves the username
[Export]
public class LoginContainer {
[ImportingConstructor]
public LoginContainer(ServiceContext context) {
var model = LoginModel.instance;
model.provide_services(context);
// await_login pumps the dispatcher but doesn't allow control to return to MEF until the username and workspace are available
model.await_login();
(UserName, UserId, Token) = model.get_user();
Workspace = model.get_workspace();
model.Dispose();
UserTuple_Export = new Lazy<UserTuple>(() => UserTuple);
Token_Export = new Lazy<AuthTokenImmutable>(() => Token);
}
public string UserName { get; private set; }
public uint UserId { get; private set; }
public UserTuple UserTuple => new UserTuple(UserId, UserName);
public AuthTokenImmutable Token { get; private set; }
[Export]
public Lazy<UserTuple> UserTuple_Export { get; private set; }
[Export(typeof(Lazy<AuthTokenImmutable>))]
public Lazy<AuthTokenImmutable> Token_Export { get; private set; }
[Export("workspace")]
public string Workspace { get; private set; }
}
public struct User {
public User(string name, uint id) {
this.name = name;
@@ -61,18 +28,12 @@ namespace mbts.ui.shell {
// Singleton to help bootstrap the system
static Lazy<LoginModel> _instance;
readonly string _config_source;
private string _workspace;
private PreloginWorkspaceEnumerator _enum_workspace;
ServiceContext _ctx;
DispatcherFrame _frame = new DispatcherFrame();
LoginModel(string config_source) {
_config_source = config_source;
init().ignore();
}
// Properties used in binding to the UI
public event Action Ready;
@@ -87,7 +48,7 @@ namespace mbts.ui.shell {
public static LoginModel init(string config_source) {
// '_instance' is lazy to guarentee it is only instantiated once
Interlocked.CompareExchange(
ref _instance, new(() => new(config_source)), null);
ref _instance, new(() => new()), null);
return _instance.Value;
}
@@ -117,15 +78,6 @@ namespace mbts.ui.shell {
// Check that the logon dependencies are valid.
// Initialization is complete when UserNames is populated
public async Task<bool> init() {
// Make sure config is initialized and working
try {
Configuration.InitializeAsync(_config_source).AsTask().Wait();
} catch (ApplicationException e) {
ErrorMessage = e.Message;
HasFatalError = true;
return false;
}
// Wait for the hub to create the login doodad
_ctx = await _hub_src.Task;
// Populate the UI
@@ -181,6 +133,7 @@ namespace mbts.ui.shell {
#region provide hub
internal void provide_services(ServiceContext ctx) {
_hub_src.TrySetResult(ctx);
_ctx = ctx;
}
private TaskCompletionSource<ServiceContext> _hub_src = new TaskCompletionSource<ServiceContext>();
#endregion
@@ -29,6 +29,9 @@
</ui:StateManager.Groups>
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/view/Resources/Buttons.xaml"/>
</ResourceDictionary.MergedDictionaries>
<sys:Double x:Key="LoginControlPaddingLeft">10</sys:Double>
<sys:Double x:Key="LoginControlPaddingTop">10</sys:Double>
<sys:Double x:Key="LoginControlPaddingRight">22</sys:Double>
@@ -157,7 +160,10 @@
<TextBox
x:Name="_username"
HorizontalAlignment="Stretch"
Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}" />
Text="{Binding Name, UpdateSourceTrigger=PropertyChanged}"
BorderThickness="0"
Foreground="{ui:BTSBrush UI.TextBox.normal_foreground}"
Background="{ui:BTSBrush UI.TextBox.normal_background}" />
<!--Password-->
<PasswordBox
x:Name="_password"
@@ -188,7 +194,7 @@
Opacity="0.5"
Text="Password"
Visibility="{Binding IsFocused, Converter={StaticResource InverseBoolToVisibility}, ElementName=_password}"
Style="{StaticResource TextBlock.Dark}" />
Foreground="{ui:BTSBrush UI.default_text}" />
<CheckBox
x:Name="_resume_workspace_checkbox"
@@ -197,7 +203,7 @@
IsChecked="{Binding resume_workspace}"
IsEnabled="True"
ToolTip="{Binding SelectedWorkspace}"
Style="{StaticResource CheckBox.Dark}">
Foreground="{ui:BTSBrush UI.default_text}">
Load last workspace
</CheckBox>
@@ -225,10 +231,10 @@
<TextBlock
Text="The application is currently unavailable."
FontWeight="Bold"
Foreground="{ui:BTSBrush UI.default_text}"
TextWrapping="Wrap"
Margin="0,0,0,10"
Style="{StaticResource TextBlock.Dark}" />
<TextBlock TextWrapping="Wrap" Style="{StaticResource TextBlock.Dark}">
Margin="0,0,0,10" />
<TextBlock TextWrapping="Wrap" Foreground="{ui:BTSBrush UI.default_text}">
<Run>Please call BTS Support at </Run>
<Run FontWeight="Bold">(919) 913-0860</Run>
<Run>or email</Run>
@@ -237,12 +243,12 @@
<TextBlock
Text="Error Details:"
Margin="0,10,0,0"
Style="{StaticResource TextBlock.Dark}" />
Foreground="{ui:BTSBrush UI.default_text}" />
<TextBlock
Text="{Binding ErrorMessage}"
TextWrapping="Wrap"
Margin="5"
Style="{StaticResource TextBlock.Dark}" />
Foreground="{ui:BTSBrush UI.default_text}" />
</StackPanel>
<!-- Loading -->
@@ -257,7 +263,7 @@
>
<ui:BusySpinner Width="64" Height="64"/>
<TextBlock
Text="Loading..." HorizontalAlignment="Center" Style="{StaticResource TextBlock.Dark}" />
Text="Loading..." HorizontalAlignment="Center" Foreground="{ui:BTSBrush UI.default_text}" />
</StackPanel>
<!-- logo -->
@@ -36,6 +36,7 @@ namespace mbts.ui.shell {
public event Action ready;
public event Action begin_login;
public event Action LoggedIn;
private void OnSendMail(object obj) {
string uri_base = obj as string;
@@ -155,7 +156,10 @@ namespace mbts.ui.shell {
string selected_workspace = _resume_workspace && SelectedWorkspace != NEW_WORKSPACE_NAME ?
SelectedWorkspace : null;
var result = await _model.do_login(Name, selected_workspace, Password);
if (result.success) { login_status = LoginStatus.LoggingIn; }
if (result.success) {
login_status = LoginStatus.LoggingIn;
LoggedIn?.Invoke();
}
if (!result.success && !string.IsNullOrEmpty(result.reason)) {
WarningMessage = result.reason;
login_status = LoginStatus.Rejected;
@@ -166,7 +170,7 @@ namespace mbts.ui.shell {
}
private void OnCancel(object unused) {
CloseView();
Application.Current.Dispatcher.InvokeAsync(() => Application.Current.Shutdown(0));
Application.Current?.Dispatcher?.InvokeAsync(() => Application.Current.Shutdown(0));
}
private void CloseView() {
+43 -16
View File
@@ -1,11 +1,13 @@
namespace mbts.ui {
using bts;
using bts.api;
using bts.api.core;
using bts.config;
using bts.core;
using bts.shell;
using bts.spark;
using Bts.DataStreamCore;
using mbts.config;
using mbts.persist;
using mbts.spark;
@@ -13,9 +15,11 @@
using mbts.ui.settings;
using mbts.ui.shell;
using Spark;
using Spark.Api.Data;
using Spark.Api.Reactive;
using Spark.Core.Data;
using Spark.Core.Services;
using System;
using System.Collections.Generic;
@@ -30,9 +34,24 @@
using System.Text;
[Export]
public class ConfigSourceExporter {
[Export("config_source")]
public string config_source { get; set; }
public class CredentialsExporter {
[Export]
public Lazy<UserTuple> UserTuple_Export { get; set; }
[Export(typeof(Lazy<AuthTokenImmutable>))]
public Lazy<AuthTokenImmutable> Token_Export { get; set; }
[Export("workspace")]
public string Workspace { get; set; }
[Export]
public ISparkConfigLoader ConfigLoader { get; set; }
}
[Export]
public class StreamFactoryExporter {
[Export]
public IEnumerable<IDataStreamFactory> StreamFactories { get; set; }
}
// Models a generic multi-window host
@@ -43,12 +62,6 @@
public CompositionHost container => _container.Value;
[Import]
public ui.shell.LoginContainer login { get; set; }
[Import]
public Lazy<UserTuple> user_tuple { get; set; }
[ImportMany]
public IEnumerable<IShellDaemon> services { get; set; }
@@ -65,8 +78,14 @@
[Export]
public IExecFeeCalculator exec_fee_calculator => _exec_fee_calculator.Value;
public void Initialize(string config_source) {
PerformMEFComposition(config_source);
public Lazy<UserTuple> UserTuple_Export { get; set; }
public Lazy<AuthTokenImmutable> Token_Export { get; set; }
public string Workspace { get; set; }
public ISparkConfigLoader ConfigLoader { get; set; }
public IEnumerable<IDataStreamFactory> StreamFactories { get; set; }
public void Initialize(Spark.Api.IServiceProvider serviceProvider, ServiceContext internalServiceContext) {
PerformMEFComposition(serviceProvider, internalServiceContext);
InitInitializers();
}
@@ -105,12 +124,20 @@
return value;
}
void PerformMEFComposition(string config_source) {
void PerformMEFComposition(Spark.Api.IServiceProvider serviceProvider, ServiceContext internalServiceContext) {
Log.Ui.info($"Generating MEF dependencies for the shell" +
$"({typeof(IInitializable)}s, {typeof(IShellModule)}s, " +
$"{typeof(IShellDaemon)}s, etc.)");
try {
container.GetExport<ConfigSourceExporter>().config_source = config_source;
var shellServices = container.GetExport<ShellServices>();
shellServices.InternalServiceContext = internalServiceContext;
shellServices.ServiceProvider = serviceProvider;
var credentials = container.GetExport<CredentialsExporter>();
credentials.UserTuple_Export = UserTuple_Export;
credentials.Token_Export = Token_Export;
credentials.Workspace = Workspace;
credentials.ConfigLoader = ConfigLoader;
container.GetExport<StreamFactoryExporter>().StreamFactories = StreamFactories;
container.SatisfyImports(this);
} catch (ReflectionTypeLoadException rtlex) {
var message = new StringBuilder(rtlex.ToString());
@@ -142,10 +169,10 @@
// specifically when a task calls for adding particular types to the
// composition host, rather than all types in this assembly.
static HashSet<Type> _base_dep_injection_types() => new() {
typeof(shell.LoginContainer),
// typeof(shell.LoginContainer),
typeof(WindowFactory),
typeof(ServiceContext),
typeof(Spark.ShellServices),
// typeof(Spark.ShellServices),
typeof(shell.LauncherVM),
typeof(OrdersModel),
typeof(SimpleBus),
@@ -0,0 +1,49 @@
#nullable enable
namespace Spark.Api.Services;
using bts.api.core;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
public class CachedServiceProvider : Api.IServiceProvider {
readonly object locker = new();
readonly Api.IServiceProvider serviceProvider;
readonly Dictionary<ServiceKey, Lazy<object>> cachedServices = new();
public CachedServiceProvider(Api.IServiceProvider serviceProvider) {
this.serviceProvider = serviceProvider;
}
public T GetService<T>(string? qualifier) where T : class, IApiClient {
Lazy<object>? service = null;
lock (locker) {
service = cachedServices.GetOrAdd(new(typeof(T), qualifier), ServiceFactory);
}
return (T)service.Value;
Lazy<object> ServiceFactory(ServiceKey key) =>
new(() => serviceProvider.GetService<T>(key.Qualifier));
}
readonly struct ServiceKey : IEquatable<ServiceKey> {
public ServiceKey(Type type, string? qualifier) {
Type = type;
Qualifier = qualifier;
}
public Type Type { get; }
public string? Qualifier { get; }
public bool Equals(ServiceKey other) =>
other.Type == Type && other.Qualifier == Qualifier;
public override bool Equals([NotNullWhen(true)] object? obj) =>
obj is ServiceKey other && Equals(other);
public override int GetHashCode() {
return HashCode.Combine(Type.FullName, Qualifier);
}
}
}
@@ -38,14 +38,12 @@ public static class SparkApiServices {
/// before any api-related services run).
throw new InvalidOperationException("Must add SparkService first");
}
services
.Configure<SparkApiCredentials>(configurationSection.GetSection("Credentials"))
.AddSingleton<ServiceContext>()
.AddSingleton<Api.IServiceProvider, ServiceContext>(sp => sp.GetRequiredService<ServiceContext>())
.AddSingleton<SparkdLoginService>()
.AddSingleton<ISparkdLoginService, SparkdLoginService>(sp => sp.GetRequiredService<SparkdLoginService>())
.AddHostedService(sp => sp.GetRequiredService<SparkdLoginService>())
.AddSingleton<SecurityResolver>();
services.AddSingleton<ServiceContext>()
.AddSingleton<Api.IServiceProvider, CachedServiceProvider>(sp => new CachedServiceProvider(sp.GetRequiredService<ServiceContext>()));
var credentials = configurationSection.GetSection("Credentials");
if (credentials.GetChildren().Any()) {
services.AddSparkLogin(credentials);
}
if (configurationSection.GetValue("EnableOrders", true)) {
services.AddSparkdService<OrderService>();
services.TryAddSingleton<SecurityResolver>();
@@ -67,6 +65,20 @@ public static class SparkApiServices {
return services;
}
public static IServiceCollection AddSparkLogin(this IServiceCollection services, IConfiguration configurationSection) =>
services.Configure<SparkApiCredentials>(configurationSection)
.AddSingleton<SparkdLoginService>()
.AddSingleton<ISparkdLoginService, SparkdLoginService>(sp => sp.GetRequiredService<SparkdLoginService>())
.AddHostedService(sp => sp.GetRequiredService<SparkdLoginService>());
public static IServiceCollection AddSparkLogin(this IServiceCollection services, SparkApiCredentials configurationSection) =>
services.AddSingleton<SparkdLoginService>()
.AddSingleton<ISparkdLoginService, SparkdLoginService>(sp => sp.GetRequiredService<SparkdLoginService>())
.AddHostedService(sp => sp.GetRequiredService<SparkdLoginService>());
internal static IServiceCollection AddSparkdService<T>(this IServiceCollection services) where T : class =>
services.AddSingleton(sp => sp.GetRequiredService<ServiceContext>().GetRequiredService<T>());
internal static IServiceCollection AddQualifiedSparkdService<T>(this IServiceCollection services, string qualifier) where T : class, IApiClient =>
services.AddSingleton(sp => sp.GetRequiredService<ServiceContext>().locate<T>(qualifier));
}
@@ -0,0 +1,5 @@
namespace bts.api.core;
public class LoginException : ApiException {
public LoginException(string msg) : base(msg) { }
}
@@ -8,5 +8,6 @@ using System.Threading.Tasks;
/// Initializes Spark protobuf config.
/// </summary>
public interface ISparkConfigLoader {
string? ConfigServer { get; }
Task InitializeAsync(CancellationToken cancellationToken);
}
@@ -27,6 +27,8 @@ public class SparkConfigLoader : ISparkConfigLoader {
this.logger = logger;
}
public string? ConfigServer => config.ConfigServer;
public async Task InitializeAsync(CancellationToken cancellationToken) {
bool success = false;
var task = Configuration.InitializeAsync(config.ConfigServer, cancellationToken);
@@ -22,6 +22,8 @@ class SparkTestConfigLoader : ISparkConfigLoader {
public SparkTestConfigLoader(SparkTestConfigLoaderOpts config) =>
this.config = config;
public string? ConfigServer => null;
public async Task InitializeAsync(CancellationToken cancellationToken) =>
Log.assert(await Configuration.ResetForTestAsync(string.Empty, cancellationToken));
}