/// <summary> /// Start the EventStore executable explicit single server options, and then connect /// </summary> /// <param name="config">EsDb Config Section</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 EventStoreConnectionManager SetupEventStore( EsdbConfig config, ProcessWindowStyle windowStyle, StartConflictOption opt) { var fullPath = Path.Combine(config.Path, "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 = config.WorkingDir, FileName = fullPath, Arguments = config.Args, Verb = "runas" } }; _process.Start(); } ESConnection = new EventStoreConnectionManager(config); return(ESConnection); }
/// <summary> /// Setup EventStore based on the config settings provided by the caller /// </summary> /// <param name="config"><see cref="EsdbConfig"/> defined by the caller.</param> public EventStoreConnectionManager(EsdbConfig config) { ESConnection = new EventStoreConnectionWrapper(EventStoreConnection.Create(config.ConnectionString)); //TODO: The connection settings to keep retrying in the EventStore code circumvents this loop of 8 tries never returning from the Connect call. Connection.Connect(); const int retry = 8; var count = 0; do { try { Connection.ReadStreamForward("by_event_type", 0, 1); return; } catch { } //ignore Thread.Sleep(100); count++; } while (count < retry); throw new Exception("Unable to start EventStore"); }
/// <summary> /// Start the EventStore executable explicit single server options, and then connect /// </summary> /// <param name="config">EsDb Config Section</param> public EventStoreConnectionManager SetupEventStore(EsdbConfig config) { return(SetupEventStore(config, windowStyle: _defaultWindowStyle, opt: _defaultStartOption)); }