public EventStoreService(IPAddress address, EventStoreServiceConfiguration configuration, Logger logger)
        {
            this.address        = address;
            this.configuration  = configuration;
            this.logger         = logger;
            this.processes      = new Dictionary <Process, Tuple <string, DateTime> >();
            this.eventStorePath = this.GetEventStorePath(configuration);

            this.restartDelay  = this.GetRestartDelay(configuration);
            this.restartWindow = this.GetRestartWindow(configuration);

            this.DumpConfig();
        }
        private string GetEventStorePath(EventStoreServiceConfiguration config)
        {
            var configPath = config.EventStorePath;

            if (string.IsNullOrWhiteSpace(configPath))
            {
                return(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "eventstore", ExecutableName));
            }

            if (Path.IsPathRooted(configPath))
            {
                return(configPath);
            }

            return(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, configPath, ExecutableName));
        }
        private TimeSpan GetRestartWindow(EventStoreServiceConfiguration config)
        {
            var windowInMs = config.RestartWindowMs.HasValue ? config.RestartWindowMs.Value : 1000 * 30;

            return(new TimeSpan(0, 0, 0, 0, windowInMs));
        }
 private int GetRestartDelay(EventStoreServiceConfiguration config)
 {
     return(config.RestartDelayMs.HasValue ? config.RestartDelayMs.Value : 1000 * 3);
 }
        private string BuildNodeArguments(
            InternalNode currentNode,
            EventStoreServiceConfiguration configuration,
            int nodeCount,
            IPAddress detectedIpAddress)
        {
            // Based on https://github.com/eventstore/eventstore/wiki/Setting-Up-OSS-Cluster
            var builder = new StringBuilder();

            var internalIpAddress = GetInternalIpAddress(currentNode, detectedIpAddress);

            var externalIpAddress = GetExternalIpAddress(currentNode, detectedIpAddress);

            builder.AppendFormat("--db={0} ", currentNode.DbPath);
            builder.AppendFormat("--log={0} ", currentNode.LogPath);
            builder.AppendFormat("--int-ip={0} ", internalIpAddress);
            builder.AppendFormat("--ext-ip={0} ", externalIpAddress);

            if (!string.IsNullOrWhiteSpace(currentNode.InternalHttpPrefixes))
            {
                builder.AppendFormat("--int-http-prefixes=\"{0}\" ", currentNode.InternalHttpPrefixes);
                builder.AppendFormat("---add-interface-prefixes=false ");
            }
            if (!string.IsNullOrWhiteSpace(currentNode.ExternalHttpPrefixes))
            {
                builder.AppendFormat("--ext-http-prefixes=\"{0}\" ", currentNode.ExternalHttpPrefixes);
                builder.AppendFormat("---add-interface-prefixes=false ");
            }

            if (!string.IsNullOrWhiteSpace(currentNode.HttpPrefix))
            {
                Console.WriteLine("WARNING: HTTPPrefix is no longer used, use -int-http-prefixes and -ext-http-prefixes if non-standard behaviour is required.");
            }

            builder.AppendFormat("--int-tcp-port={0} ", currentNode.IntTcpPort);
            builder.AppendFormat("--ext-tcp-port={0} ", currentNode.ExtTcpPort);
            builder.AppendFormat("--int-http-port={0} ", currentNode.IntHttpPort);
            builder.AppendFormat("--ext-http-port={0} ", currentNode.ExtHttpPort);

            builder.AppendFormat(" {0} {1} ", configuration.AdditionalFlags, currentNode.AdditionalFlags);

            builder.AppendFormat("--cluster-size={0} ", nodeCount);

            builder.AppendFormat("--discover-via-dns=false ");

            var gossipSeeds = new List <string>();

            foreach (var otherNode in configuration.InternalNodes.Cast <InternalNode>().Where(n => !ReferenceEquals(n, currentNode)))
            {
                gossipSeeds.Add(string.Format("{0}:{1}", GetInternalIpAddress(otherNode, detectedIpAddress), otherNode.IntHttpPort));
            }

            foreach (var externalNode in configuration.ExternalNodes.Cast <ExternalNode>())
            {
                gossipSeeds.Add(string.Format("{0}:{1}", externalNode.IpAddress, externalNode.GossipPort));
            }

            if (gossipSeeds.Any())
            {
                builder.AppendFormat("--gossip-seed={0} ", String.Join(",", gossipSeeds));
            }

            return(builder.ToString());
        }
 public ServiceWrapper(EventStoreServiceConfiguration configuration)
 {
     _configuration = configuration;
     _processes = new List<Process>();
 }