public IEnumerable <ServiceLocation> GetServiceLocations(string serviceName,
                                                                 string globalScope = null)
        {
            if (globalScope == null)
            {
                globalScope = _globalPrefix;
            }

            IEnumerable <KeyValuePair <string, string> > keyValuePairs =
                GetServiceEntries(globalScope, serviceName);

            foreach (var kvp in keyValuePairs)
            {
                ServiceLocation serviceLocation = Parse(kvp.Key);

                yield return(serviceLocation);
            }
        }
        public int GetTotalEndpointCount(out int distinctServiceCount)
        {
            IEnumerable <KeyValuePair <string, string> > keyValuePairs = GetServiceEntries();

            var all = new List <ServiceLocation>();

            foreach (var kvp in keyValuePairs)
            {
                ServiceLocation serviceLocation = Parse(kvp.Key);

                all.Add(serviceLocation);
            }

            distinctServiceCount = all.Select(s => s.ServiceName).Distinct().Count();
            int endPointCount = all.Select(s => $"{s.HostName}:{s.Port}").Distinct().Count();

            return(endPointCount);
        }
        private ServiceLocation Parse(string key)
        {
            string[] components = key.Split('/');

            string serviceName = components[2];
            string hostName    = components[3];
            string portStr     = components[4];

            if (!int.TryParse(portStr, out var port))
            {
                throw new InvalidOperationException($"Cannot parse {portStr} to int");
            }

            string protocol = components[5];

            bool useTls = protocol == "https";

            ServiceLocation serviceLocation = new ServiceLocation(
                serviceName, hostName, port, useTls, _globalPrefix);

            return(serviceLocation);
        }
示例#4
0
 protected bool Equals(ServiceLocation other)
 {
     return(Scope == other.Scope && ServiceName == other.ServiceName &&
            HostName == other.HostName && Port == other.Port);
 }