public static object GetValuesFromDirectoryProperty(SyncPropertyDefinition property, DirectoryProperty originalValues, List <ValidationError> errors) { if (originalValues == null) { return(null); } IList values = originalValues.GetValues(); if (values == null || values.Count == 0 || values == DirectoryProperty.EmptyValues) { return(null); } if (property.IsMultivalued) { IList values2 = new ArrayList(values.Count); SyncValueConvertor.ConvertMultipleValues(property, values, ref values2, errors); MultiValuedPropertyBase multiValuedPropertyBase = ADValueConvertor.CreateGenericMultiValuedProperty(property, property.IsReadOnly, values2, null, null); multiValuedPropertyBase.IsCompletelyRead = true; return(multiValuedPropertyBase); } ValidationError validationError = null; object result = SyncValueConvertor.ConvertSingleValue(property, values[0], out validationError); if (validationError != null) { errors.Add(validationError); } return(result); }
private static void AddValueToResultCollection(SyncPropertyDefinition property, ArrayList result, object value) { object obj = SyncValueConvertor.ConvertSingleValueForDirectoryProperty(property, value); if (obj != SyncValueConvertor.IgnoreValue) { result.Add(obj); } }
private static void ConvertMultipleValues(SyncPropertyDefinition property, IList values, ref IList convertedValues, List <ValidationError> errors) { foreach (object value in values) { ValidationError validationError = null; object obj = SyncValueConvertor.ConvertSingleValue(property, value, out validationError); if (obj != null) { convertedValues.Add(obj); } if (validationError != null) { errors.Add(validationError); } } }
public static void InitializeSyncPropertyCollections(ICollection <PropertyDefinition> allProperties, out ReadOnlyCollection <SyncPropertyDefinition> allLinkedProperties, out ReadOnlyCollection <SyncPropertyDefinition> allForwardSyncProperties, out ReadOnlyCollection <SyncPropertyDefinition> allForwardSyncLinkedProperties, out ReadOnlyCollection <SyncPropertyDefinition> allBackSyncProperties, out ReadOnlyCollection <SyncPropertyDefinition> allShadowProperties) { List <SyncPropertyDefinition> list = new List <SyncPropertyDefinition>(); List <SyncPropertyDefinition> list2 = new List <SyncPropertyDefinition>(); List <SyncPropertyDefinition> list3 = new List <SyncPropertyDefinition>(); List <SyncPropertyDefinition> list4 = new List <SyncPropertyDefinition>(); List <SyncPropertyDefinition> list5 = new List <SyncPropertyDefinition>(); foreach (PropertyDefinition propertyDefinition in allProperties) { ADPropertyDefinition adpropertyDefinition = (ADPropertyDefinition)propertyDefinition; SyncPropertyDefinition syncPropertyDefinition = adpropertyDefinition as SyncPropertyDefinition; if (syncPropertyDefinition != null) { if (syncPropertyDefinition.IsSyncLink) { list.Add(syncPropertyDefinition); if (syncPropertyDefinition.IsForwardSync) { list3.Add(syncPropertyDefinition); } } if (syncPropertyDefinition.IsForwardSync) { list2.Add(syncPropertyDefinition); } if (syncPropertyDefinition.IsBackSync) { list4.Add(syncPropertyDefinition); } if (syncPropertyDefinition.IsShadow) { list5.Add(syncPropertyDefinition); } } } allLinkedProperties = new ReadOnlyCollection <SyncPropertyDefinition>(list.ToArray()); allForwardSyncProperties = new ReadOnlyCollection <SyncPropertyDefinition>(list2.ToArray()); allForwardSyncLinkedProperties = new ReadOnlyCollection <SyncPropertyDefinition>(list3.ToArray()); allBackSyncProperties = new ReadOnlyCollection <SyncPropertyDefinition>(list4.ToArray()); allShadowProperties = new ReadOnlyCollection <SyncPropertyDefinition>(list5.ToArray()); }
public static IList GetValuesForDirectoryProperty(SyncPropertyDefinition property, object value) { ArrayList result = new ArrayList(); if (property.IsMultivalued) { MultiValuedPropertyBase multiValuedPropertyBase = (MultiValuedPropertyBase)value; using (IEnumerator enumerator = ((IEnumerable)multiValuedPropertyBase).GetEnumerator()) { while (enumerator.MoveNext()) { object value2 = enumerator.Current; SyncValueConvertor.AddValueToResultCollection(property, result, value2); } return(result); } } SyncValueConvertor.AddValueToResultCollection(property, result, value); return(result); }
internal bool TryGetLinkedPropertyDefinitionByMsoPropertyName(string propertyName, out SyncPropertyDefinition propertyDefinition) { propertyDefinition = null; foreach (SyncPropertyDefinition syncPropertyDefinition in this.allLinkedProperties) { if (propertyName.Equals(syncPropertyDefinition.MsoPropertyName, StringComparison.OrdinalIgnoreCase)) { propertyDefinition = syncPropertyDefinition; return(true); } } return(false); }
private static object ConvertSingleValue(SyncPropertyDefinition property, object value, out ValidationError error) { error = null; if (value is XmlValueAssignedPlan) { return(((XmlValueAssignedPlan)value).Plan); } if (value is XmlValueCompanyVerifiedDomain) { return(((XmlValueCompanyVerifiedDomain)value).Domain); } if (value is XmlValueDirSyncStatus) { return(SyncValueConvertor.ConvertDirSyncStatusToString(((XmlValueDirSyncStatus)value).DirSyncStatus)); } if (value is AttributeSet) { return(SyncValueConvertor.ConvertAttributeSetToString((AttributeSet)value)); } if (value is XmlValueValidationError) { return(((XmlValueValidationError)value).ErrorInfo); } if (value is XmlValueLicenseUnitsDetail) { return(SyncValueConvertor.ConvertXmlValueLicenseUnitsDetailToString((XmlValueLicenseUnitsDetail)value)); } if (property == SyncSubscribedPlanSchema.Capability) { return(((XmlElement)value).OuterXml); } if (property == SyncCompanySchema.CompanyPartnership) { return(SyncValueConvertor.ConvertCompanyPartnershipToString((XmlValueCompanyPartnership)value)); } if (property == SyncRecipientSchema.SipAddresses) { string text = (string)value; if (!string.IsNullOrEmpty(text) && !text.StartsWith(ProxyAddressPrefix.SIP.ToString() + ':', StringComparison.OrdinalIgnoreCase)) { value = ProxyAddressPrefix.SIP.ToString() + ':' + text; } } else { if (property.Type == typeof(RemoteRecipientType)) { return((RemoteRecipientType)value); } if (property.Type == typeof(RecipientTypeDetails)) { return((RecipientTypeDetails)value); } if (property.Type == typeof(MailboxAuditOperations)) { return((MailboxAuditOperations)value); } if (property.Type == typeof(ElcMailboxFlags)) { return((ElcMailboxFlags)value); } if (property.Type == typeof(DateTime?)) { return((DateTime?)value); } if (property.Type == typeof(DateTime)) { return((DateTime)value); } if (property.Type == typeof(EnhancedTimeSpan)) { return(TimeSpan.FromSeconds((double)((int)value))); } if (value is XmlValueRightsManagementTenantConfiguration) { return(((XmlValueRightsManagementTenantConfiguration)value).RightsManagementTenantConfiguration); } if (value is XmlValueRightsManagementTenantKey) { return(((XmlValueRightsManagementTenantKey)value).RightsManagementTenantKey); } if (value is XmlValueServiceInfo) { return(((XmlValueServiceInfo)value).Info); } if (value is int || value is bool) { return(value); } if (value is DirectoryReferenceAddressList) { DirectoryReferenceAddressList directoryReferenceAddressList = (DirectoryReferenceAddressList)value; if (!directoryReferenceAddressList.TargetDeleted) { return(new PropertyReference(directoryReferenceAddressList.Value, directoryReferenceAddressList.TargetClass, directoryReferenceAddressList.TargetDeleted)); } return(null); } else if (value is DirectoryReferenceUserAndServicePrincipal) { DirectoryReferenceUserAndServicePrincipal directoryReferenceUserAndServicePrincipal = (DirectoryReferenceUserAndServicePrincipal)value; return(directoryReferenceUserAndServicePrincipal.Value); } } bool noConversionRequired = property.Type == typeof(byte[]) || property.Type == typeof(string); return(ADValueConvertor.ConvertFromADAndValidateSingleValue(value, property, noConversionRequired, out error)); }
private static object ConvertSingleValueForDirectoryProperty(SyncPropertyDefinition property, object value) { if (object.Equals(property.DefaultValue, value) && !property.PersistDefaultValue) { return(SyncValueConvertor.IgnoreValue); } if (value == null) { return(null); } if (typeof(DirectoryPropertyString).IsAssignableFrom(property.ExternalType) || property.ExternalType == typeof(string)) { return(ADValueConvertor.ConvertValueToString(value, property.FormatProvider)); } if (typeof(DirectoryPropertyGuid).IsAssignableFrom(property.ExternalType)) { return(ADValueConvertor.ConvertValueToString(value, property.FormatProvider)); } if (typeof(DirectoryPropertyBinary).IsAssignableFrom(property.ExternalType)) { return(ADValueConvertor.ConvertValueToBinary(value, property.FormatProvider)); } if (typeof(DirectoryPropertyBoolean).IsAssignableFrom(property.ExternalType)) { return(bool.Parse(ADValueConvertor.ConvertValueToString(value, property.FormatProvider))); } if (typeof(DirectoryPropertyInt32).IsAssignableFrom(property.ExternalType)) { return(int.Parse(ADValueConvertor.ConvertValueToString(value, property.FormatProvider))); } if (typeof(DirectoryPropertyDateTime).IsAssignableFrom(property.ExternalType)) { Type type = value.GetType(); if (type.Equals(typeof(DateTime))) { return(((DateTime)value).ToUniversalTime()); } return(DateTime.Parse(ADValueConvertor.ConvertValueToString(value, property.FormatProvider), property.FormatProvider)); } else { if (typeof(DirectoryPropertyXmlServiceOriginatedResource) == property.ExternalType && value is Capability) { Capability capability = (Capability)value; if (CapabilityHelper.IsAllowedSKUCapability(capability)) { Guid skucapabilityGuid = CapabilityHelper.GetSKUCapabilityGuid(capability); if (skucapabilityGuid != Guid.Empty) { return(new XmlValueServiceOriginatedResource { Resource = new ServiceOriginatedResourceValue { ServicePlanId = skucapabilityGuid.ToString("D"), Capability = capability.ToString() } }); } } return(SyncValueConvertor.IgnoreValue); } if (typeof(DirectoryPropertyXmlDirSyncStatus).IsAssignableFrom(property.ExternalType)) { string stringValue = (string)value; return(new XmlValueDirSyncStatus { DirSyncStatus = SyncValueConvertor.ConvertStringToDirSyncStatus(stringValue) }); } if (typeof(DirectoryPropertyReferenceAddressList).IsAssignableFrom(property.ExternalType) && value is PropertyReference) { PropertyReference propertyReference = (PropertyReference)value; return(new DirectoryReferenceAddressList { TargetClass = propertyReference.TargetObjectClass, Value = propertyReference.TargetId, TargetDeleted = propertyReference.TargetDeleted }); } throw new NotSupportedException("Conversion for external type " + property.ExternalType.Name); } }
internal static ProxyAddressCollection GetEmailAddressesByPrefix(IPropertyBag propertyBag, ProxyAddressPrefix proxyAddressPrefix, SyncPropertyDefinition propertyDefinition) { List <ProxyAddress> list = new List <ProxyAddress>(); ADPropertyDefinition propertyDefinition2 = SyncRecipientSchema.EmailAddresses; if ((bool)propertyBag[SyncRecipientSchema.UseShadow]) { propertyDefinition2 = SyncRecipientSchema.EmailAddresses.ShadowProperty; } ProxyAddressCollection proxyAddressCollection = (ProxyAddressCollection)propertyBag[propertyDefinition2]; foreach (ProxyAddress proxyAddress in proxyAddressCollection) { if (proxyAddress.Prefix == proxyAddressPrefix) { list.Add(proxyAddress); } } return(new ProxyAddressCollection(false, propertyDefinition, list)); }
private SyncPropertyDefinition(string name, string msoPropertyName, ExchangeObjectVersion versionAdded, Type type, Type externalType, string ldapDisplayName, ADPropertyDefinitionFlags flags, SyncPropertyDefinitionFlags syncFlags, ServerVersion syncVersionAdded, object defaultValue, ProviderPropertyDefinition[] supportingProperties, CustomFilterBuilderDelegate customFilterBuilderDelegate, GetterDelegate getterDelegate, SetterDelegate setterDelegate, ADPropertyDefinition shadowProperty) : base(name, versionAdded, type, ldapDisplayName, SyncPropertyDefinition.CalculateFlags(ldapDisplayName, (ADPropertyDefinitionFlags)(syncFlags | (SyncPropertyDefinitionFlags)flags)), defaultValue, PropertyDefinitionConstraint.None, PropertyDefinitionConstraint.None, supportingProperties, customFilterBuilderDelegate, getterDelegate, setterDelegate, null, null) { this.externalType = externalType; this.MsoPropertyName = msoPropertyName; this.SyncPropertyVersionAdded = syncVersionAdded; SyncPropertyDefinitionFlags syncPropertyDefinitionFlags = syncFlags & ~(SyncPropertyDefinitionFlags.ForwardSync | SyncPropertyDefinitionFlags.BackSync); syncPropertyDefinitionFlags |= SyncPropertyDefinitionFlags.Shadow; if (shadowProperty != null) { Type type2 = shadowProperty.Type; if (type2 == typeof(ADObjectId)) { type2 = typeof(SyncLink); } this.shadowProperty = new SyncPropertyDefinition(shadowProperty, msoPropertyName, type2, externalType, syncPropertyDefinitionFlags, syncVersionAdded); return; } if (this.IsBackSync && base.SupportingProperties.Count == 1 && ((ADPropertyDefinition)base.SupportingProperties[0]).ShadowProperty != null) { this.shadowProperty = new SyncPropertyDefinition(string.Format(CultureInfo.InvariantCulture, "Shadow{0}", new object[] { base.Name }), msoPropertyName, base.Type, this.ExternalType, syncPropertyDefinitionFlags, syncVersionAdded, base.DefaultValue, new ProviderPropertyDefinition[] { ((ADPropertyDefinition)base.SupportingProperties[0]).ShadowProperty }, base.GetterDelegate, base.SetterDelegate); } }
public SyncPropertyDefinition(ADPropertyDefinition aDPropertyDefinition, string msoPropertyName, Type type, Type externalType, SyncPropertyDefinitionFlags flags, ServerVersion versionAdded) : this(aDPropertyDefinition.Name, msoPropertyName, aDPropertyDefinition.VersionAdded, type, externalType, aDPropertyDefinition.LdapDisplayName, aDPropertyDefinition.Flags, flags, versionAdded, aDPropertyDefinition.DefaultValue, SyncPropertyDefinition.ConvertReadOnlyCollectionToArray <ProviderPropertyDefinition>(aDPropertyDefinition.SupportingProperties), aDPropertyDefinition.CustomFilterBuilderDelegate, aDPropertyDefinition.GetterDelegate, aDPropertyDefinition.SetterDelegate, aDPropertyDefinition.ShadowProperty) { }