public int IndexOf(ActiveDirectorySchemaProperty schemaProperty)
    {
      Contract.Requires(schemaProperty != null);
      Contract.Ensures(Contract.Result<int>() >= -1);

      return default(int);
    }
		public int Add(ActiveDirectorySchemaProperty schemaProperty)
		{
			if (schemaProperty != null)
			{
				if (schemaProperty.isBound)
				{
					if (this.Contains(schemaProperty))
					{
						object[] objArray = new object[1];
						objArray[0] = schemaProperty;
						throw new ArgumentException(Res.GetString("AlreadyExistingInCollection", objArray), "schemaProperty");
					}
					else
					{
						return base.List.Add(schemaProperty);
					}
				}
				else
				{
					object[] name = new object[1];
					name[0] = schemaProperty.Name;
					throw new InvalidOperationException(Res.GetString("SchemaObjectNotCommitted", name));
				}
			}
			else
			{
				throw new ArgumentNullException("schemaProperty");
			}
		}
        // You can use the DirectoryServer or Forest value of the DirectoryContextType enumeration
        // for connecting to and then extending an AD schema.
        // However, use caution when extended an AD schema. Additions are not easily reversible
        public static void CreateNewAttribute()
        {
            //specify a common name
            string newAttributeCommonName = "New-Attribute1";

            //specify an OID value. The root name was generated by oidgen.exe
            string newAttributeOid =
                "1.2.840.113556.1.4.7000.233.28688.28684.8.145234.1728134.2034934.1932637.1";

            // specify a syntax
            ActiveDirectorySyntax syntax = ActiveDirectorySyntax.CaseIgnoreString;

            // create a new attribute schema object
            ActiveDirectorySchemaProperty newAttribute =
                                                new ActiveDirectorySchemaProperty(
                                                        adamContext,
                                                        newAttributeLdapDisplayName);

            // set attributes for this schema attribute object
            newAttribute.CommonName = newAttributeCommonName;
            newAttribute.Oid = newAttributeOid;
            newAttribute.IsSingleValued = true;
            newAttribute.Syntax = syntax;

            // do not replicate to the global catalog
            // the default for isMemberOfPartialAttributeSet is already False, but this
            // setting is irrelevant for an ADAM instance.
            // newAttribute.IsInGlobalCatalog = false;

            try
            {
                // save the new attribute schema object to the schema
                newAttribute.Save();
            }
            catch (ActiveDirectoryObjectExistsException e)
            {
                // an object by this name already exists in the schema
                Console.WriteLine("The schema object \"{0}\" was not created. {1}",
                    newAttributeLdapDisplayName, e.Message);
                return;
            }

            catch (ActiveDirectoryOperationException e)
            {
                // a call to the underlying directory was rejected
                Console.WriteLine("The schema object \"{0}\" was not created. {0}",
                            newAttributeLdapDisplayName, e.Message);
                return;

            }

            Console.WriteLine("Attribute schema object \"{0}\" created successfully.",
                                                    newAttributeLdapDisplayName);
        }
 public bool Contains(ActiveDirectorySchemaProperty schemaProperty)
 {
     if (schemaProperty == null)
         throw new ArgumentNullException("schemaProperty");
     for (int i = 0; i < InnerList.Count; i++)
     {
         ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i];
         if (Utils.Compare(tmp.Name, schemaProperty.Name) == 0)
         {
             return true;
         }
     }
     return false;
 }
        public int IndexOf(ActiveDirectorySchemaProperty schemaProperty)
        {
            if (schemaProperty == null)
                throw new ArgumentNullException("schemaProperty");

            for (int i = 0; i < InnerList.Count; i++)
            {
                ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i];
                if (Utils.Compare(tmp.Name, schemaProperty.Name) == 0)
                {
                    return i;
                }
            }
            return -1;
        }
 public int Add(ActiveDirectorySchemaProperty schemaProperty)
 {
     if (schemaProperty == null)
     {
         throw new ArgumentNullException("schemaProperty");
     }
     if (!schemaProperty.isBound)
     {
         throw new InvalidOperationException(Res.GetString("SchemaObjectNotCommitted", new object[] { schemaProperty.Name }));
     }
     if (this.Contains(schemaProperty))
     {
         throw new ArgumentException(Res.GetString("AlreadyExistingInCollection", new object[] { schemaProperty }), "schemaProperty");
     }
     return base.List.Add(schemaProperty);
 }
 public void AddRange(ActiveDirectorySchemaProperty[] properties)
 {
     if (properties == null)
     {
         throw new ArgumentNullException("properties");
     }
     ActiveDirectorySchemaProperty[] propertyArray = properties;
     for (int i = 0; i < propertyArray.Length; i++)
     {
         if (propertyArray[i] == null)
         {
             throw new ArgumentException("properties");
         }
     }
     for (int j = 0; j < properties.Length; j++)
     {
         this.Add(properties[j]);
     }
 }
        public int Add(ActiveDirectorySchemaProperty schemaProperty)
        {
            if (schemaProperty == null)
            {
                throw new ArgumentNullException("schemaProperty");
            }

            if (!schemaProperty.isBound)
            {
                throw new InvalidOperationException(Res.GetString(Res.SchemaObjectNotCommitted, schemaProperty.Name));
            }

            if (!Contains(schemaProperty))
            {
                return List.Add(schemaProperty);
            }
            else
            {
                throw new ArgumentException(Res.GetString(Res.AlreadyExistingInCollection, schemaProperty), "schemaProperty");
            }
        }
		public int IndexOf(ActiveDirectorySchemaProperty schemaProperty)
		{
			if (schemaProperty != null)
			{
				int num = 0;
				while (num < base.InnerList.Count)
				{
					ActiveDirectorySchemaProperty item = (ActiveDirectorySchemaProperty)base.InnerList[num];
					if (Utils.Compare(item.Name, schemaProperty.Name) != 0)
					{
						num++;
					}
					else
					{
						return num;
					}
				}
				return -1;
			}
			else
			{
				throw new ArgumentNullException("schemaProperty");
			}
		}
