internal static object QuotaSettingGetter(ADPropertyDefinition adPropertyDefinition, IPropertyBag propertyBag)
        {
            if (adPropertyDefinition == null)
            {
                throw new ArgumentNullException("adPropertyDefinition");
            }
            MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)propertyBag[DataClassificationConfigSchema.DataClassificationConfigQuotaSettings];
            string quotaSettingIdentifier = adPropertyDefinition.Name + ':';
            object result = adPropertyDefinition.DefaultValue;

            if (multiValuedProperty != null && multiValuedProperty.Count > 0)
            {
                string text = multiValuedProperty.FirstOrDefault((string item) => item.StartsWith(quotaSettingIdentifier, StringComparison.Ordinal));
                if (!string.IsNullOrEmpty(text))
                {
                    try
                    {
                        result = ValueConvertor.ConvertValueFromString(text.Substring(quotaSettingIdentifier.Length), adPropertyDefinition.Type, null);
                    }
                    catch (FormatException ex)
                    {
                        PropertyValidationError error = new PropertyValidationError(DirectoryStrings.CannotCalculateProperty(adPropertyDefinition.Name, ex.Message), adPropertyDefinition, propertyBag[DataClassificationConfigSchema.DataClassificationConfigQuotaSettings]);
                        throw new DataValidationException(error, ex);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
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);
 }