Ejemplo n.º 1
0
 internal static Utils.EntryType ValidateAddressEntrySyntax(string address)
 {
     try
     {
         RoutingAddress.Parse(address);
         return(Utils.EntryType.SmtpAddress);
     }
     catch (FormatException)
     {
     }
     try
     {
         SmtpDomain.Parse(address);
         return(Utils.EntryType.Domain);
     }
     catch (FormatException)
     {
     }
     if (address == "*")
     {
         return(Utils.EntryType.WildCardedDomain);
     }
     if (address.StartsWith("*.") && address.Length > 2)
     {
         SmtpDomain.Parse(address.Substring(2, address.Length - 2));
         return(Utils.EntryType.WildCardedDomain);
     }
     throw new FormatException(Strings.AddressRewriteUnrecognizedAddress);
 }
        protected override UIValidationError[] GetValidationErrors()
        {
            UIValidationError uivalidationError = null;

            if (!this.clearingError)
            {
                if (this.customDomainRadioButton.Checked)
                {
                    if (string.IsNullOrEmpty(this.customDomainTextBox.Text))
                    {
                        uivalidationError = new UIValidationError(Strings.ErrorDomainPartCannotBeEmpty, this.customDomainTextBox);
                        goto IL_8F;
                    }
                    try
                    {
                        SmtpDomain.Parse(this.customDomainTextBox.Text);
                        goto IL_8F;
                    }
                    catch (FormatException ex)
                    {
                        uivalidationError = new UIValidationError(new LocalizedString(ex.Message), this.customDomainTextBox);
                        goto IL_8F;
                    }
                }
                if (string.IsNullOrEmpty(this.acceptedDomainPickerLauncherTextBox.Text))
                {
                    uivalidationError = new UIValidationError(Strings.ErrorDomainPartCannotBeEmpty, this.acceptedDomainPickerLauncherTextBox);
                }
            }
IL_8F:
            if (uivalidationError != null)
            {
                return(new UIValidationError[]
                {
                    uivalidationError
                });
            }
            return(UIValidationError.None);
        }
Ejemplo n.º 3
0
 public static object ConvertFromString(string item, Type type)
 {
     if (!string.IsNullOrEmpty(item))
     {
         type = (type ?? item.GetType());
         if (type == typeof(ExchangeObjectVersion))
         {
             return(new ExchangeObjectVersion(long.Parse(item)));
         }
         if (typeof(Enum).IsAssignableFrom(type))
         {
             return(Enum.Parse(type, item));
         }
         if (type == typeof(ADObjectId))
         {
             return(new ADObjectId(SearchHelper.ConvertFromString <byte[]>(item)));
         }
         if (type == typeof(ProxyAddressCollection))
         {
             ProxyAddressCollection proxyAddressCollection = new ProxyAddressCollection();
             foreach (string item2 in item.Split(new char[]
             {
                 ','
             }, StringSplitOptions.RemoveEmptyEntries))
             {
                 proxyAddressCollection.Add(SearchHelper.ConvertFromString <ProxyAddress>(item2));
             }
             return(proxyAddressCollection);
         }
         if (type == typeof(OrganizationId))
         {
             OrganizationId result;
             if (OrganizationId.TryCreateFromBytes(SearchHelper.ConvertFromString <byte[]>(item), Encoding.Unicode, out result))
             {
                 return(result);
             }
         }
         else
         {
             if (type == typeof(string))
             {
                 return(item);
             }
             if (type == typeof(ProxyAddress))
             {
                 return(ProxyAddress.Parse(item));
             }
             if (type == typeof(SmtpAddress))
             {
                 return(new SmtpAddress(SearchHelper.ConvertFromString <byte[]>(item)));
             }
             if (type == typeof(Guid))
             {
                 return(new Guid(item));
             }
             if (type == typeof(SmtpDomain))
             {
                 return(SmtpDomain.Parse(item));
             }
             if (type == typeof(SecurityIdentifier))
             {
                 return(new SecurityIdentifier(item));
             }
             if (type == typeof(byte[]))
             {
                 return(Convert.FromBase64String(item));
             }
             return(ValueConvertor.ConvertValueFromString(item, type, null));
         }
     }
     return(null);
 }
