diff --git a/src/DataStreamSuite/DataStreamQueryAnalyzer/Program.cs b/src/DataStreamSuite/DataStreamQueryAnalyzer/Program.cs index ddaa8ca85..bb2915d11 100644 --- a/src/DataStreamSuite/DataStreamQueryAnalyzer/Program.cs +++ b/src/DataStreamSuite/DataStreamQueryAnalyzer/Program.cs @@ -1,49 +1,49 @@ -using BCG; - -using bts; -using bts.api.core; - -using Bts.DataStreamQueryAnalyzer; -using Bts.PubSub; - -using CommandLine; - -using mbts.config; - -using System; -using System.Threading.Tasks; -using System.Windows.Forms; - -static class Program { - [STAThread] - static async Task Main(string[] args) { - await Parser.Default.ParseArguments(args) - .MapResult(RunAsync, errs => Task.FromResult(1)); - - async Task RunAsync(DataStreamQueryAnalyzerConfig cfg) { - try { - cfg.MergeWithConfigFile(); - cfg.MergeWith(DataStreamQueryAnalyzerConfig.Default()); - PubSubConfig.SetGlobalConfig(Log.notnull(cfg.PubSub)); - Configuration.initialize(cfg.Sparkd); - Log.Gen.info("Starting DataStreamQueryAnalyzer"); - var service_ctx = ServiceContext.create(cfg.Sparkd); - await service_ctx.login(cfg.User ?? "bts", cfg.Password ?? string.Empty); - Log.Gen.info("Launching Main Window"); - var mainForm = new MainForm(); - if (cfg.StreamFile is not null) { - mainForm.loadFile(cfg.StreamFile); - } - Application.Run(mainForm); - } catch (Exception ex) { - // Write the error to console first, in case the logging system is compromised. - var error_msg = $"DataStreamPublisher threw exception:\n{ex}"; - Console.Error.WriteLine(error_msg); - Console.Error.Flush(); - bts.Log.Gen.error(error_msg); - return 1; - } - return 0; - } - } -} +using BCG; + +using bts; +using bts.api.core; + +using Bts.DataStreamQueryAnalyzer; +using Bts.PubSub; + +using CommandLine; + +using mbts.config; + +using System; +using System.Threading.Tasks; +using System.Windows.Forms; + +static class Program { + [STAThread] + static async Task Main(string[] args) { + await Parser.Default.ParseArguments(args) + .MapResult(RunAsync, errs => Task.FromResult(1)); + + async Task RunAsync(DataStreamQueryAnalyzerConfig cfg) { + try { + cfg.MergeWithConfigFile(); + cfg.MergeWith(DataStreamQueryAnalyzerConfig.Default()); + PubSubConfig.SetGlobalConfig(Log.notnull(cfg.PubSub)); + Configuration.initialize(cfg.Sparkd); + Log.Gen.info("Starting DataStreamQueryAnalyzer"); + var service_ctx = ServiceContext.create(cfg.Sparkd); + await service_ctx.login(cfg.User ?? "bts", cfg.Password ?? string.Empty); + Log.Gen.info("Launching Main Window"); + var mainForm = new MainForm(); + if (cfg.StreamFile is not null) { + mainForm.loadFile(cfg.StreamFile); + } + Application.Run(mainForm); + } catch (Exception ex) { + // Write the error to console first, in case the logging system is compromised. + var error_msg = $"DataStreamPublisher threw exception:\n{ex}"; + Console.Error.WriteLine(error_msg); + Console.Error.Flush(); + bts.Log.Gen.error(error_msg); + return 1; + } + return 0; + } + } +} diff --git a/src/DataStreamSuite/PubSubServer/PubSubServerConfig.cs b/src/DataStreamSuite/PubSubServer/PubSubServerConfig.cs index 31482328a..bf2cde73c 100644 --- a/src/DataStreamSuite/PubSubServer/PubSubServerConfig.cs +++ b/src/DataStreamSuite/PubSubServer/PubSubServerConfig.cs @@ -1,67 +1,67 @@ -namespace Bts.PubSubServer; - -using Bts.PubSub; - -using CommandLine; - -using System; -using System.IO; -using System.Text.Json; -using System.Text.Json.Serialization; - -public class PubSubServerConfig { - /// - /// The config server url for sparkd - /// - [JsonPropertyName("sparkd")] - [Option("sparkd", HelpText = "The sparkd config server")] - public string? Sparkd { get; set; } - - [JsonPropertyName("simple_echo_server")] - [Option("simple-echo-server", HelpText = "Run a simple echo server (won't connect to sparkd)")] - public bool? SimpleEchoServer { get; set; } - - [JsonPropertyName("pubsub")] - public PubSubConfig? PubSub { get; set; } - - [JsonIgnore] - [Option( - "config", - MetaValue = "PATH", - HelpText = "Path to json file representing these options (PubSubServerConfig)")] - public string? ConfigFile { get; set; } - - public static PubSubServerConfig Default() => - new() { - Sparkd = "http://localhost:8000/config", - SimpleEchoServer = false, - PubSub = PubSubConfig.Default(), - ConfigFile = null, - }; - - public void MergeWith(PubSubServerConfig other) { - Sparkd ??= other.Sparkd; - SimpleEchoServer ??= other.SimpleEchoServer; - PubSub ??= other.PubSub; - ConfigFile ??= other.ConfigFile; - } - - /// - /// Merges options with those defined in `ConfigFile` (does not overwrite - /// non-null existing values). - /// - /// - /// JsonSerializer.Deserialize returns null - /// - public void MergeWithConfigFile() { - if (ConfigFile is null) { - return; - } - var cfgString = File.ReadAllText(ConfigFile); - var parsedCfg = JsonSerializer.Deserialize(cfgString) ?? - throw new InvalidOperationException($"Failed to parse json from {ConfigFile}"); - MergeWith(parsedCfg); - ConfigFile = null; - } -} - +namespace Bts.PubSubServer; + +using Bts.PubSub; + +using CommandLine; + +using System; +using System.IO; +using System.Text.Json; +using System.Text.Json.Serialization; + +public class PubSubServerConfig { + /// + /// The config server url for sparkd + /// + [JsonPropertyName("sparkd")] + [Option("sparkd", HelpText = "The sparkd config server")] + public string? Sparkd { get; set; } + + [JsonPropertyName("simple_echo_server")] + [Option("simple-echo-server", HelpText = "Run a simple echo server (won't connect to sparkd)")] + public bool? SimpleEchoServer { get; set; } + + [JsonPropertyName("pubsub")] + public PubSubConfig? PubSub { get; set; } + + [JsonIgnore] + [Option( + "config", + MetaValue = "PATH", + HelpText = "Path to json file representing these options (PubSubServerConfig)")] + public string? ConfigFile { get; set; } + + public static PubSubServerConfig Default() => + new() { + Sparkd = "http://localhost:8000/config", + SimpleEchoServer = false, + PubSub = PubSubConfig.Default(), + ConfigFile = null, + }; + + public void MergeWith(PubSubServerConfig other) { + Sparkd ??= other.Sparkd; + SimpleEchoServer ??= other.SimpleEchoServer; + PubSub ??= other.PubSub; + ConfigFile ??= other.ConfigFile; + } + + /// + /// Merges options with those defined in `ConfigFile` (does not overwrite + /// non-null existing values). + /// + /// + /// JsonSerializer.Deserialize returns null + /// + public void MergeWithConfigFile() { + if (ConfigFile is null) { + return; + } + var cfgString = File.ReadAllText(ConfigFile); + var parsedCfg = JsonSerializer.Deserialize(cfgString) ?? + throw new InvalidOperationException($"Failed to parse json from {ConfigFile}"); + MergeWith(parsedCfg); + ConfigFile = null; + } +} +