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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }
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); }