-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.cs
More file actions
70 lines (57 loc) · 2.01 KB
/
Client.cs
File metadata and controls
70 lines (57 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System;
using System.Net;
using System.Runtime.CompilerServices;
using System.Threading;
using EventStore.ClientAPI;
using EventStore.ClientAPI.SystemData;
using EventStore.TestClientAPI.Commands;
namespace EventStore.TestClientAPI
{
public class Client
{
public readonly ClientOptions Options;
private readonly CommandsProcessor _commands = new CommandsProcessor();
public Client(ClientOptions options)
{
Options = options;
RegisterProcessors();
}
public int Run()
{
return Execute(Options.Command);
}
private int Execute(string[] args)
{
int exitCode;
CommandProcessorContext context = new CommandProcessorContext(this,new ManualResetEventSlim());
if (_commands.TryProcess(context, args, out exitCode))
{
return exitCode;
}
return 1;
}
private void RegisterProcessors()
{
_commands.Register(new WriteFloodProcessor());
}
public IEventStoreConnection CreateEventStoreConnection()
{
IPEndPoint endPoint = new IPEndPoint(IPAddress.Loopback, Options.TcpPort);
var connectionStringBuilder = ConnectionSettings
.Create()
//.UseConsoleLogger()
//.EnableVerboseLogging()
//.LimitRetriesForOperationTo(1)
.SetDefaultUserCredentials(new UserCredentials(Options.Username, Options.Password));
IEventStoreConnection connection = EventStoreConnection.Create(connectionStringBuilder, endPoint);
using (Statistics.OnStartConnect())
{
if (!connection.ConnectAsync().Wait(Options.ConnectTimeout))
{
throw new TimeoutException(string.Format("Took longer than {0} connect to Event Store.", Options.ConnectTimeout));
}
}
return connection;
}
}
}