示例#10
0
 public int IndexOf(ActiveDirectorySchemaProperty schemaProperty)
 {
     if (schemaProperty != null)
     {
         int num = 0;
         while (num < base.InnerList.Count)
         {
             ActiveDirectorySchemaProperty item = (ActiveDirectorySchemaProperty)base.InnerList[num];
             if (Utils.Compare(item.Name, schemaProperty.Name) != 0)
             {
                 num++;
             }
             else
             {
                 return(num);
             }
         }
         return(-1);
     }
     else
     {
         throw new ArgumentNullException("schemaProperty");
     }
 }
 public void Remove(ActiveDirectorySchemaProperty schemaProperty)
 {
     if (schemaProperty != null)
     {
         if (schemaProperty.isBound)
         {
             int num = 0;
             while (num < base.InnerList.Count)
             {
                 ActiveDirectorySchemaProperty item = (ActiveDirectorySchemaProperty)base.InnerList[num];
                 if (Utils.Compare(item.Name, schemaProperty.Name) != 0)
                 {
                     num++;
                 }
                 else
                 {
                     base.List.Remove(item);
                     return;
                 }
             }
             object[] objArray = new object[1];
             objArray[0] = schemaProperty;
             throw new ArgumentException(Res.GetString("NotFoundInCollection", objArray), "schemaProperty");
         }
         else
         {
             object[] name = new object[1];
             name[0] = schemaProperty.Name;
             throw new InvalidOperationException(Res.GetString("SchemaObjectNotCommitted", name));
         }
     }
     else
     {
         throw new ArgumentNullException("schemaProperty");
     }
 }
		public int IndexOf(ActiveDirectorySchemaProperty schemaProperty)
		{
			if (schemaProperty != null)
			{
				if (schemaProperty.isBound)
				{
					int num = 0;
					while (num < base.InnerList.Count)
					{
						ActiveDirectorySchemaProperty item = (ActiveDirectorySchemaProperty)base.InnerList[num];
						if (Utils.Compare(item.Name, schemaProperty.Name) != 0)
						{
							num++;
						}
						else
						{
							return num;
						}
					}
					return -1;
				}
				else
				{
					object[] name = new object[1];
					name[0] = schemaProperty.Name;
					throw new InvalidOperationException(Res.GetString("SchemaObjectNotCommitted", name));
				}
			}
			else
			{
				throw new ArgumentNullException("schemaProperty");
			}
		}
        //
        // This method searches in the schema container for all non-defunct properties of the 
        // specified name (ldapDisplayName).
        //
        private ArrayList GetProperties(ICollection ldapDisplayNames)
        {
            ArrayList properties = new ArrayList();
            SearchResultCollection resCol = null;

            try
            {
                if (ldapDisplayNames.Count < 1)
                {
                    return properties;
                }

                if (_schemaEntry == null)
                {
                    _schemaEntry = DirectoryEntryManager.GetDirectoryEntry(_context, WellKnownDN.SchemaNamingContext);
                }

                // constructing the filter
                StringBuilder str = new StringBuilder(100);

                if (ldapDisplayNames.Count > 1)
                {
                    str.Append("(|");
                }
                foreach (string ldapDisplayName in ldapDisplayNames)
                {
                    str.Append("(");
                    str.Append(PropertyManager.LdapDisplayName);
                    str.Append("=");
                    str.Append(Utils.GetEscapedFilterValue(ldapDisplayName));
                    str.Append(")");
                }
                if (ldapDisplayNames.Count > 1)
                {
                    str.Append(")");
                }

                string filter = "(&(" + PropertyManager.ObjectCategory + "=attributeSchema)" + str.ToString() + "(!(" + PropertyManager.IsDefunct + "=TRUE)))";

                string[] propertiesToLoad = new String[1];
                propertiesToLoad[0] = PropertyManager.LdapDisplayName;

                ADSearcher searcher = new ADSearcher(_schemaEntry, filter, propertiesToLoad, SearchScope.OneLevel);
                resCol = searcher.FindAll();

                foreach (SearchResult res in resCol)
                {
                    string ldapDisplayName = (string)PropertyManager.GetSearchResultPropertyValue(res, PropertyManager.LdapDisplayName);
                    DirectoryEntry de = res.GetDirectoryEntry();

                    de.AuthenticationType = Utils.DefaultAuthType;
                    de.Username = _context.UserName;
                    de.Password = _context.Password;

                    ActiveDirectorySchemaProperty schemaProperty = new ActiveDirectorySchemaProperty(_context, ldapDisplayName, de, _schemaEntry);

                    properties.Add(schemaProperty);
                }
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(_context, e);
            }
            finally
            {
                if (resCol != null)
                {
                    resCol.Dispose();
                }
            }

            return properties;
        }
		public void CopyTo (ActiveDirectorySchemaProperty[] properties, int index)
		{
			throw new NotImplementedException ();
		}
		public void Insert (int index, ActiveDirectorySchemaProperty schemaProperty)
		{
			throw new NotImplementedException ();
		}
		public void AddRange (ActiveDirectorySchemaProperty[] properties)
		{
			throw new NotImplementedException ();
		}
        public int IndexOf(ActiveDirectorySchemaProperty schemaProperty)
        {
            if (schemaProperty == null)
            {
                throw new ArgumentNullException("schemaProperty");
            }

            if (!schemaProperty.isBound)
            {
                throw new InvalidOperationException(Res.GetString(Res.SchemaObjectNotCommitted, schemaProperty.Name));
            }

            for (int i = 0; i < InnerList.Count; i++)
            {
                ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i];
                if (Utils.Compare(tmp.Name, schemaProperty.Name) == 0)
                {
                    return i;
                }
            }
            return -1;
        }
        public void Remove(ActiveDirectorySchemaProperty schemaProperty)
        {
            if (schemaProperty == null)
            {
                throw new ArgumentNullException("schemaProperty");
            }

            if (!schemaProperty.isBound)
            {
                throw new InvalidOperationException(Res.GetString(Res.SchemaObjectNotCommitted, schemaProperty.Name));
            }

            for (int i = 0; i < InnerList.Count; i++)
            {
                ActiveDirectorySchemaProperty tmp = (ActiveDirectorySchemaProperty)InnerList[i];
                if (Utils.Compare(tmp.Name, schemaProperty.Name) == 0)
                {
                    List.Remove(tmp);
                    return;
                }
            }
            throw new ArgumentException(Res.GetString(Res.NotFoundInCollection, schemaProperty), "schemaProperty");
        }
 public void CopyTo(ActiveDirectorySchemaProperty[] properties, int index)
 {
   Contract.Requires(properties != null);
   Contract.Requires(index >= 0);
 }
    public bool Contains(ActiveDirectorySchemaProperty schemaProperty)
    {
      Contract.Requires(schemaProperty != null);

      return default(bool);
    }
