internal static object ConvertValueFromStore(EwsStoreObjectPropertyDefinition property, object originalValue) { if (originalValue == null) { return(null); } Type type = originalValue.GetType(); if (type == typeof(EmailAddressCollection) && property.Type == typeof(ADRecipientOrAddress)) { return(new MultiValuedProperty <ADRecipientOrAddress>(false, property, (from x in (EmailAddressCollection)originalValue select EwsStoreValueConverter.ConvertValueFromStore(property, x)).ToArray <object>())); } if (type == typeof(PolicyTag)) { return(((PolicyTag)originalValue).RetentionId); } Type type2 = property.Type; if (type2 == typeof(ADRecipientOrAddress)) { EmailAddress emailAddress = (EmailAddress)originalValue; return(new ADRecipientOrAddress(new Participant(emailAddress.Name, emailAddress.Address, emailAddress.RoutingType))); } if (!(type2 != typeof(byte[])) || !(property.StorePropertyDefinition.Type == typeof(byte[])) || !(originalValue is byte[])) { return(StoreValueConverter.ConvertValueFromStore(property, originalValue)); } if (type2 == typeof(ADObjectId)) { return(StoreValueConverter.ConvertValueFromStore(property, originalValue)); } return(Convert.ChangeType(EwsStoreValueConverter.DeserializeFromBinary((byte[])originalValue), type2)); }
private void SetAttachmentItemProperty(Item item, object value) { FileAttachment propertyAttachment = EwsStoreObjectPropertyDefinition.GetPropertyAttachment(item, base.Name); if (value == null) { if (propertyAttachment != null) { item.Attachments.Remove(propertyAttachment); return; } } else { byte[] array = value as byte[]; if (array == null) { array = EwsStoreValueConverter.SerializeToBinary(value); } if (propertyAttachment != null) { item.Attachments.Remove(propertyAttachment); } item.Attachments.AddFileAttachment(base.Name, array); } }
private bool TryGetAttachmentItemProperty(Item item, out object result) { FileAttachment propertyAttachment = EwsStoreObjectPropertyDefinition.GetPropertyAttachment(item, base.Name); result = null; if (propertyAttachment != null) { int num = 2; Exception ex; do { ex = null; try { propertyAttachment.Load(); goto IL_64; } catch (ServiceRemoteException ex2) { if (ex2 is ServiceResponseException && ((ServiceResponseException)ex2).ErrorCode == 131) { goto IL_64; } ex = ex2; } catch (ServiceLocalException ex3) { ex = ex3; } }while (num-- > 0); throw new DataSourceOperationException(new LocalizedString(ex.Message), ex); IL_64: if (base.Type != typeof(byte[])) { if (propertyAttachment.Content != null && propertyAttachment.Content.Length > 0) { result = EwsStoreValueConverter.DeserializeFromBinary(propertyAttachment.Content); } } else { result = propertyAttachment.Content; } return(true); } return(false); }
internal static object ConvertValueToStore(EwsStoreObjectPropertyDefinition property, object originalValue) { if (originalValue == null) { return(null); } Type type = originalValue.GetType(); if (type == typeof(ADRecipientOrAddress)) { ADRecipientOrAddress adrecipientOrAddress = (ADRecipientOrAddress)originalValue; return(new EmailAddress(adrecipientOrAddress.DisplayName, adrecipientOrAddress.Address, adrecipientOrAddress.RoutingType)); } if (type == typeof(MultiValuedProperty <ADRecipientOrAddress>)) { return((from x in (MultiValuedProperty <ADRecipientOrAddress>) originalValue select x.Address).ToArray <string>()); } if (type == typeof(AuditLogSearchId)) { return(((AuditLogSearchId)originalValue).Guid); } if (type == typeof(ADObjectId) && property.StorePropertyDefinition.Type == typeof(byte[])) { return(((ADObjectId)originalValue).GetBytes()); } if (type == typeof(MultiValuedProperty <ADObjectId>) && property.IsMultivalued && property.StorePropertyDefinition is ExtendedPropertyDefinition && ((ExtendedPropertyDefinition)property.StorePropertyDefinition).MapiType == 3) { return((from x in (MultiValuedProperty <ADObjectId>) originalValue select x.GetBytes()).ToArray <byte[]>()); } if (type != typeof(byte[]) && property.StorePropertyDefinition.Type == typeof(byte[])) { return(EwsStoreValueConverter.SerializeToBinary(originalValue)); } if (!(property.StorePropertyDefinition.Type == typeof(PolicyTag))) { return(ValueConvertor.ConvertValue(StoreValueConverter.ConvertValueToStore(originalValue), EwsStoreValueConverter.GetStorePropertyDefinitionActualType(property), null)); } if ((Guid?)originalValue == null) { return(null); } return(new PolicyTag(true, (Guid)originalValue)); }
internal void CopyChangeToItemObject(Item item, ExchangeVersion ewsVersion) { if (base.ObjectState == ObjectState.Unchanged) { return; } if (item.IsNew && !string.IsNullOrEmpty(this.ItemClass)) { EwsStoreObjectSchema.ItemClass.SetItemProperty(item, this.ItemClass); } foreach (PropertyDefinition propertyDefinition in this.ObjectSchema.AllProperties) { EwsStoreObjectPropertyDefinition ewsStoreObjectPropertyDefinition = propertyDefinition as EwsStoreObjectPropertyDefinition; if (ewsStoreObjectPropertyDefinition != null && !ewsStoreObjectPropertyDefinition.IsReadOnly && !ewsStoreObjectPropertyDefinition.IsCalculated && (base.ObjectState == ObjectState.New || base.IsChanged(ewsStoreObjectPropertyDefinition))) { if (ewsStoreObjectPropertyDefinition.StorePropertyDefinition.Version > ewsVersion && !ewsStoreObjectPropertyDefinition.IsMandatory) { ExTraceGlobals.StorageTracer.TraceDebug(0L, "Skip saving property '{0}.{1}' because the current EWS version '{2}' is lower than '{3}'.", new object[] { base.GetType().FullName, ewsStoreObjectPropertyDefinition.Name, ewsVersion, ewsStoreObjectPropertyDefinition.StorePropertyDefinition.Version }); } else { object obj = this[ewsStoreObjectPropertyDefinition]; if (obj == ewsStoreObjectPropertyDefinition.DefaultValue && !ewsStoreObjectPropertyDefinition.PersistDefaultValue) { if (base.ObjectState == ObjectState.New) { continue; } obj = null; } if (obj != null) { obj = EwsStoreValueConverter.ConvertValueToStore(ewsStoreObjectPropertyDefinition, obj); } ewsStoreObjectPropertyDefinition.SetItemProperty(item, obj); } } } }
public void SetItemProperty(Item item, object value) { if (value != null && this.StorePropertyDefinition.Type != value.GetType()) { value = Convert.ChangeType(value, EwsStoreValueConverter.GetStorePropertyDefinitionActualType(this)); if (value is Array && ((Array)value).Length == 0) { value = null; } } if (this.ItemPropertySetter != null) { this.ItemPropertySetter(item, value); return; } if (this.storePropertyDefinition == ItemSchema.Attachments) { this.SetAttachmentItemProperty(item, value); return; } EwsStoreObjectPropertyDefinition.SetExtendedPropertyItemProperty(item, (ExtendedPropertyDefinition)this.storePropertyDefinition, value); }
internal void CopyFromItemObject(Item item, ExchangeVersion ewsVersion) { if (item == null) { throw new ArgumentNullException("item"); } base.InstantiationErrors.Clear(); foreach (PropertyDefinition propertyDefinition in this.ObjectSchema.AllProperties) { if (propertyDefinition != EwsStoreObjectSchema.ExchangeVersion) { EwsStoreObjectPropertyDefinition ewsStoreObjectPropertyDefinition = propertyDefinition as EwsStoreObjectPropertyDefinition; if (ewsStoreObjectPropertyDefinition != null) { object obj = null; if (ewsStoreObjectPropertyDefinition.GetItemProperty(item, out obj)) { if (ewsStoreObjectPropertyDefinition.StorePropertyDefinition.Version > ewsVersion) { ExTraceGlobals.StorageTracer.TraceDebug(0L, "Skip loading property '{0}.{1}' because the current EWS version '{2}' is lower than '{3}'.", new object[] { base.GetType().FullName, ewsStoreObjectPropertyDefinition.Name, ewsVersion, ewsStoreObjectPropertyDefinition.StorePropertyDefinition.Version }); } else { Exception ex = null; try { obj = EwsStoreValueConverter.ConvertValueFromStore(ewsStoreObjectPropertyDefinition, obj); this.propertyBag.SetField(ewsStoreObjectPropertyDefinition, obj); base.InstantiationErrors.AddRange(ewsStoreObjectPropertyDefinition.ValidateProperty(obj, this.propertyBag, true)); } catch (LocalizedException ex2) { base.InstantiationErrors.Add(new PropertyValidationError(ex2.LocalizedString, ewsStoreObjectPropertyDefinition, obj)); } catch (InvalidCastException ex3) { ex = ex3; } catch (FormatException ex4) { ex = ex4; } catch (SerializationException ex5) { ex = ex5; } if (ex != null) { base.InstantiationErrors.Add(new PropertyValidationError(new LocalizedString(ex.Message), ewsStoreObjectPropertyDefinition, obj)); } } } } } } }