Ejemplo n.º 1
0
        internal static T GetProperty <T>(IAnchorStoreObject item, PropertyDefinition propertyDefinition, bool required) where T : class
        {
            Exception innerException = null;

            try
            {
                if (required)
                {
                    return((T)((object)item[propertyDefinition]));
                }
                return(item.GetValueOrDefault <T>(propertyDefinition, default(T)));
            }
            catch (PropertyErrorException ex)
            {
                innerException = ex;
            }
            catch (InvalidCastException ex2)
            {
                innerException = ex2;
            }
            catch (CorruptDataException ex3)
            {
                innerException = ex3;
            }
            catch (InvalidDataException ex4)
            {
                innerException = ex4;
            }
            throw new MigrationDataCorruptionException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, null), innerException);
        }
Ejemplo n.º 2
0
        private static ADObjectId GetADObjectIdImpl(IAnchorStoreObject item, StorePropertyDefinition propertyDefinition, bool useTryGet)
        {
            AnchorUtil.ThrowOnNullArgument(item, "item");
            AnchorUtil.ThrowOnNullArgument(propertyDefinition, "propertyDefinition");
            Exception innerException = null;

            try
            {
                byte[] array;
                if (useTryGet)
                {
                    array = item.GetValueOrDefault <byte[]>(propertyDefinition, null);
                    if (array == null)
                    {
                        return(null);
                    }
                }
                else
                {
                    array = (byte[])item[propertyDefinition];
                }
                return(new ADObjectId(array));
            }
            catch (CorruptDataException ex)
            {
                innerException = ex;
            }
            catch (ArgumentNullException ex2)
            {
                innerException = ex2;
            }
            throw new InvalidDataException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, null), innerException);
        }
Ejemplo n.º 3
0
        internal static Guid GetGuidProperty(IAnchorStoreObject item, StorePropertyDefinition propertyDefinition, bool required)
        {
            Guid valueOrDefault = item.GetValueOrDefault <Guid>(propertyDefinition, Guid.Empty);

            if (required && valueOrDefault == Guid.Empty)
            {
                throw new InvalidDataException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, null));
            }
            return(valueOrDefault);
        }
Ejemplo n.º 4
0
        internal static ExTimeZone GetExTimeZoneProperty(IPropertyBag item, StorePropertyDefinition propertyDefinition)
        {
            Exception  ex              = null;
            object     objectValue     = item[propertyDefinition];
            ExTimeZone exTimeZoneValue = AnchorHelper.GetExTimeZoneValue(objectValue, ref ex);

            if (ex != null)
            {
                throw new InvalidDataException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, objectValue), ex);
            }
            return(exTimeZoneValue);
        }
Ejemplo n.º 5
0
        internal static CultureInfo GetCultureInfoPropertyOrDefault(IAnchorStoreObject item, PropertyDefinition propertyDefinition)
        {
            string      valueOrDefault = item.GetValueOrDefault <string>(propertyDefinition, "en-US");
            CultureInfo result;

            try
            {
                result = new CultureInfo(valueOrDefault);
            }
            catch (ArgumentException innerException)
            {
                throw new InvalidDataException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, valueOrDefault), innerException);
            }
            return(result);
        }
Ejemplo n.º 6
0
        internal static SmtpAddress GetSmtpAddress(string smtpAddress, StorePropertyDefinition propertyDefinition)
        {
            Exception innerException = null;

            try
            {
                return(SmtpAddress.Parse(smtpAddress));
            }
            catch (PropertyErrorException ex)
            {
                innerException = ex;
            }
            catch (FormatException ex2)
            {
                innerException = ex2;
            }
            throw new InvalidDataException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, null), innerException);
        }
Ejemplo n.º 7
0
        internal static StoreObjectId GetObjectIdProperty(IAnchorStoreObject item, StorePropertyDefinition propertyDefinition, bool required)
        {
            Exception innerException = null;

            try
            {
                byte[] property = AnchorHelper.GetProperty <byte[]>(item, propertyDefinition, required);
                if (property == null)
                {
                    return(null);
                }
                return(MigrationHelperBase.GetStoreObjectId(property));
            }
            catch (CorruptDataException ex)
            {
                innerException = ex;
            }
            throw new InvalidDataException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, null), innerException);
        }
Ejemplo n.º 8
0
        internal static Fqdn GetFqdnProperty(IAnchorStoreObject item, StorePropertyDefinition propertyDefinition, bool required)
        {
            Exception innerException = null;

            try
            {
                string property = AnchorHelper.GetProperty <string>(item, propertyDefinition, required);
                if (property == null)
                {
                    return(null);
                }
                return(new Fqdn(property));
            }
            catch (FormatException ex)
            {
                innerException = ex;
            }
            throw new InvalidDataException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, null), innerException);
        }
Ejemplo n.º 9
0
        private static T GetEnumProperty <T>(StorePropertyDefinition propertyDefinition, object objectValue) where T : struct
        {
            Exception innerException = null;

            try
            {
                return((T)((object)objectValue));
            }
            catch (PropertyErrorException ex)
            {
                innerException = ex;
            }
            catch (FormatException ex2)
            {
                innerException = ex2;
            }
            catch (InvalidCastException ex3)
            {
                innerException = ex3;
            }
            throw new InvalidDataException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, objectValue), innerException);
        }
Ejemplo n.º 10
0
        internal static PersistableDictionary GetDictionaryProperty(IAnchorStoreObject item, PropertyDefinition propertyDefinition, bool required)
        {
            AnchorUtil.ThrowOnNullArgument(item, "item");
            AnchorUtil.ThrowOnNullArgument(propertyDefinition, "propertyDefinition");
            string property = AnchorHelper.GetProperty <string>(item, propertyDefinition, required);

            if (property == null)
            {
                return(null);
            }
            PersistableDictionary result;

            try
            {
                result = PersistableDictionary.Create(property);
            }
            catch (XmlException innerException)
            {
                throw new InvalidDataException(AnchorHelper.GetPropertyErrorMessage(propertyDefinition, property), innerException);
            }
            return(result);
        }