Example #1
0
        public static LauncherConfig GetLauncherConfig(string[] commandLineArgs)
        {
            var arguments  = ExpandArgs(commandLineArgs);
            var configFile = ServiceConfiguration.FromArgs(arguments.Where(a => a.Contains(".json")).ToArray());

            var servicesToStart =
                arguments.Select(ServiceTypeHelper.GetServiceTypeFromString)
                .Where(type => type != ServiceType.Unknown)
                .ToList();

            var config = new LauncherConfig
            {
                Help                 = !arguments.Any() || arguments.Any(a => a.IsIn("--help", "/?", "-h", "-help")),
                IsInteractive        = arguments.Any(a => a == "--interactive"),
                PopulateEventStore   = arguments.Any(a => a == "--populate-eventstore"),
                EventStoreParameters = configFile.EventStore,
                InvalidArguments     = new List <string>(),
                ServicesToStart      = servicesToStart
            };

            return(config);
        }
        public static LauncherConfig GetLauncherConfig(string[] commandLineArgs)
        {
            var arguments = ExpandArgs(commandLineArgs);
            var configFile = ServiceConfiguration.FromArgs(arguments.Where(a => a.Contains(".json")).ToArray());

            var servicesToStart =
                arguments.Select(ServiceTypeHelper.GetServiceTypeFromString)
                    .Where(type => type != ServiceType.Unknown)
                    .ToList();

            var config = new LauncherConfig
            {
                Help = !arguments.Any() || arguments.Any(a => a.IsIn("--help", "/?", "-h", "-help")),
                IsInteractive = arguments.Any(a => a == "--interactive"),
                PopulateEventStore = arguments.Any(a => a == "--populate-eventstore"),
                EventStoreParameters = configFile.EventStore,
                InvalidArguments = new List<string>(),
                ServicesToStart = servicesToStart
            };

            return config;
        }