示例#21
0
        //
        // This method finds only among defunct properties
        //
        public ActiveDirectorySchemaProperty FindDefunctProperty(string commonName)
        {
            CheckIfDisposed();

            if (commonName == null)
            {
                throw new ArgumentNullException("commonName");
            }

            if (commonName.Length == 0)
            {
                throw new ArgumentException(Res.GetString(Res.EmptyStringParameter), "commonName");
            }

            // this will bind to the schema container and load the properties of this property
            // (will also check whether or not the property exists)
            SearchResult propertiesFromServer = ActiveDirectorySchemaProperty.GetPropertiesFromSchemaContainer(context, _schemaEntry, commonName, true /* isDefunctOnServer */);
            ActiveDirectorySchemaProperty schemaProperty = new ActiveDirectorySchemaProperty(context, commonName, propertiesFromServer, _schemaEntry);

            return schemaProperty;
        }
        public bool Contains(ActiveDirectorySchemaProperty schemaProperty)
        {
            Contract.Requires(schemaProperty != null);

            return(default(bool));
        }
		public static ActiveDirectorySchemaProperty FindByName(DirectoryContext context, string ldapDisplayName)
		{
			if (context != null)
			{
				if (context.Name != null || context.isRootDomain())
				{
					if (context.Name == null || context.isRootDomain() || context.isADAMConfigSet() || context.isServer())
					{
						if (ldapDisplayName != null)
						{
							if (ldapDisplayName.Length != 0)
							{
								context = new DirectoryContext(context);
								ActiveDirectorySchemaProperty activeDirectorySchemaProperty = new ActiveDirectorySchemaProperty(context, ldapDisplayName, (DirectoryEntry)null, (DirectoryEntry)null);
								return activeDirectorySchemaProperty;
							}
							else
							{
								throw new ArgumentException(Res.GetString("EmptyStringParameter"), "ldapDisplayName");
							}
						}
						else
						{
							throw new ArgumentNullException("ldapDisplayName");
						}
					}
					else
					{
						throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
					}
				}
				else
				{
					throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
				}
			}
			else
			{
				throw new ArgumentNullException("context");
			}
		}
        public void AddRange(ActiveDirectorySchemaProperty[] properties)
        {
            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }

            foreach (ActiveDirectorySchemaProperty property in properties)
            {
                if (property == null)
                {
                    throw new ArgumentException("properties");
                }
            }

            for (int i = 0; ((i) < (properties.Length)); i = ((i) + (1)))
            {
                this.Add((ActiveDirectorySchemaProperty)properties[i]);
            }
        }
 public bool Contains(ActiveDirectorySchemaProperty schemaProperty)
 {
     if (schemaProperty == null)
     {
         throw new ArgumentNullException("schemaProperty");
     }
     if (!schemaProperty.isBound)
     {
         throw new InvalidOperationException(Res.GetString("SchemaObjectNotCommitted", new object[] { schemaProperty.Name }));
     }
     for (int i = 0; i < base.InnerList.Count; i++)
     {
         ActiveDirectorySchemaProperty property = (ActiveDirectorySchemaProperty) base.InnerList[i];
         if (Utils.Compare(property.Name, schemaProperty.Name) == 0)
         {
             return true;
         }
     }
     return false;
 }
 public void CopyTo(ActiveDirectorySchemaProperty[] properties, int index)
 {
     List.CopyTo(properties, index);
 }
 public void Remove(ActiveDirectorySchemaProperty schemaProperty)
 {
     if (schemaProperty == null)
     {
         throw new ArgumentNullException("schemaProperty");
     }
     if (!schemaProperty.isBound)
     {
         throw new InvalidOperationException(Res.GetString("SchemaObjectNotCommitted", new object[] { schemaProperty.Name }));
     }
     for (int i = 0; i < base.InnerList.Count; i++)
     {
         ActiveDirectorySchemaProperty property = (ActiveDirectorySchemaProperty) base.InnerList[i];
         if (Utils.Compare(property.Name, schemaProperty.Name) == 0)
         {
             base.List.Remove(property);
             return;
         }
     }
     throw new ArgumentException(Res.GetString("NotFoundInCollection", new object[] { schemaProperty }), "schemaProperty");
 }
 public void Insert(int index, ActiveDirectorySchemaProperty schemaProperty)
 {
     throw new NotImplementedException();
 }
 public int IndexOf(ActiveDirectorySchemaProperty schemaProperty)
 {
     throw new NotImplementedException();
 }
		public void Remove (ActiveDirectorySchemaProperty schemaProperty)
		{
			throw new NotImplementedException ();
		}
