Beispiel #1
0
        /// <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>
        /// 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;
        }