Exemple #1
0
        // Token: 0x06000B48 RID: 2888 RVA: 0x00033CCC File Offset: 0x00031ECC
        private bool AreMultivaluedPropertiesEqual(object leftValue, object rightValue, ADPropertyDefinition adProperty)
        {
            MultiValuedPropertyBase multiValuedPropertyBase  = leftValue as MultiValuedPropertyBase;
            MultiValuedPropertyBase multiValuedPropertyBase2 = rightValue as MultiValuedPropertyBase;

            if (multiValuedPropertyBase != null && multiValuedPropertyBase.Count > 0 && rightValue == null)
            {
                return(false);
            }
            if (multiValuedPropertyBase == null && multiValuedPropertyBase2 != null && multiValuedPropertyBase2.Count > 0)
            {
                return(false);
            }
            if (multiValuedPropertyBase == null && multiValuedPropertyBase2 != null && multiValuedPropertyBase2.Count == 0)
            {
                return(true);
            }
            if (multiValuedPropertyBase != null && multiValuedPropertyBase.Count == 0 && multiValuedPropertyBase2 == null)
            {
                return(true);
            }
            if (multiValuedPropertyBase.Count == 0 && multiValuedPropertyBase2.Count == 0)
            {
                return(true);
            }
            IEnumerable   enumerable = (IEnumerable)leftValue;
            List <byte[]> list       = new List <byte[]>();
            List <string> list2      = new List <string>();

            foreach (object originalValue in enumerable)
            {
                if (adProperty.IsBinary)
                {
                    list.Add(ADValueConvertor.ConvertValueToBinary(originalValue, adProperty.FormatProvider));
                }
                else
                {
                    list2.Add(ADValueConvertor.ConvertValueToString(originalValue, adProperty.FormatProvider));
                }
            }
            IEnumerable   enumerable2 = (IEnumerable)rightValue;
            List <byte[]> list3       = new List <byte[]>();
            List <string> list4       = new List <string>();

            foreach (object originalValue2 in enumerable2)
            {
                if (adProperty.IsBinary)
                {
                    list3.Add(ADValueConvertor.ConvertValueToBinary(originalValue2, adProperty.FormatProvider));
                }
                else
                {
                    list4.Add(ADValueConvertor.ConvertValueToString(originalValue2, adProperty.FormatProvider));
                }
            }
            return(list.Equals(list3, ByteArrayComparer.Instance) && list2.Equals(list4, StringComparer.Ordinal));
        }
Exemple #2
0
 // Token: 0x06000B4A RID: 2890 RVA: 0x00033E84 File Offset: 0x00032084
 internal bool Equals(ADRawEntry left, ADRawEntry right, IEnumerable <PropertyDefinition> properties)
 {
     if (left == null)
     {
         return(null == right);
     }
     if (right == null)
     {
         return(null == left);
     }
     foreach (PropertyDefinition propertyDefinition in properties)
     {
         ADPropertyDefinition adpropertyDefinition = (ADPropertyDefinition)propertyDefinition;
         if (adpropertyDefinition.LdapDisplayName != null && !adpropertyDefinition.IsCalculated && !adpropertyDefinition.LdapDisplayName.Equals(ADObjectSchema.Id.LdapDisplayName, StringComparison.Ordinal))
         {
             object obj = null;
             left.propertyBag.TryGetField(adpropertyDefinition, ref obj);
             object obj2 = null;
             right.propertyBag.TryGetField(adpropertyDefinition, ref obj2);
             if (obj != null || obj2 != null)
             {
                 if (adpropertyDefinition.IsMultivalued)
                 {
                     if (!this.AreMultivaluedPropertiesEqual(obj, obj2, adpropertyDefinition))
                     {
                         return(false);
                     }
                 }
                 else
                 {
                     if (obj != null && obj2 == null)
                     {
                         return(false);
                     }
                     if (obj == null && obj2 != null)
                     {
                         return(false);
                     }
                     if (adpropertyDefinition.IsBinary)
                     {
                         byte[] left2  = ADValueConvertor.ConvertValueToBinary(obj, adpropertyDefinition.FormatProvider);
                         byte[] right2 = ADValueConvertor.ConvertValueToBinary(obj2, adpropertyDefinition.FormatProvider);
                         if (!ByteArrayComparer.Instance.Equals(left2, right2))
                         {
                             return(false);
                         }
                     }
                     else
                     {
                         string a = ADValueConvertor.ConvertValueToString(obj, adpropertyDefinition.FormatProvider);
                         string b = ADValueConvertor.ConvertValueToString(obj2, adpropertyDefinition.FormatProvider);
                         if (!string.Equals(a, b, StringComparison.Ordinal))
                         {
                             return(false);
                         }
                     }
                 }
             }
         }
     }
     return(true);
 }
 // Token: 0x060050C6 RID: 20678 RVA: 0x0012B948 File Offset: 0x00129B48
 internal static object MarshalAttribute(ADPropertyDefinition property, object value)
 {
     if (property == null)
     {
         throw new ArgumentNullException("property");
     }
     if (value == null)
     {
         return(null);
     }
     object[] array;
     if (!property.IsMultivalued)
     {
         array    = new object[2];
         array[0] = property.LdapDisplayName;
         if (property.IsBinary)
         {
             byte[] array2 = ADValueConvertor.ConvertValueToBinary(value, property.FormatProvider);
             array[1] = HexConverter.ByteArrayToHexString(array2);
         }
         else
         {
             ADObjectId adobjectId = value as ADObjectId;
             if (adobjectId != null)
             {
                 array[1] = adobjectId.ToDNString();
             }
             else
             {
                 array[1] = ADValueConvertor.ConvertValueToString(value, property.FormatProvider);
             }
         }
     }
     else
     {
         int         num        = 0;
         ArrayList   arrayList  = new ArrayList();
         IEnumerable enumerable = (IEnumerable)value;
         foreach (object obj in enumerable)
         {
             if (property.IsBinary)
             {
                 byte[] array3 = ADValueConvertor.ConvertValueToBinary(obj, property.FormatProvider);
                 arrayList.Add(HexConverter.ByteArrayToHexString(array3));
             }
             else
             {
                 ADObjectId adobjectId2 = obj as ADObjectId;
                 string     value2;
                 if (adobjectId2 != null)
                 {
                     value2 = adobjectId2.ToDNString();
                 }
                 else
                 {
                     value2 = ADValueConvertor.ConvertValueToString(obj, property.FormatProvider);
                 }
                 arrayList.Add(value2);
             }
             num++;
         }
         if (num == 0)
         {
             return(null);
         }
         array    = new object[num + 1];
         array[0] = property.LdapDisplayName;
         arrayList.CopyTo(array, 1);
     }
     return(array);
 }
 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);
     }
 }
