예제 #1
0
        public static ADRawEntry CreateFrom(SimpleADObject simpleADObject, IEnumerable <PropertyDefinition> properties)
        {
            ArgumentValidator.ThrowIfNull("simpleADObject", simpleADObject);
            ArgumentValidator.ThrowIfNull("properties", properties);
            ADPropertyBag adpropertyBag = new ADPropertyBag();

            SimpleADObject.SimpleList <SimpleADObject.SimpleADProperty> properties2 = simpleADObject.Properties;
            SimpleADObject.SimpleADProperty simpleADProperty;
            if (!properties2.TryGetValue(ADObjectSchema.Id.LdapDisplayName, out simpleADProperty))
            {
                throw new InvalidOperationException("dn is missing");
            }
            ValidationError validationError;
            ADObjectId      value = (ADObjectId)ADValueConvertor.ConvertFromADAndValidateSingleValue(simpleADProperty.Value as string, ADObjectSchema.Id, false, out validationError);

            adpropertyBag.SetField(ADObjectSchema.Id, value);
            foreach (PropertyDefinition propertyDefinition in properties)
            {
                ADPropertyDefinition propertyDefinition2 = (ADPropertyDefinition)propertyDefinition;
                SimpleADObject.AddPropertyToPropertyBag(propertyDefinition2, adpropertyBag, properties2);
            }
            adpropertyBag.SetField(ADObjectSchema.ObjectState, simpleADObject.ObjectState);
            adpropertyBag.SetObjectVersion(simpleADObject.ExchangeVersion);
            return(new ADRawEntry(adpropertyBag)
            {
                OriginatingServer = simpleADObject.OriginatingServer,
                WhenReadUTC = new DateTime?(simpleADObject.WhenReadUTC),
                DirectoryBackendType = simpleADObject.DirectoryBackendType,
                IsCached = true
            });
        }
예제 #2
0
 public bool Equals(SimpleADObject.SimpleList <T> right)
 {
     if (right == null)
     {
         return(false);
     }
     if (object.ReferenceEquals(this, right))
     {
         return(true);
     }
     if (base.Count != right.Count)
     {
         return(false);
     }
     foreach (T t in base.Values)
     {
         T right2;
         if (!right.TryGetValue(t.Name, out right2) || !t.Equals(right2))
         {
             return(false);
         }
     }
     return(true);
 }
예제 #3
0
        public static TObject CreateFrom <TObject>(SimpleADObject simpleADObject, ADObjectSchema schema, IEnumerable <PropertyDefinition> additionalProperties) where TObject : ADRawEntry, new()
        {
            ArgumentValidator.ThrowIfNull("simpleADObject", simpleADObject);
            if (typeof(TObject).Equals(typeof(ADRawEntry)))
            {
                throw new ArgumentException("TObject cannot be ADRawEntry");
            }
            ADPropertyBag adpropertyBag = new ADPropertyBag();

            SimpleADObject.SimpleList <SimpleADObject.SimpleADProperty> properties = simpleADObject.Properties;
            SimpleADObject.SimpleADProperty simpleADProperty;
            if (!properties.TryGetValue(ADObjectSchema.Id.LdapDisplayName, out simpleADProperty))
            {
                throw new InvalidOperationException("dn is missing");
            }
            ValidationError validationError;
            ADObjectId      value = (ADObjectId)ADValueConvertor.ConvertFromADAndValidateSingleValue(simpleADProperty.Value as string, ADObjectSchema.Id, false, out validationError);

            adpropertyBag.SetField(ADObjectSchema.Id, value);
            adpropertyBag.SetField(ADObjectSchema.ObjectState, simpleADObject.ObjectState);
            adpropertyBag.SetObjectVersion(simpleADObject.ExchangeVersion);
            TObject tobject = Activator.CreateInstance <TObject>();
            IEnumerable <PropertyDefinition> enumerable;

            if (schema != null)
            {
                enumerable = schema.AllProperties;
            }
            else
            {
                enumerable = ((ADObject)((object)tobject)).Schema.AllProperties;
            }
            if (additionalProperties != null)
            {
                enumerable = enumerable.Concat(additionalProperties);
            }
            foreach (PropertyDefinition propertyDefinition in enumerable)
            {
                ADPropertyDefinition propertyDefinition2 = (ADPropertyDefinition)propertyDefinition;
                SimpleADObject.AddPropertyToPropertyBag(propertyDefinition2, adpropertyBag, properties);
            }
            if (tobject is MiniObject)
            {
                adpropertyBag.SetIsReadOnly(true);
            }
            if (schema != null || (!(tobject is ADRecipient) && !(tobject is MiniRecipient)))
            {
                tobject = (TObject)((object)ADObjectFactory.CreateAndInitializeConfigObject <TObject>(adpropertyBag, tobject, null));
            }
            else
            {
                tobject = (TObject)((object)ADObjectFactory.CreateAndInitializeRecipientObject <TObject>(adpropertyBag, tobject, null));
            }
            tobject.OriginatingServer    = simpleADObject.OriginatingServer;
            tobject.WhenReadUTC          = new DateTime?(simpleADObject.WhenReadUTC);
            tobject.DirectoryBackendType = simpleADObject.DirectoryBackendType;
            tobject.IsCached             = true;
            tobject.ValidateRead();
            tobject.ResetChangeTracking();
            return(tobject);
        }
