Exemplo n.º 1
0
        /// <summary>
        /// Implements a multi-object search
        /// </summary>
        /// <param name="value">Object name to search for</param>
        private void Many_User_Search(string value, string field = "displayName")
        {
            Boolean         success = false;
            ADObjectFactory factory = new ADObjectFactory(ad);

            //Clear out the data
            userBinding.Clear();

            //Disable controls
            set_Control_Enable(false);
            try
            {
                //For each Princpal returned by ad.Find...
                foreach (Principal item in ad.Find(new BaseCriteria(field, value)))
                {
                    //Create an ADObject using the factory, and add it to the binding
                    userBinding.Add(factory.toADObject(item));

                    //Enable user controls
                    set_Control_Enable(true);
                }

                success = true;
            }
            catch (Exception ex)
            {
                //If we get an error, display the message in a message box
                Error_Message(ex.Message);
            }

            //Reset the bindings to update bound controls
            userBinding.ResetBindings(false);

            //Set the status text
            Set_Status("Search " + toSucceeded(success));
        }
Exemplo n.º 2
0
 protected override ADObject CreateAndInitializeObject <TResult>(ADPropertyBag propertyBag, ADRawEntry dummyObject)
 {
     return(ADObjectFactory.CreateAndInitializeConfigObject <TResult>(propertyBag, dummyObject, this));
 }
Exemplo n.º 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);
        }