private static bool ParseDoubleForm(string[] daemonAddress, out DaemonConfig endPoint)
        {
            endPoint = new DaemonConfig();
            EndPoint udpEndpoint = null;
            EndPoint tcpEndpoint = null;
            IDictionary <string, string> addressMap = new Dictionary <string, string>();

            string[] address1 = daemonAddress[0].Split(_addressPortDelimiter); // tcp:<hostname or address>:2000 udp:<hostname or address>:2001
            string[] address2 = daemonAddress[1].Split(_addressPortDelimiter);

            addressMap[address1[0]] = address1[1] + _addressPortDelimiter + address1[2];
            addressMap[address2[0]] = address2[1] + _addressPortDelimiter + address2[2];

            string udpAddress = null;
            string tcpAddress = null;

            udpAddress = addressMap[_udpKey];
            tcpAddress = addressMap[_tcpKey];

            if (TryParse(udpAddress, out udpEndpoint) && TryParse(tcpAddress, out tcpEndpoint))
            {
                endPoint._udpEndpoint = udpEndpoint;
                endPoint._tcpEndpoint = tcpEndpoint;
                _logger.InfoFormat("Using custom daemon address for UDP {0}:{1} and TCP {2}:{3}", endPoint.UDPEndpoint.Address.ToString(), endPoint.UDPEndpoint.Port, endPoint.TCPEndpoint.Address.ToString(), endPoint.TCPEndpoint.Port);
                return(true);
            }

            return(false);
        }
        internal static DaemonConfig ParsEndpoint(string daemonAddress)
        {
            DaemonConfig daemonEndPoint;

            if (!IPEndPointExtension.TryParse(daemonAddress, out daemonEndPoint))
            {
                daemonEndPoint = new DaemonConfig();
                _logger.InfoFormat("The given daemonAddress ({0}) is invalid, using default daemon UDP and TCP address {1}:{2}.", daemonAddress, daemonEndPoint.UDPEndpoint.Address.ToString(), daemonEndPoint.UDPEndpoint.Port);
            }
            return(daemonEndPoint);
        }
        private static bool TryParseDaemonAddress(string[] daemonAddress, out DaemonConfig endPoint)
        {
            endPoint = null;
            if (daemonAddress.Length == 1)
            {
                return(ParseSingleForm(daemonAddress, out endPoint));
            }
            else if (daemonAddress.Length == 2)
            {
                return(ParseDoubleForm(daemonAddress, out endPoint));
            }

            return(false);
        }
        private static bool ParseSingleForm(string[] daemonAddress, out DaemonConfig endPoint)
        {
            EndPoint udpEndpoint = null;

            endPoint = new DaemonConfig();

            if (TryParse(daemonAddress[0], out udpEndpoint))
            {
                endPoint._udpEndpoint = udpEndpoint;
                endPoint._tcpEndpoint = udpEndpoint;
                _logger.InfoFormat("Using custom daemon address for UDP and TCP: {0}:{1}", endPoint.UDPEndpoint.Address.ToString(), endPoint.UDPEndpoint.Port);
                return(true);
            }
            else
            {
                return(false);
            }
        }
        /// <summary>
        /// Tries to parse a string to <see cref="DaemonConfig"/>.
        /// </summary>
        /// <param name="daemonAddress">The input string.</param>
        /// <param name="daemonEndPoint">The parsed <see cref="DaemonConfig"/> instance.</param>
        /// <returns></returns>
        public static bool TryParse(string daemonAddress, out DaemonConfig daemonEndPoint)
        {
            daemonEndPoint = null;

            if (string.IsNullOrEmpty(daemonAddress))
            {
                return(false);
            }

            try
            {
                string[] ep = daemonAddress.Split(_addressDelimiter);
                return(TryParseDaemonAddress(ep, out daemonEndPoint));
            }
            catch (Exception e)
            {
                _logger.Error(e, "Invalid daemon address. ({0})", daemonAddress);
                return(false);
            }
        }