Example #1
0
        public static T SelectOne <T>(this IEndpointResolver resolver, Func <AmqpTcpEndpoint, T> selector)
        {
            var t          = default(T);
            var exceptions = new List <Exception>();

            foreach (AmqpTcpEndpoint ep in resolver.All())
            {
                try
                {
                    t = selector(ep);
                    if (!t.Equals(default(T)))
                    {
                        return(t);
                    }
                }
                catch (Exception e)
                {
                    exceptions.Add(e);
                }
            }

            if (Object.Equals(t, default(T)) && exceptions.Count > 0)
            {
                throw new AggregateException(exceptions);
            }

            return(t);
        }
Example #2
0
        public static T SelectOne <T>(this IEndpointResolver resolver, Func <AmqpTcpEndpoint, T> selector)
        {
            var       t         = default(T);
            Exception exception = null;

            foreach (var ep in resolver.All())
            {
                try
                {
                    t = selector(ep);
                    if (t.Equals(default(T)) == false)
                    {
                        return(t);
                    }
                }
                catch (Exception e)
                {
                    exception = e;
                }
            }

            if (Object.Equals(t, default(T)) && exception != null)
            {
                throw exception;
            }

            return(t);
        }