Esempio n. 1
0
 public RoutingDomain(string domain, string type)
 {
     if (string.Equals(type, "smtp", StringComparison.OrdinalIgnoreCase))
     {
         if (!RoutingAddress.IsValidDomain(domain))
         {
             throw new FormatException(string.Format("The format of the specified domain '{0}' isn't valid", domain ?? string.Empty));
         }
     }
     else
     {
         if (string.IsNullOrEmpty(type))
         {
             throw new FormatException("A null or empty routing type isn't valid");
         }
         if (string.IsNullOrEmpty(domain))
         {
             throw new FormatException("A null or empty domain isn't valid");
         }
         if (type.IndexOfAny(RoutingDomain.CharactersNotAllowedInType) != -1)
         {
             throw new FormatException(string.Format("Domain type '{0}' contains at least one invalid character. You can't use the following characters when specifying domain types: '{1}'", type, RoutingDomain.CharactersNotAllowedInType));
         }
     }
     this.domain = type + RoutingDomain.Separator + domain;
 }
Esempio n. 2
0
        private static bool TryParse(string domainRepresentation, out string domain)
        {
            domain = string.Empty;
            if (string.IsNullOrEmpty(domainRepresentation))
            {
                return(false);
            }
            int num = domainRepresentation.IndexOf(RoutingDomain.Separator);

            if (num != -1)
            {
                string text  = domainRepresentation.Substring(0, num);
                string value = domainRepresentation.Substring(num + 1);
                if (string.IsNullOrEmpty(text) || string.IsNullOrEmpty(value) || text.IndexOfAny(RoutingDomain.CharactersNotAllowedInType) != -1)
                {
                    return(false);
                }
                if (text.Equals("smtp", StringComparison.OrdinalIgnoreCase) && !RoutingAddress.IsValidDomain(value))
                {
                    return(false);
                }
                domain = domainRepresentation;
            }
            else
            {
                if (!RoutingAddress.IsValidDomain(domainRepresentation))
                {
                    return(false);
                }
                domain = "smtp:" + domainRepresentation;
            }
            return(true);
        }