Beispiel #1
0
        public void Start()
        {
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                _reset.Set();
            };

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

            var config = ServiceConfiguration.FromArgs(_args);

            try
            {
                using (var connectionFactory = BrokerConnectionFactory.Create(config.Broker))
                {
                    var brokerStream = connectionFactory.GetBrokerStream();


                    var esFactory = _factory as IServiceHostFactoryWithEventStore;

                    if (esFactory != null)
                    {
                        // TODO TIDY

                        var eventStoreConnection = GetEventStoreConnection(config.EventStore);
                        var mon      = new ConnectionStatusMonitor(eventStoreConnection);
                        var esStream = mon.GetEventStoreConnectedStream(eventStoreConnection);
                        eventStoreConnection.ConnectAsync().Wait();

                        using (esFactory.Initialize(brokerStream, esStream))
                        {
                            connectionFactory.Start();

                            _reset.WaitOne();
                        }
                    }
                    else
                    {
                        using (_factory.Initialize(brokerStream))
                        {
                            connectionFactory.Start();
                            _reset.WaitOne();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Error connecting to broker");
            }
        }
Beispiel #2
0
        public static App Create(string[] args, IServiceHostFactory factory)
        {
            var config = ServiceConfiguration.FromArgs(args);

            switch (factory)
            {
            case IServiceHostFactoryWithBroker withBroker:
                return(new BrokerOnlyApp(config, withBroker));

            case IServiceHostFactoryWithEventStore withEventStore:
                return(new EventStoreApp(config, withEventStore));

            default:
                throw new ArgumentException($"Unsupported service host factory type: '{factory.GetType().FullName}'", nameof(factory));
            }
        }
Beispiel #3
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);
        }
Beispiel #4
0
 public static void Main(string[] args)
 {
     _serviceConfiguration = ServiceConfiguration.FromArgs(args);
     BuildWebHost(args).Run();
 }