Beispiel #1
0
        public static async Task <int> Main(bool version            = false, FileInfo?log              = null, bool whatIf             = false,
                                            string[]?command        = null, string host                = "localhost", int tcpPort      = 1113, int httpPort             = 2113,
                                            int timeout             = Timeout.Infinite, int readWindow = 2000, int writeWindow         = 2000, int pingWindow           = 2000,
                                            bool reconnect          = true, bool useTls                = false, bool tlsValidateServer = false, string connectionString = "",
                                            StatsFormat statsFormat = StatsFormat.Csv)
        {
            Log.Logger = EventStoreLoggerConfiguration.ConsoleLog;

            try {
                var logsDirectory = log?.FullName ?? Locations.DefaultTestClientLogDirectory;
                EventStoreLoggerConfiguration.Initialize(logsDirectory, "client", LogConsoleFormat.Plain,
                                                         1024 * 1024 * 1024, RollingInterval.Day, 31, false);
                var statsLog = statsFormat == StatsFormat.Csv
                                        ? TestClientCsvLoggerConfiguration.Initialize(logsDirectory, "client")
                                        : Log.ForContext(Serilog.Core.Constants.SourceContextPropertyName, "REGULAR-STATS-LOGGER");

                var options = new ClientOptions {
                    Timeout           = timeout,
                    HttpPort          = httpPort,
                    Host              = host,
                    TcpPort           = tcpPort,
                    Reconnect         = reconnect,
                    PingWindow        = pingWindow,
                    ReadWindow        = readWindow,
                    WriteWindow       = writeWindow,
                    UseTls            = useTls,
                    TlsValidateServer = tlsValidateServer,
                    ConnectionString  = connectionString,
                    Command           = command ?? Array.Empty <string>(),
                    OutputCsv         = statsFormat == StatsFormat.Csv,
                    StatsLog          = statsLog
                };

                var hostedService = new TestClientHostedService(options);

                if (whatIf)
                {
                    await Console.Out.WriteLineAsync(options.ToString());
                }

                if (version || whatIf)
                {
                    await Console.Out.WriteLineAsync(VersionInfo.Text);

                    await Console.Out.FlushAsync();

                    return(0);
                }
                await CreateHostBuilder(hostedService, Environment.GetCommandLineArgs())
                .RunConsoleAsync(options => options.SuppressStatusMessages = true, hostedService.CancellationToken);

                return(await hostedService.Exited);
            } catch (Exception ex) {
                Log.Fatal(ex, "Host terminated unexpectedly.");
                return(1);
            } finally {
                Log.CloseAndFlush();
            }
        }
Beispiel #2
0
 private static IHostBuilder CreateHostBuilder(TestClientHostedService hostedService, string[] args) =>
 new HostBuilder()
 .ConfigureHostConfiguration(builder =>
                             builder.AddEnvironmentVariables("DOTNET_").AddCommandLine(args ?? Array.Empty <string>()))
 .ConfigureAppConfiguration(builder =>
                            builder.AddEnvironmentVariables().AddCommandLine(args ?? Array.Empty <string>()))
 .ConfigureServices(services => services.AddSingleton <IHostedService>(hostedService))
 .ConfigureLogging(logging => logging.AddSerilog());
Beispiel #3
0
        public static async Task <int> Main(string[] args)
        {
            try {
                var hostedService = new TestClientHostedService(args);
                await CreateHostBuilder(hostedService, args)
                .RunConsoleAsync(options => options.SuppressStatusMessages = true, hostedService.CancellationToken);

                return(await hostedService.Exited);
            } catch (Exception ex) {
                Log.Fatal(ex, "Host terminated unexpectedly.");
                return(1);
            } finally {
                Log.CloseAndFlush();
            }
        }