示例#31
0
        public int Add(ActiveDirectorySchemaProperty schemaProperty)
        {
            Contract.Requires(schemaProperty != null);

            return(default(int));
        }
		public bool Contains (ActiveDirectorySchemaProperty schemaProperty)
		{
			throw new NotImplementedException ();
		}
 private ArrayList GetProperties(ICollection ldapDisplayNames)
 {
     ArrayList list = new ArrayList();
     SearchResultCollection results = null;
     try
     {
         if (ldapDisplayNames.Count >= 1)
         {
             if (this.schemaEntry == null)
             {
                 this.schemaEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, WellKnownDN.SchemaNamingContext);
             }
             StringBuilder builder = new StringBuilder(100);
             if (ldapDisplayNames.Count > 1)
             {
                 builder.Append("(|");
             }
             foreach (string str in ldapDisplayNames)
             {
                 builder.Append("(");
                 builder.Append(PropertyManager.LdapDisplayName);
                 builder.Append("=");
                 builder.Append(Utils.GetEscapedFilterValue(str));
                 builder.Append(")");
             }
             if (ldapDisplayNames.Count > 1)
             {
                 builder.Append(")");
             }
             string filter = "(&(" + PropertyManager.ObjectCategory + "=attributeSchema)" + builder.ToString() + "(!(" + PropertyManager.IsDefunct + "=TRUE)))";
             string[] propertiesToLoad = new string[] { PropertyManager.LdapDisplayName };
             results = new ADSearcher(this.schemaEntry, filter, propertiesToLoad, SearchScope.OneLevel).FindAll();
             foreach (SearchResult result in results)
             {
                 string searchResultPropertyValue = (string) PropertyManager.GetSearchResultPropertyValue(result, PropertyManager.LdapDisplayName);
                 DirectoryEntry directoryEntry = result.GetDirectoryEntry();
                 directoryEntry.AuthenticationType = Utils.DefaultAuthType;
                 directoryEntry.Username = this.context.UserName;
                 directoryEntry.Password = this.context.Password;
                 ActiveDirectorySchemaProperty property = new ActiveDirectorySchemaProperty(this.context, searchResultPropertyValue, directoryEntry, this.schemaEntry);
                 list.Add(property);
             }
         }
         return list;
     }
     catch (COMException exception)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(this.context, exception);
     }
     finally
     {
         if (results != null)
         {
             results.Dispose();
         }
     }
     return list;
 }
		public int IndexOf (ActiveDirectorySchemaProperty schemaProperty)
		{
			throw new NotImplementedException ();
		}