예제 #4
0
        private static void AddPropertyToPropertyBag(ADPropertyDefinition propertyDefinition, PropertyBag propertyBag, SimpleADObject.SimpleList <SimpleADObject.SimpleADProperty> lookup)
        {
            if (propertyBag.Contains(propertyDefinition))
            {
                return;
            }
            if (propertyDefinition.IsCalculated)
            {
                foreach (ProviderPropertyDefinition providerPropertyDefinition in propertyDefinition.SupportingProperties)
                {
                    ADPropertyDefinition propertyDefinition2 = (ADPropertyDefinition)providerPropertyDefinition;
                    SimpleADObject.AddPropertyToPropertyBag(propertyDefinition2, propertyBag, lookup);
                }
                return;
            }
            if (string.IsNullOrEmpty(propertyDefinition.LdapDisplayName))
            {
                return;
            }
            SimpleADObject.SimpleADProperty simpleADProperty;
            if (!lookup.TryGetValue(propertyDefinition.LdapDisplayName, out simpleADProperty) || simpleADProperty == null)
            {
                propertyBag.SetField(propertyDefinition, null);
                return;
            }
            if (simpleADProperty.Value == null)
            {
                propertyBag.SetField(propertyDefinition, null);
                return;
            }
            object value5;

            if (propertyDefinition.IsMultivalued)
            {
                ArrayList arrayList     = new ArrayList();
                ArrayList invalidValues = new ArrayList();
                if (propertyDefinition.IsBinary)
                {
                    List <byte[]> list = simpleADProperty.Value as List <byte[]>;
                    if (list == null)
                    {
                        return;
                    }
                    using (List <byte[]> .Enumerator enumerator2 = list.GetEnumerator())
                    {
                        while (enumerator2.MoveNext())
                        {
                            byte[]          value = enumerator2.Current;
                            ValidationError validationError;
                            object          value2 = ADValueConvertor.ConvertFromADAndValidateSingleValue(value, propertyDefinition, propertyDefinition.Type == typeof(byte[]), out validationError);
                            arrayList.Add(value2);
                        }
                        goto IL_17F;
                    }
                }
                List <string> list2 = simpleADProperty.Value as List <string>;
                if (list2 == null)
                {
                    return;
                }
                foreach (string value3 in list2)
                {
                    ValidationError validationError2;
                    object          value4 = ADValueConvertor.ConvertFromADAndValidateSingleValue(value3, propertyDefinition, propertyDefinition.Type == typeof(string), out validationError2);
                    arrayList.Add(value4);
                }
IL_17F:
                MultiValuedPropertyBase multiValuedPropertyBase = ADValueConvertor.CreateGenericMultiValuedProperty(propertyDefinition, true, arrayList, invalidValues, null);
                multiValuedPropertyBase.IsCompletelyRead        = true;
                value5 = multiValuedPropertyBase;
            }
            else
            {
                ValidationError validationError3;
                value5 = ADValueConvertor.ConvertFromADAndValidateSingleValue(simpleADProperty.Value, propertyDefinition, propertyDefinition.Type == (propertyDefinition.IsBinary ? typeof(byte[]) : typeof(string)), out validationError3);
            }
            propertyBag.SetField(propertyDefinition, value5);
        }