示例#1
0
        public IEnumerable <IContactPoint> ParseContactPoints(IEnumerable <object> providedContactPoints)
        {
            var result = new HashSet <IContactPoint>();

            foreach (var contactPoint in providedContactPoints)
            {
                IContactPoint parsedContactPoint;

                switch (contactPoint)
                {
                case IContactPoint typedContactPoint:
                    parsedContactPoint = typedContactPoint;
                    break;

                case IPEndPoint ipEndPointContactPoint:
                    parsedContactPoint = new IpLiteralContactPoint(ipEndPointContactPoint, _serverNameResolver);
                    break;

                case IPAddress ipAddressContactPoint:
                    parsedContactPoint = new IpLiteralContactPoint(ipAddressContactPoint, _protocolOptions, _serverNameResolver);
                    break;

                case string contactPointText:
                {
                    if (IPAddress.TryParse(contactPointText, out var ipAddress))
                    {
                        parsedContactPoint = new IpLiteralContactPoint(ipAddress, _protocolOptions, _serverNameResolver);
                    }
                    else
                    {
                        parsedContactPoint = new HostnameContactPoint(
                            _dnsResolver,
                            _protocolOptions,
                            _serverNameResolver,
                            _keepContactPointsUnresolved,
                            contactPointText);
                    }

                    break;
                }

                default:
                    throw new InvalidOperationException("Contact points should be either string or IPEndPoint instances");
                }

                if (result.Contains(parsedContactPoint))
                {
                    Cluster.Logger.Warning("Found duplicate contact point: {0}. Ignoring it.", contactPoint.ToString());
                    continue;
                }

                result.Add(parsedContactPoint);
            }

            return(result);
        }
 private bool TypedEquals(IpLiteralContactPoint other)
 {
     return(object.Equals(_ipEndPoint, other._ipEndPoint) && object.Equals(_ipAddress, other._ipAddress));
 }