Example #3
0
        public void Run(LauncherConfig config)
        {
            _config = config;

            if (_config.Help)
            {
                Usage();
                return;
            }

            Log.Error();
            Log.Error(@"______                _   _             _____             _           ");
            Log.Error(@"| ___ \              | | (_)           |_   _|           | |          ");
            Log.Error(@"| |_/ /___  __ _  ___| |_ ___   _____    | |_ __ __ _  __| | ___ _ __ ");
            Log.Error(@"|    // _ \/ _` |/ __| __| \ \ / / _ \   | | '__/ _` |/ _` |/ _ \ '__|");
            Log.Error(@"| |\ \  __/ (_| | (__| |_| |\ V /  __/   | | | | (_| | (_| |  __/ |   ");
            Log.Error(@"\_| \_\___|\__,_|\___|\__|_| \_/ \___|   \_/_|  \__,_|\__,_|\___|_|   ");
            Log.Error();

            try
            {
                Console.CancelKeyPress += (s, e) =>
                {
                    Log.Info("Termination signal sent.");

                    Stop();
                };

                LogManager.Adapter = new ConsoleOutLoggerFactoryAdapter
                {
                    ShowLogName = true
                };

                if (_config.PopulateEventStore)
                {
                    _launcher.InitializeEventStore(_config.EventStoreParameters, _config.RunEmbeddedEventStore);
                }

                if (_config.RunMessageBroker)
                {
                    MessageBrokerLauncher.Run();
                    Log.Info("Started Message Broker");
                }

                foreach (var service in _config.ServicesToStart)
                {
                    ParseCommand($"start {service}");
                }


                foreach (var unhandledCommand in _config.InvalidArguments)
                {
                    Log.Error("Unrecognised Command:  {0}", unhandledCommand);
                }


                if (!_config.IsInteractive)
                {
                    if (_launcher.GetRunningServices().Any())
                    {
                        _terminationSignal.WaitOne();
                    }

                    return;
                }

                Log.Info();
                Log.Info("INTERACTIVE MODE - type 'help' for help or 'exit' to EXIT");

                // interactive mode
                while (_running)
                {
                    var x = Console.ReadLine();

                    try
                    {
                        if (x == null || x == "exit" || x == "quit")
                        {
                            break;
                        }

                        if (ParseCommand(x))
                        {
                            continue;
                        }

                        if (x == "help" || x == "h" || x == "")
                        {
                        }
                        else
                        {
                            Log.Error("Didn't understand command {0}", x);
                        }


                        Console.WriteLine();
                        Console.WriteLine("Available Commands");
                        Console.WriteLine("==================");
                        Console.WriteLine("start");
                        Console.WriteLine("  p|pricing - launch a pricing service.");
                        Console.WriteLine("  r|reference - launch a reference service.");
                        Console.WriteLine("  b|blotter - launch a blotter service.");
                        Console.WriteLine("  e|execution - launch a trade execution service.");
                        Console.WriteLine("  a|analytics - launch an analytics service.");
                        Console.WriteLine("kill [name] - kills a service (use status to find names).");
                        Console.WriteLine("status - returns a list of running services.");
                        Console.WriteLine("help - show this page.");
                        Console.WriteLine("exit - close the launcher.");
                        Console.WriteLine();
                    }
                    catch (Exception e)
                    {
                        Log.Error("Error handling request " + e.Message);
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("Exception: " + e.Message);
            }
        }
        public void Run(LauncherConfig config)
        {
            _config = config;

            if (_config.Help)
            {
                Usage();
                return;
            }

            Log.Error();
            Log.Error(@"______                _   _             _____             _           ");
            Log.Error(@"| ___ \              | | (_)           |_   _|           | |          ");
            Log.Error(@"| |_/ /___  __ _  ___| |_ ___   _____    | |_ __ __ _  __| | ___ _ __ ");
            Log.Error(@"|    // _ \/ _` |/ __| __| \ \ / / _ \   | | '__/ _` |/ _` |/ _ \ '__|");
            Log.Error(@"| |\ \  __/ (_| | (__| |_| |\ V /  __/   | | | | (_| | (_| |  __/ |   ");
            Log.Error(@"\_| \_\___|\__,_|\___|\__|_| \_/ \___|   \_/_|  \__,_|\__,_|\___|_|   ");
            Log.Error();
            
            try
            {
                Console.CancelKeyPress += (s, e) =>
                {
                    Log.Info("Termination signal sent.");
                    Stop();
                };

                Serilog.Log.Logger = new LoggerConfiguration()
                    .MinimumLevel.Information()
                    .WriteTo.ColoredConsole()
                    .CreateLogger();

                if (_config.PopulateEventStore)
                    _launcher.InitializeEventStore(_config.EventStoreParameters);

                foreach (var service in _config.ServicesToStart)
                    ParseCommand($"start {service}");

                foreach (var unhandledCommand in _config.InvalidArguments)
                    Log.Error("Unrecognised Command:  {0}", unhandledCommand);

                if (!_config.IsInteractive)
                {
                    if (_launcher.GetRunningServices().Any())
                        _terminationSignal.WaitOne();

                    return;
                }

                Log.Info();
                Log.Info("INTERACTIVE MODE - type 'help' for help or 'exit' to EXIT");

                // interactive mode
                while (_running)
                {
                    var x = Console.ReadLine();

                    try
                    {
                        if (x == null || x == "exit" || x == "quit")
                            break;

                        if (ParseCommand(x)) continue;

                        if (x == "help" || x == "h" || x == "")
                        {
                        }
                        else
                            Log.Error("Didn't understand command {0}", x);


                        Console.WriteLine();
                        Console.WriteLine("Available Commands");
                        Console.WriteLine("==================");
                        Console.WriteLine("start");
                        Console.WriteLine("  p|pricing - launch a pricing service.");
                        Console.WriteLine("  r|reference - launch a reference service.");
                        Console.WriteLine("  b|blotter - launch a blotter service.");
                        Console.WriteLine("  e|execution - launch a trade execution service.");
                        Console.WriteLine("  a|analytics - launch an analytics service.");
                        Console.WriteLine("kill [name] - kills a service (use status to find names).");
                        Console.WriteLine("status - returns a list of running services.");
                        Console.WriteLine("help - show this page.");
                        Console.WriteLine("exit - close the launcher.");
                        Console.WriteLine();
                    }
                    catch (Exception e)
                    {
                        Log.Error("Error handling request " + e.Message);
                        
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error("Exception: " + e.Message);
            }
        }