示例#35
0
 public void Insert(int index, ActiveDirectorySchemaProperty schemaProperty)
 {
     Contract.Requires(schemaProperty != null);
     Contract.Requires(index >= 0);
 }
 public void Remove(ActiveDirectorySchemaProperty schemaProperty)
 {
     throw new NotImplementedException();
 }
		public void Remove(ActiveDirectorySchemaProperty schemaProperty)
		{
			if (schemaProperty != null)
			{
				if (schemaProperty.isBound)
				{
					int num = 0;
					while (num < base.InnerList.Count)
					{
						ActiveDirectorySchemaProperty item = (ActiveDirectorySchemaProperty)base.InnerList[num];
						if (Utils.Compare(item.Name, schemaProperty.Name) != 0)
						{
							num++;
						}
						else
						{
							base.List.Remove(item);
							return;
						}
					}
					object[] objArray = new object[1];
					objArray[0] = schemaProperty;
					throw new ArgumentException(Res.GetString("NotFoundInCollection", objArray), "schemaProperty");
				}
				else
				{
					object[] name = new object[1];
					name[0] = schemaProperty.Name;
					throw new InvalidOperationException(Res.GetString("SchemaObjectNotCommitted", name));
				}
			}
			else
			{
				throw new ArgumentNullException("schemaProperty");
			}
		}
 public bool Contains(ActiveDirectorySchemaProperty schemaProperty)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        ///Function: go through an populates an arrayList containing all writable user attributes.
        /// </summary>
        private void createWriteableAttribList()
        {
            //First, get schemea of properties, both single and multivalued
            //Get current server
            string ADServer = Environment.GetEnvironmentVariable("LOGONSERVER");
            //Remove the "//"
            ADServer = ADServer.Substring(2);
            //Get the selected domain
            string domainName = cboDC.Text.ToString();
            //Concatenate to make full server name
            string fullServerName = ADServer + "." + domainName;
            //MessageBox.Show("The directory context is: " + fullServerName);
            //Specify server stuff                                                                ex. "prjdc.project.com"
            DirectoryContext adamContext = new DirectoryContext(DirectoryContextType.DirectoryServer, fullServerName);
            //MessageBox.Show(adamContext.Name);

            //Get schema for that servers active directory
            ActiveDirectorySchema schema = ActiveDirectorySchema.GetSchema(adamContext);

            /*
            // Test for getting all classes
            foreach (ActiveDirectorySchemaClass schemaClass in schema.FindAllClasses())
            {
                MessageBox.Show(schemaClass.GetAllProperties().ToString());
            }
            */

            //Get the user schema class
            ActiveDirectorySchemaClass schemaClass = schema.FindClass("user");

            //Now that we have the correct class, GET ALL PROPERTIES in that class (these properties themselves are readonly because we don't want to alter them)
            ReadOnlyActiveDirectorySchemaPropertyCollection adPropertyCollection = schemaClass.GetAllProperties(); //There are 342

            //http://stackoverflow.com/questions/4931982/how-can-i-check-if-a-user-has-write-rights-in-active-directory-using-c

            //Find the current logged on user that will be modfying user properties
            string userName = Environment.UserName;
            //Get the users domain
            string userDomainName = Environment.UserDomainName;
            //MessageBox.Show("The domain name which the user is in: " + userDomainName);

            DirectoryEntry de = new DirectoryEntry();
            de.Path = "LDAP://" + userDomainName;
            de.AuthenticationType = AuthenticationTypes.Secure;

            DirectorySearcher deSearch = new DirectorySearcher();

            deSearch.SearchRoot = de;
            deSearch.Filter = "(&(objectClass=user) (cn=" + userName + "))";

            SearchResult result = deSearch.FindOne();

            DirectoryEntry deUser = new DirectoryEntry(result.Path);

            //Refresh Cache to get the values, I guess?
            deUser.RefreshCache(new string[] { "allowedAttributesEffective" });

            // Proof this is the user
            //MessageBox.Show("About to show the username: "******"cn"].Value.ToString());
            //MessageBox.Show("About to show the users distinguished name: " + deUser.Properties["distinguishedName"].Value.ToString());

            //Now get the property["allowedAttributesEffective"] of the user

            //Test on a property that did not have to refresh cache for, just to ensure enumeration was working
            //string propertyName = deUser.Properties["otherHomePhone"].PropertyName;

            string propertyName = deUser.Properties["allowedAttributesEffective"].PropertyName;

            //MessageBox.Show("About to loop through the multi-valued property: " + deUser.Properties["allowedAttributesEffective"].PropertyName);
            //MessageBox.Show("About to loop through the multi-valued property: " + propertyName);
            //MessageBox.Show("Number of elements: " + deUser.Properties[propertyName].Count);

            alWritableProperties.Clear();
            //Go through all the elements of that multi-valued property
            IEnumerator propEnumerator = deUser.Properties[propertyName].GetEnumerator(); //Getting the Enumerator

            propEnumerator.Reset(); //Position at the Beginning

            //Loading Bar for writable properties
            int i = 0;
            ProgressWindow pwBar = new ProgressWindow("Finding Writable User Properties", deUser.Properties[propertyName].Count);
            pwBar.Show();
            pwBar.SetPercentDone(i);

            while (propEnumerator.MoveNext()) //while there is a next one to move to
            {
                //MessageBox.Show("" + propEnumerator.Current.ToString());
                try
                {
                    ActiveDirectorySchemaProperty propertyToTest = new ActiveDirectorySchemaProperty(adamContext, propEnumerator.Current.ToString());
                    //See if property is writable
                    //is property single valued
                    if (adPropertyCollection[adPropertyCollection.IndexOf(propertyToTest)].IsSingleValued == true)
                    {
                        //Single valued comparison
                        deUser.Properties[propEnumerator.Current.ToString()].Value = deUser.Properties[propEnumerator.Current.ToString()].Value;
                    }
                    else
                    {
                        //Multi-valued comparison (Not implemented)

                        //http://stackoverflow.com/questions/5067363/active-directory-unable-to-add-multiple-email-addresses-in-multi-valued-propert

                        //MessageBox.Show("Dealing with multivalued property: " + propEnumerator.Current.ToString());

                        //deUser.Properties[propEnumerator.Current.ToString()].Clear();
                        //deUser.Properties[propEnumerator.Current.ToString()].Count;
                        //MessageBox.Show("Number of elements: " + deUser.Properties[propEnumerator.Current.ToString()].Count.ToString());
                        //deUser.Properties[propEnumerator.Current.ToString()].Value = deUser.Properties[propEnumerator.Current.ToString()].Value;
                        /*
                        if (propEnumerator.Current.ToString().Equals("departmentNumber"))
                        {
                            MessageBox.Show("Number of elements before: " + deUser.Properties[propEnumerator.Current.ToString()].Count.ToString());
                            deUser.Properties[propEnumerator.Current.ToString()].Add("9");
                            MessageBox.Show("Number of elements after: " + deUser.Properties[propEnumerator.Current.ToString()].Count.ToString());
                            //MessageBox.Show("Number of elements before: " + deUser.Properties[propEnumerator.Current.ToString()].Count.ToString());
                            //object tempObject = deUser.Properties[propEnumerator.Current.ToString()].Value;
                            //deUser.Properties[propEnumerator.Current.ToString()].Clear();
                            //MessageBox.Show("Number of elements now cleared: " + deUser.Properties[propEnumerator.Current.ToString()].Count.ToString());
                            //deUser.Properties[propEnumerator.Current.ToString()].Value = tempObject;
                            //MessageBox.Show("Number of elements after: " + deUser.Properties[propEnumerator.Current.ToString()].Count.ToString());
                        }
                        */
                    }

                    deUser.CommitChanges();

                    //Add to array since it is writable
                    alWritableProperties.Add(propEnumerator.Current.ToString());
                }
                catch (Exception e)
                {
                    //MessageBox.Show(propEnumerator.Current.ToString() + " can only be viewed" + e.Message);
                }
                pwBar.SetPercentDone(i++);
            }
            deUser.Close();
            //MessageBox.Show("Number of actual writable properties: " + alWritableProperties.Count);

            //End loading bar
            pwBar.Close();

            // OLD STUFF BELOW

            // http://msdn.microsoft.com/en-us/library/ms180940(v=vs.80).aspx
            //ActiveDirectorySchemaClass
            // http://stackoverflow.com/questions/3290730/how-can-i-read-the-active-directory-schema-programmatically

            // http://msdn.microsoft.com/en-us/library/bb267453.aspx#sdsadintro_topic3_manageschema

            /*
            //Get current server
            string ADServer = Environment.GetEnvironmentVariable("LOGONSERVER");
            //Remove the "//"
            ADServer = ADServer.Substring(2);
            //Get the selected domain
            string domainName = cboDC.Text.ToString();
            //Concatenate to make full server name
            string fullServerName = ADServer + "." + domainName;
            MessageBox.Show("The directory context is: " + fullServerName);
            //Specify server stuff                                                                ex. "prjdc.project.com"
            DirectoryContext adamContext = new DirectoryContext(DirectoryContextType.DirectoryServer, fullServerName);
            MessageBox.Show(adamContext.Name);

            //Get schema for that servers active directory
            ActiveDirectorySchema schema = ActiveDirectorySchema.GetSchema(adamContext);
            */
            /*
            // Test for getting all classes
            foreach (ActiveDirectorySchemaClass schemaClass in schema.FindAllClasses())
            {
                MessageBox.Show(schemaClass.GetAllProperties().ToString());
            }
            */
            /*
            //Get the user schema class
            ActiveDirectorySchemaClass schemaClass = schema.FindClass("user");

            //Now that we have the correct class, GET ALL PROPERTIES in that class (these properties themselves are readonly because we don't want to alter them)
            ReadOnlyActiveDirectorySchemaPropertyCollection adPropertyCollection = schemaClass.GetAllProperties(); //There are 342
            //ActiveDirectorySchemaPropertyCollection adPropertyCollection = schemaClass.OptionalProperties; //There are 335
            //ActiveDirectorySchemaPropertyCollection adPropertyCollection = schemaClass.MandatoryProperties;  //There are 7
            */

            /*
            foreach (ActiveDirectorySchemaProperty schemaProperty in adPropertyCollection)
            {

                // http://msdn.microsoft.com/en-us/library/system.reflection.propertyattributes.aspx
                // Final test with "systemOnly" attribute, if this doesn't work, it won't ever...

                // Get the PropertyAttributes enumeration of the property.
                // Get the type.
                TypeAttributes schemaPropertyAttributes = schemaProperty.GetType().Attributes;
                // Get the property attributes.
                //PropertyInfo schemaPropertyInfo = schemaPropertyType.GetProperty("systemOnly");
                //PropertyAttributes propAttributes = schemaPropertyInfo.Attributes;
                //Display the property attributes value.
                MessageBox.Show("Property: " + schemaProperty.CommonName.ToString() + " has attributes: " + s;

            }
            */

            //Have a fake read-only property
            //ActiveDirectorySchemaProperty fakeProperty = new ActiveDirectorySchemaProperty(adamContext, "cn");
            //AttributeCollection fakePropertyAttributes = TypeDescriptor.GetAttributes(fakeProperty);
            //DirectoryServicesPermissionAttribute a = new DirectoryServicesPermissionAttribute(

            /*
            MessageBox.Show("Does fake property contain read-write attribute: " + fakePropertyAttributes.Contains(ReadOnlyAttribute.No).ToString());

            if (a)
            {
                MessageBox.Show("READ ONLY");
            }
            else
            {
                //Can't be, when try to go fakeProperty.Name = "MEGADEATH" it says can't because prop is read-only
                MessageBox.Show("READ AND WRITE");
            }
            */

            //http://technet.microsoft.com/en-us/library/cc773309(WS.10).aspx

            // CURRENT PROBLEM:
            // Can get all properties, but cannot seem to separate writable from read-only
            // have heard of attributeSchema but no luck
            // now thinking of using systemOnly flag, but no idea how to check for that http://msdn.microsoft.com/en-us/library/aa772300.aspx
            /*
            // Test value of flags using bitwise AND.
            bool test = (meetingDays & Days2.Thursday) == Days2.Thursday; // true
            Console.WriteLine("Thursday {0} a meeting day.", test == true ? "is" : "is not");
            // Output: Thursday is a meeting day.
             *
             */

            /*
            Type type = typeof(ActiveDirectorySchemaProperty);
            object[] ac = type.GetCustomAttributes(true);

            //Test for what's in collection
            MessageBox.Show("Now Testing what is in ReadOnlyActiveDirectorySchemaPropertyCollection");
            int actualNumber = 0;
            foreach (ActiveDirectorySchemaProperty adProperty in adPropertyCollection)
            {
                actualNumber++;

                //MessageBox.Show("Property: " + adProperty.Name + " // Common Name: " + adProperty.CommonName);
                // http://msdn.microsoft.com/en-us/library/system.componentmodel.attributecollection.aspx //
                //Get attributes of that property (ex. is a string, is read only, is writable, etc)
                AttributeCollection attributes = TypeDescriptor.GetAttributes(adProperty);

                //List of systemOnly of the property
                MessageBox.Show("Now showing attributes in current property");

                //attributes.Contains(Attribute.GetCustomAttribute(AssemblyFlagsAttribute"systemOnly",typeof(FlagsAttribute)));
                AssemblyName a = new AssemblyName();
                //https://connid.googlecode.com/svn-history/r169/bundles/ad/trunk/src/main/java/org/connid/ad/schema/ADSchemaBuilder.java

                //AssemblyNameFlags aName = new AssemblyNameFlags();
                //AssemblyFlagsAttribute afa = new AssemblyFlagsAttribute(aName);

                //See if the attributes collection isn't writable
                //if (attributes.Contains(ReadOnlyAttribute.No) == false)
                //if(attributes.Contains(Attribute.GetCustomAttribute(typeof(ActiveDirectorySchemaProperty),"systemOnly")))

                // More freaking testing
                // http://stackoverflow.com/questions/2051065/check-if-property-has-attribute //
                //http://msdn.microsoft.com/en-us/library/cc220922(v=prot.10).aspx

                //Go through all attributes and see if systemOnly is false, if it is then add the property to the array

                //Go through all attributes and see if systemOnly is false, if it is then add the property to the array
                foreach (Attribute currentattribute in attributes)
                {
                    MessageBox.Show(currentattribute.TypeId.ToString());
                }

                /*
                if ()
                {
                    //Cannot read and write
                }
                else
                {
                    //Our property is read/write!
                    //Add the name of the property to our alWritableProperties array list
                    alWritableProperties.Add(adProperty.Name.ToString());
                }
                */

            /*
            }
            MessageBox.Show("Now Seeing what has been added to the writable properties list");
            MessageBox.Show("Number of Properties: " + actualNumber.ToString() + "\nNumber of Writable Properties: " + alWritableProperties.Count);
            */

            /*
            #region Properties of the schema
            /*
            // This will get the properties of the schema class
            PropertyInfo[] aPropertyInfo = schemaClass.GetType().GetProperties();

            //For each property
            foreach (PropertyInfo property in aPropertyInfo)
            {

                MessageBox.Show("Property: " + property.Name);
                /*
                if (property.PropertyType.Assembly == schemaClass.GetType().Assembly)
                {
                    //Show just property
                    MessageBox.Show("Property: " + property.Name);
                }
                else
                {
                    MessageBox.Show("Property: " + property.Name + " Value: " + propValue);
                }
                */
            /*
            }
            */
            /*
            #endregion
            */
            /* http://msdn.microsoft.com/en-us/library/windows/desktop/ms677167(v=vs.85).aspx */
            //IDEA: We get do foreach madatory, and a foreach optional property, put all into huge property array
            //      Then for each property, we do the whole type thing
            //http://stackoverflow.com/questions/6196413/how-to-recursively-print-the-values-of-an-objects-properties-using-reflection

            /*
            //foreach (ActiveDirectorySchemaProperty schemaProperty in schemaClass.MandatoryProperties)
            //ActiveDirectorySchemaPropertyCollection
            //ActiveDirectorySchemaPropertyCollection[] properties = schemaClass.GetType().GetProperties();
            foreach(ActiveDirectorySchemaProperty schemaProperty in schemaClass.MandatoryProperties)
            {
                PropertyInfo[] properties = schemaProperty.GetType().GetProperties();

                //findAttrValue

                //See what we have in the properties MessageBox.Show(properties.GetEnumerator().ToString());

                /*
                http://msdn.microsoft.com/en-us/library/system.componentmodel.defaultvalueattribute(v=vs.71).aspx
                 */
            //[C#]
            // Gets the attributes for the property.
            //AttributeCollection attributes = TypeDescriptor.GetProperties(this)["MyProperty"].Attributes;
            //AttributeCollection attributes = TypeDescriptor.GetProperties(this)[schemaProperty.Name].Attributes;
            //AttributeCollection attributes = [schemaProperty.Name].Attributes;

            //Prints the default value by retrieving the DefaultValueAttribute
            //from the AttributeCollection.
            //DefaultValueAttribute myAttribute = (DefaultValueAttribute)attributes[typeof(DefaultValueAttribute)];
            //MessageBox.Show("The default value is: " + myAttribute.Value.ToString());
            /*
            // Checks to see whether the value of the ReadOnlyAttribute is Yes.
            if (attributes[typeof(ReadOnlyAttribute)].Equals(ReadOnlyAttribute.Yes))
            {
                // Insert code here.
                MessageBox.Show("The Property " + schemaProperty.Name + " is read-only");
            }
            */

            //AttributeCollection attributes = TypeDescriptor.GetProperties(schemaProperty)[schemaProperty.Name].Attributes;
            //Attribute a = attributes[schemaProperty].

            /*
                foreach (PropertyInfo property in properties)
                {
                    MessageBox.Show("Property: " + property.Name);
                }

            }
            */

            /*

            //Find all mandatory properties for the schemaClass
            foreach (ActiveDirectorySchemaProperty schemaProperty in schemaClass.MandatoryProperties)
            {
                MessageBox.Show("Property: " + schemaProperty.ToString());
                MessageBox.Show("Name(what we write to): " + schemaProperty.Name + ", Common Name(Display Name to show on datagridview): " + schemaProperty.CommonName);

                //Determine if it is a writable property

                //To get the CanWrite property, first get the class Type.
                //Type propertyType = Type.GetType(schemaProperty.Name);
                Type propertyType = schemaProperty.GetType();
                //Type propertyType = schemaProperty.Name.GetType();
                //Type propertyType = Type.GetType(schemaProperty.Name);
                //From the Type, get the PropertyInfo. From the PropertyInfo, get the CanWrite value.

                MessageBox.Show("Made it past Type: " + propertyType.ToString());

                PropertyInfo[] properties = propertyType.GetProperties();

                foreach (PropertyInfo property in properties)
                {
                    object propValue = property.GetValue(schemaProperty, null);
                    if (property.PropertyType.Assembly == propertyType.Assembly)
                    {
                        MessageBox.Show("Property: " + property.Name);
                    }
                    else
                    {
                        MessageBox.Show("Property: " + property.Name + " Value: " + propValue);
                    }
                }

                /*
                PropertyInfo propInfo = propertyType.GetProperty(schemaProperty.ToString());

                PropertyAttributes pAttributes = propInfo.Attributes;

                MessageBox.Show("Attributes: " + pAttributes.ToString());
                */
            /*
            //MessageBox.Show("Made it past Info! " + propInfo.CanWrite);

            if (propInfo.CanWrite == true)
            {
                MessageBox.Show("We CAN write to this mofo!");
            }
            else
            {
                MessageBox.Show("We CANNOT write to this mofo!");
            }
            */

            //MessageBox.Show("Can we write to this mofo?  " + propInfo.CanWrite.ToString());

            //Old
            //PropertyInfo[] propInfo = propertyType.GetProperties(BindingFlags.Public | BindingFlags.Instance);

            /* http://msdn.microsoft.com/en-us/library/system.reflection.propertyinfo.canwrite.aspx */

            //using reflection
            /* http://www.codersource.net/microsoft-net/c-basics-tutorials/reflection-in-c.aspx */
            /*
            for (int i = 0; i < propInfo.Length ;i++)
            {
                MessageBox.Show(propInfo[0].ToString());
            }
            */
            /*
            if(propertyType)
            {
                //Since this is a writable property, add it to the array

            }
            */
            /*
            }
            */
        }
示例#40
0
 //
 // This method finds only among non-defunct properties
 //
 public ActiveDirectorySchemaProperty FindProperty(string ldapDisplayName)
 {
     CheckIfDisposed();
     return(ActiveDirectorySchemaProperty.FindByName(context, ldapDisplayName));
 }
示例#41
0
 public void Remove(ActiveDirectorySchemaProperty schemaProperty)
 {
 }