using BCG; using bts; using bts.api.core; using Bts.DataStreamQueryAnalyzer; using Bts.PubSub; using CommandLine; using Spark.Api.Services; using Spark.Core.Services; 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)); var configLoader = new SparkConfigLoader(new SparkConfigLoaderOpts() { ConfigServer = cfg.Sparkd }); var serviceContext = new ServiceContext(configLoader); var credentials = new SparkApiCredentials() { User = cfg.User, Password = cfg.Password }; var loginService = new SparkdLoginService(serviceContext, credentials, configLoader); var permissions = new UserDataPermissions(loginService); var mdClientConfig = new MarketDataClientConfig() { HotPollInterval = TimeSpan.FromSeconds(0.5) }; var mdClient = new MarketDataClient(configLoader, loginService, permissions, mdClientConfig); PrimitiveManager.SetMarketDataClient(mdClient); using var vsd = new ViewStreamDatabase(new SubscriberCoreFactory()); ViewStreamDatabase.SetGlobalInstance(new ViewStreamDatabase(new SubscriberCoreFactory())); Log.Gen.info("Starting DataStreamQueryAnalyzer"); 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; } } }