Exemple #5
0
        public static SimpleADObject CreateFromRawEntry(ADRawEntry adRawEntry, IEnumerable <PropertyDefinition> properties, bool includeNullProperties)
        {
            ArgumentValidator.ThrowIfNull("adRawEntry", adRawEntry);
            ArgumentValidator.ThrowIfNull("properties", properties);
            SimpleADObject simpleADObject = new SimpleADObject();

            simpleADObject.OriginatingServer    = adRawEntry.OriginatingServer;
            simpleADObject.ObjectState          = adRawEntry.ObjectState;
            simpleADObject.WhenReadUTC          = adRawEntry.WhenReadUTC.Value;
            simpleADObject.DirectoryBackendType = adRawEntry.DirectoryBackendType;
            simpleADObject.ExchangeVersion      = adRawEntry.ExchangeVersion;
            foreach (PropertyDefinition propertyDefinition in properties)
            {
                ADPropertyDefinition adpropertyDefinition = (ADPropertyDefinition)propertyDefinition;
                if (adpropertyDefinition == null)
                {
                    ArgumentValidator.ThrowIfTypeInvalid("properties", properties, typeof(IEnumerable <ADPropertyDefinition>));
                }
                if (adpropertyDefinition.LdapDisplayName != null && !adpropertyDefinition.IsCalculated)
                {
                    object obj = null;
                    if (!adRawEntry.propertyBag.TryGetField(adpropertyDefinition, ref obj) || obj == null)
                    {
                        if (includeNullProperties)
                        {
                            simpleADObject.AddProperty(new SimpleADObject.SimpleADProperty
                            {
                                Name  = adpropertyDefinition.LdapDisplayName,
                                Value = null
                            });
                        }
                    }
                    else
                    {
                        if (adpropertyDefinition.IsMultivalued)
                        {
                            MultiValuedPropertyBase multiValuedPropertyBase = (MultiValuedPropertyBase)obj;
                            if (multiValuedPropertyBase == null || multiValuedPropertyBase.Count == 0)
                            {
                                if (includeNullProperties)
                                {
                                    simpleADObject.AddProperty(new SimpleADObject.SimpleADProperty
                                    {
                                        Name  = adpropertyDefinition.LdapDisplayName,
                                        Value = null
                                    });
                                    continue;
                                }
                                continue;
                            }
                        }
                        SimpleADObject.SimpleADProperty simpleADProperty = new SimpleADObject.SimpleADProperty();
                        simpleADProperty.Name = adpropertyDefinition.LdapDisplayName;
                        ADObjectId adobjectId = obj as ADObjectId;
                        if (!adpropertyDefinition.IsMultivalued)
                        {
                            if (adpropertyDefinition.IsBinary)
                            {
                                simpleADProperty.Value = ADValueConvertor.ConvertValueToBinary(obj, adpropertyDefinition.FormatProvider);
                            }
                            else if (adobjectId != null && adpropertyDefinition.IsSoftLinkAttribute && string.IsNullOrEmpty(adobjectId.DistinguishedName))
                            {
                                simpleADProperty.Value = adobjectId.ToSoftLinkValue();
                            }
                            else if (adobjectId != null)
                            {
                                simpleADProperty.Value = adobjectId.ToExtendedDN();
                            }
                            else
                            {
                                simpleADProperty.Value = ADValueConvertor.ConvertValueToString(obj, adpropertyDefinition.FormatProvider);
                            }
                        }
                        else
                        {
                            IEnumerable enumerable = (IEnumerable)obj;
                            if (adpropertyDefinition.IsBinary)
                            {
                                List <byte[]> list = new List <byte[]>();
                                foreach (object originalValue in enumerable)
                                {
                                    list.Add(ADValueConvertor.ConvertValueToBinary(originalValue, adpropertyDefinition.FormatProvider));
                                }
                                if (list.Count == 0)
                                {
                                    list = null;
                                }
                                simpleADProperty.Value = list;
                            }
                            else
                            {
                                List <string> list2 = new List <string>();
                                foreach (object obj2 in enumerable)
                                {
                                    adobjectId = (obj2 as ADObjectId);
                                    if (adobjectId != null)
                                    {
                                        list2.Add(adobjectId.ToExtendedDN());
                                    }
                                    else
                                    {
                                        list2.Add(ADValueConvertor.ConvertValueToString(obj2, adpropertyDefinition.FormatProvider));
                                    }
                                }
                                if (list2.Count == 0)
                                {
                                    list2 = null;
                                }
                                simpleADProperty.Value = list2;
                            }
                        }
                        simpleADObject.AddProperty(simpleADProperty);
                    }
                }
            }
            return(simpleADObject);
        }