Exemplo n.º 1
0
 protected override ADObject CreateAndInitializeObject <TResult>(ADPropertyBag propertyBag, ADRawEntry dummyObject)
 {
     return(ADObjectFactory.CreateAndInitializeConfigObject <TResult>(propertyBag, dummyObject, this));
 }
Exemplo n.º 2
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);
        }