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(); } Connect( credentials, server, tcpPort); }
private static void StartClusterNode(StartConflictOption opt) { //TODO: Convert to Embedded when I can figure out loading the miniWeb component var runningEventStores = Process.GetProcessesByName("EventStore.ClusterNode"); if (runningEventStores.Length != 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."); default: throw new ArgumentOutOfRangeException(nameof(opt), opt, null); } } if (_process == null) { StartNewProcess(); } }
public EventStoreLauncher( StartConflictOption startConflictOption = StartConflictOption.Connect, ProcessWindowStyle windowStyle = ProcessWindowStyle.Hidden) { _defaultStartOption = startConflictOption; _defaultWindowStyle = windowStyle; }
/// <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); }
//Method to start setting up the EventStore upon executing the program public static void SetupEventStore(StartConflictOption opt = StartConflictOption.Connect) //set default to Connect { //Save the EventStore process in a variable for later use if running var runningEventStores = Process.GetProcessesByName("EventStore.ClusterNode"); //if a process was found, check the parameter options on what to do with the process if (runningEventStores.Length != 0) { switch (opt) { case StartConflictOption.Connect: _process = runningEventStores[0]; //set the process to the EventStore.ClusterNode break; case StartConflictOption.Kill: foreach (var es in runningEventStores) //makes sure that all running processes are killed { es.Kill(); } break; case StartConflictOption.Error: throw new Exception("Conflicting EventStore running."); //Will be thrown if there is already a running EventStore process default: throw new ArgumentOutOfRangeException(nameof(opt), opt, null); } } if (_process == null) { _process = new Process { StartInfo = { UseShellExecute = false, CreateNoWindow = true, FileName = Path, Arguments = Args, Verb = "runas" } }; _process.Start(); } //set default IP endpoint and port (localhost:1113). HTTP uses port 2113, while TCP uses port 1113 var tcp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113); var http = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2113); //Connect to the Event Store Connection = EventStoreConnection.Create(new Uri("tcp://*****:*****@localhost:1113")); Connection.ConnectAsync().Wait(); }
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 tcpEndpoint = new IPEndPoint(server, tcpPort); var settings = ConnectionSettings.Create() .SetDefaultUserCredentials(credentials) .KeepReconnecting() .KeepRetrying() .UseConsoleLogger() //.EnableVerboseLogging() .Build(); Connection = EventStoreConnection.Create(settings, tcpEndpoint, "Default Connection"); if (Connection == null) { Log.Error("EventStore Connection is null - Diagnostic Monitoring will be unavailable."); TeardownEventStore(false); return; } Connection.ConnectAsync().Wait(); int retry = 8; int count = 0; do { try { var r = Connection.ReadStreamEventsForwardAsync("by_event_type", 0, 1, false).Result; return; } catch { //ignore } Thread.Sleep(100); count++; } while (count < retry); throw new Exception("Unable to start Eventstore"); }
public static void SetupEventStore(StartConflictOption opt = StartConflictOption.Connect) { //TODO: Convert to Embedded when I can figure out loading the miniWeb component var runningEventStores = Process.GetProcessesByName("EventStore.ClusterNode"); if (runningEventStores.Length != 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."); default: throw new ArgumentOutOfRangeException(nameof(opt), opt, null); } } if (_process == null) { _process = new Process { StartInfo = { UseShellExecute = false, CreateNoWindow = true, FileName = Path, Arguments = Args, Verb = "runas" } }; _process.Start(); } var tcp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113); var http = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2113); Connection = EventStoreConnection.Create(tcp); Connection.ConnectAsync().Wait(); var pManager = new ProjectionsManager(new NullLogger(), http, TimeSpan.FromSeconds(5)); var creds = new UserCredentials("admin", "changeit"); bool ready = false; int retry = 0; while (!ready) { try { pManager.EnableAsync("$streams", creds).Wait(); pManager.EnableAsync("$by_event_type", creds).Wait(); pManager.EnableAsync("$by_category", creds).Wait(); pManager.EnableAsync("$stream_by_category", creds).Wait(); ready = true; } catch { retry++; if (retry > 8) throw new Exception("EventStore Projection Start Error."); System.Threading.Thread.Sleep(250); } } }
public static void SetupEventStore(StartConflictOption opt = StartConflictOption.Connect) { //TODO: Convert to Embedded when I can figure out loading the miniWeb component var runningEventStores = Process.GetProcessesByName("EventStore.ClusterNode"); if (runningEventStores.Length != 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."); default: throw new ArgumentOutOfRangeException(nameof(opt), opt, null); } } if (_process == null) { _process = new Process { StartInfo = { UseShellExecute = false, CreateNoWindow = true, FileName = Path, Arguments = Args, Verb = "runas" } }; _process.Start(); } var tcp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 1113); var http = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 2113); Connection = EventStoreConnection.Create(tcp); Connection.ConnectAsync().Wait(); var pManager = new ProjectionsManager(new NullLogger(), http, TimeSpan.FromSeconds(5)); var creds = new UserCredentials("admin", "changeit"); bool ready = false; int retry = 0; while (!ready) { try { pManager.EnableAsync("$streams", creds).Wait(); pManager.EnableAsync("$by_event_type", creds).Wait(); pManager.EnableAsync("$by_category", creds).Wait(); pManager.EnableAsync("$stream_by_category", creds).Wait(); ready = true; } catch { retry++; if (retry > 8) { throw new Exception("EventStore Projection Start Error."); } System.Threading.Thread.Sleep(250); } } }
public static void SetupEventStore(StartConflictOption opt = StartConflictOption.Connect) { StartClusterNode(opt); StartConnection(); StartProjections(); }