/// <summary> /// Setup EventStore based on the connection settings provided by the caller /// </summary> /// <remarks> /// <see cref="StreamStoreConnectionSettings"/> and <see cref="StreamStoreConnectionSettingsBuilder"/> for options to configure: /// <list type="bullet"> /// <item> /// <description>A single server using an IPAddress and TCP Port</description> /// </item> /// <item> /// <description>A cluster using a DNS name and HTTP Port</description> /// </item> /// <item> /// <description>A cluster using one or more gossip seed IPAddresses and an HTTP Port</description> /// </item> /// </list> /// </remarks> /// <param name="connectionSettings"><see cref="StreamStoreConnectionSettings"/> defined by the caller.</param> public EventStoreConnectionManager(StreamStoreConnectionSettings connectionSettings) { if (connectionSettings.IsSingleConnection) { Connect(connectionSettings.UserCredentials, connectionSettings.SingleServerIpEndPoint, connectionSettings.UseTlsConnection, connectionSettings.TargetHost, connectionSettings.ValidateServer, connectionSettings.VerboseLogging); } else if (connectionSettings.IsDnsClusterConnection) { Connect(connectionSettings.UserCredentials, connectionSettings.ClusterDns, connectionSettings.NetworkIpPort, connectionSettings.UseTlsConnection, connectionSettings.TargetHost, connectionSettings.ValidateServer, connectionSettings.VerboseLogging); } else if (connectionSettings.IsGossipSeedClusterConnection) { Connect(connectionSettings.UserCredentials, connectionSettings.GossipSeeds, connectionSettings.UseTlsConnection, connectionSettings.TargetHost, connectionSettings.ValidateServer, connectionSettings.VerboseLogging); } else { throw new EventStoreConnectionException( "EventStoreConnectionManager invalid settings. Minimum values: UserCredentials, SingleServerIpAddress, ClusterDns, or GossipSeeds required."); } StartEventStore(); }
/// <summary> /// Start the EventStore executable explicit single server options, and then connect /// </summary> /// <param name="installPath">DirectoryInfo: EventStore executable path</param> /// <param name="args">string: EventStore CLI arguments</param> /// <param name="credentials">UserCredentials: Username-Password pair for authentication and authorization.</param> /// <param name="server">IPAddress: EventStore Server </param> /// <param name="tcpPort">int: Network port used for Tcp communication.</param> /// <param name="windowStyle">ProcessWindowStyle: How the EventStore executable window will be displayed or hidden.</param> /// <param name="opt">StartConflictOption Enum: What to do if a conflicting EventStore process is already running.</param> public void SetupEventStore( DirectoryInfo installPath, string args, UserCredentials credentials, IPAddress server, int tcpPort, ProcessWindowStyle windowStyle, StartConflictOption opt) { Ensure.NotNullOrEmpty(args, "args"); Ensure.NotNull(credentials, "credentials"); var fullPath = Path.Combine(installPath.FullName, "EventStore.ClusterNode.exe"); var runningEventStores = Process.GetProcessesByName("EventStore.ClusterNode"); if (runningEventStores.Count() != 0) { switch (opt) { case StartConflictOption.Connect: _process = runningEventStores[0]; break; case StartConflictOption.Kill: foreach (var es in runningEventStores) { es.Kill(); } break; case StartConflictOption.Error: throw new Exception("Conflicting EventStore running."); } } if (_process == null) { _process = new Process { StartInfo = { WindowStyle = windowStyle, UseShellExecute = true, CreateNoWindow = false, WorkingDirectory = installPath.FullName, FileName = fullPath, Arguments = args, Verb = "runas" } }; _process.Start(); } var sscSettings = StreamStoreConnectionSettings.Create() .SetUserCredentials(credentials) .SetSingleServerIpEndPoint(new IPEndPoint(server, tcpPort)) .SetVerboseLogging(false); var eventStoreConnectionManager = new EventStoreConnectionManager(sscSettings); Connection = eventStoreConnectionManager.Connection; }