Example #1
0
        public static bool TryParse(string address, out RoutingHost routinghost)
        {
            routinghost = null;
            if (string.IsNullOrEmpty(address))
            {
                return(false);
            }
            address = address.Trim();
            RoutingHost routingHost = new RoutingHost();
            int         length      = address.Length;

            if (address[0] == '[' && address[length - 1] == ']')
            {
                address = address.Substring(1, length - 2);
            }
            if (IPAddress.TryParse(address, out routingHost.ipAddress))
            {
                if (routingHost.ipAddress.Equals(IPAddress.Any))
                {
                    return(false);
                }
            }
            else
            {
                if (!RoutingHostName.TryParse(address, out routingHost.domain))
                {
                    return(false);
                }
                routingHost.ipAddress = IPAddress.Any;
            }
            routinghost = routingHost;
            return(true);
        }
Example #2
0
        internal static List <T> GetRoutingHostsFromString <T>(string routingHostsString, Func <RoutingHost, T> routingHostWrapperGetter)
        {
            if (routingHostWrapperGetter == null)
            {
                throw new ArgumentNullException("routingHostWrapperGetter");
            }
            List <T> list = new List <T>();
            int      num;

            for (int i = 0; i < routingHostsString.Length; i = num + 1)
            {
                num = routingHostsString.IndexOfAny(RoutingHost.routingHostDelimiters, i);
                if (-1 == num)
                {
                    num = routingHostsString.Length;
                }
                RoutingHost routingHost = RoutingHost.InternalParseRoutingHost(routingHostsString, i, num - i);
                if (routingHost != null)
                {
                    T item = routingHostWrapperGetter(routingHost);
                    if (!list.Contains(item))
                    {
                        list.Add(item);
                    }
                }
            }
            return(list);
        }
		public RoutingOverride(RoutingDomain routingDomain, List<RoutingHost> alternateDeliveryRoutingHosts, DeliveryQueueDomain deliveryQueueDomain)
		{
			if (routingDomain == RoutingDomain.Empty)
			{
				throw new ArgumentException(string.Format("The provided domain '{0}' is RoutingDomain.Empty which isn't valid for RoutingOverride", routingDomain));
			}
			if ((alternateDeliveryRoutingHosts == null || alternateDeliveryRoutingHosts.Count == 0) && deliveryQueueDomain == DeliveryQueueDomain.UseAlternateDeliveryRoutingHosts)
			{
				throw new ArgumentException(string.Format("The provided delivery queue domain value UseAlternateDeliveryRoutingHosts is only valid when you specify alternate delivery hosts.", new object[0]));
			}
			if (alternateDeliveryRoutingHosts != null && alternateDeliveryRoutingHosts.Count != 0 && !string.Equals(routingDomain.Type, "smtp", StringComparison.OrdinalIgnoreCase))
			{
				throw new ArgumentException(string.Format("The routing domain needs to be an SMTP domain if alternate delivery hosts are specified - routingDomain.Type == {0}", routingDomain.Type));
			}
			this.routingDomain = routingDomain;
			this.alternateDeliveryRoutingHosts = RoutingHost.ConvertRoutingHostsToString<RoutingHost>(alternateDeliveryRoutingHosts, (RoutingHost host) => host);
			this.deliveryQueueDomain = deliveryQueueDomain;
		}
Example #4
0
 public bool Equals(RoutingHost value)
 {
     if (object.ReferenceEquals(this, value))
     {
         return(true);
     }
     if (value == null)
     {
         return(false);
     }
     if (this.IsIPAddress != value.IsIPAddress)
     {
         return(false);
     }
     if (this.IsIPAddress)
     {
         return(this.ipAddress.Equals(value.ipAddress));
     }
     return(this.domain.Equals(value.domain));
 }
Example #5
0
        internal static string ConvertRoutingHostsToString <T>(IList <T> routingHostWrappers, Func <T, RoutingHost> routingHostGetter)
        {
            if (routingHostWrappers == null || routingHostWrappers.Count == 0 || routingHostGetter == null)
            {
                return(string.Empty);
            }
            StringBuilder stringBuilder = new StringBuilder();
            int           num           = 0;

            foreach (T arg in routingHostWrappers)
            {
                RoutingHost routingHost = routingHostGetter(arg);
                num++;
                stringBuilder.Append(routingHost.ToString());
                if (num < routingHostWrappers.Count)
                {
                    stringBuilder.Append(',');
                }
            }
            return(stringBuilder.ToString());
        }
Example #6
0
        private static RoutingHost InternalParseRoutingHost(string routingHostString, int startPos, int count)
        {
            string text = routingHostString.Substring(startPos, count);

            text = text.Trim();
            if (text.Length == 0)
            {
                return(null);
            }
            RoutingHost result;

            try
            {
                if ('[' != text[0])
                {
                    result = RoutingHost.Parse(text);
                }
                else if (']' != text[count - 1])
                {
                    result = null;
                }
                else
                {
                    result = RoutingHost.Parse(text.Substring(1, count - 2));
                }
            }
            catch (ArgumentException)
            {
                result = null;
            }
            catch (FormatException)
            {
                result = null;
            }
            return(result);
        }
Example #7
0
        public override bool Equals(object comparand)
        {
            RoutingHost routingHost = comparand as RoutingHost;

            return(routingHost != null && this.Equals(routingHost));
        }