Ejemplo n.º 4
0
        protected static object GetSingleProperty(object prop, Type type)
        {
            if (prop == null)
            {
                return(null);
            }
            object obj = null;

            if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>))
            {
                obj = MockObjectCreator.GetSingleProperty(prop, type.GetGenericArguments()[0]);
            }
            else if (type == typeof(ADObjectId) && prop is PSObject)
            {
                obj = new ADObjectId(((PSObject)prop).Members["DistinguishedName"].Value.ToString(), new Guid(((PSObject)prop).Members["ObjectGuid"].Value.ToString()));
            }
            else if (type == typeof(EnhancedTimeSpan))
            {
                obj = EnhancedTimeSpan.Parse(prop.ToString());
            }
            else if (type == typeof(Unlimited <EnhancedTimeSpan>))
            {
                obj = Unlimited <EnhancedTimeSpan> .Parse(prop.ToString());
            }
            else if (type == typeof(ByteQuantifiedSize))
            {
                obj = ByteQuantifiedSize.Parse(prop.ToString());
            }
            else if (type == typeof(Unlimited <ByteQuantifiedSize>))
            {
                obj = Unlimited <ByteQuantifiedSize> .Parse(prop.ToString());
            }
            else if (type == typeof(Unlimited <int>))
            {
                obj = Unlimited <int> .Parse(prop.ToString());
            }
            else if (type == typeof(ProxyAddress))
            {
                obj = ProxyAddress.Parse(prop.ToString());
            }
            else if (type == typeof(SmtpAddress))
            {
                obj = new SmtpAddress(prop.ToString());
            }
            else if (type == typeof(SmtpDomain))
            {
                obj = SmtpDomain.Parse(prop.ToString());
            }
            else if (type == typeof(CountryInfo))
            {
                obj = CountryInfo.Parse(prop.ToString());
            }
            else if (type == typeof(SharingPolicyDomain))
            {
                obj = SharingPolicyDomain.Parse(prop.ToString());
            }
            else if (type == typeof(ApprovedApplication))
            {
                obj = ApprovedApplication.Parse(prop.ToString());
            }
            else if (type == typeof(SmtpDomainWithSubdomains))
            {
                obj = SmtpDomainWithSubdomains.Parse(prop.ToString());
            }
            else if (type == typeof(UMLanguage))
            {
                obj = UMLanguage.Parse(prop.ToString());
            }
            else if (type == typeof(UMSmartHost))
            {
                obj = UMSmartHost.Parse(prop.ToString());
            }
            else if (type == typeof(ScheduleInterval))
            {
                obj = ScheduleInterval.Parse(prop.ToString());
            }
            else if (type == typeof(NumberFormat))
            {
                obj = NumberFormat.Parse(prop.ToString());
            }
            else if (type == typeof(DialGroupEntry))
            {
                obj = DialGroupEntry.Parse(prop.ToString());
            }
            else if (type == typeof(CustomMenuKeyMapping))
            {
                obj = CustomMenuKeyMapping.Parse(prop.ToString());
            }
            else if (type == typeof(HolidaySchedule))
            {
                obj = HolidaySchedule.Parse(prop.ToString());
            }
            else if (type == typeof(UMTimeZone))
            {
                obj = UMTimeZone.Parse(prop.ToString());
            }
            else if (type == typeof(ServerVersion))
            {
                obj = ServerVersion.ParseFromSerialNumber(prop.ToString());
            }
            else if (type == typeof(X509Certificate2))
            {
                obj = new X509Certificate2(((PSObject)prop).Members["RawData"].Value as byte[]);
            }
            else if (type == typeof(LocalizedString))
            {
                obj = new LocalizedString(prop.ToString());
            }
            else if (type == typeof(ExchangeObjectVersion))
            {
                obj = ExchangeObjectVersion.Parse(prop.ToString());
            }
            else if (type == typeof(bool))
            {
                obj = bool.Parse(prop.ToString());
            }
            else if (type == typeof(SecurityPrincipalIdParameter))
            {
                obj = new SecurityPrincipalIdParameter(prop.ToString());
            }
            else if (type == typeof(ActiveDirectoryAccessRule))
            {
                obj = (prop as ActiveDirectoryAccessRule);
            }
            else if (type == typeof(ObjectId))
            {
                string text = prop.ToString();
                if (!ADObjectId.IsValidDistinguishedName(text) && text.Contains("/"))
                {
                    text = MockObjectCreator.ConvertDNFromTreeStructure(text);
                }
                obj = new ADObjectId(text);
            }
            else if (type.IsEnum)
            {
                try
                {
                    obj = Enum.Parse(type, prop.ToString());
                }
                catch (ArgumentException)
                {
                    obj = Enum.GetValues(type).GetValue(0);
                }
            }
            return(obj ?? prop);
        }