Esempio n. 1
0
        public void RefreshSchema()
        {
            const string baseDN  = "cn=aggregate,cn=schemacontext";
            var          attribs = new string[] { ATTRIBUTETYPES, OBJECTCLASSES, DITCONTENTRULES };
            ILdapMessage ldMsg   = null;

            try {
                List <ILdapEntry> response = _conn.SearchAndGetEntries(baseDN, LdapScope.SCOPE_SUBTREE, "(objectClass=*)", attribs, 0, ref ldMsg);
                if (response.Count == 0)
                {
                    throw new Exception("Failed to get schema");
                }

                LdapEntry baseEntry = (LdapEntry)response [0];
                var       dict      = CollectData(baseEntry);
                ParseAttributes(dict [ATTRIBUTETYPES]);
                ParseObjectClasses(dict [OBJECTCLASSES]);
                ParseContentRules(dict [DITCONTENTRULES]);
            } catch (Exception) {
                throw;
            }
            finally
            {
                if (ldMsg != null)
                {
                    (ldMsg as LdapMessage).FreeMessage();
                }
            }
        }
Esempio n. 2
0
        public void RefreshSchema()

        {
            try
            {
                const string baseDN = "cn=schemacontext";
                ILdapMessage ldMsg  = null;
                try
                {
                    List <ILdapEntry> attributesResponse = _conn.SearchAndGetEntries(baseDN, LdapScope.SCOPE_SUBTREE, "(objectclass=attributeschema)", null, 0, ref ldMsg);
                    List <ILdapEntry> schemaResponse     = _conn.SearchAndGetEntries(baseDN, LdapScope.SCOPE_SUBTREE, "(objectclass=classschema)", null, 0, ref ldMsg);

                    if (attributesResponse.Count == 0 || schemaResponse.Count == 0)
                    {
                        throw new Exception("Failed to get schema");
                    }

                    var schemaDict = new Dictionary <string, Dictionary <string, object> >();
                    var attrDict   = new Dictionary <string, Dictionary <string, object> >();

                    CollectData(schemaResponse, OBJECTCLASSES, schemaDict);
                    CollectData(attributesResponse, ATTRIBUTETYPES, attrDict);
                    ParseAttributes(attrDict);
                    ParseObjectClasses(schemaDict);
                }
                finally
                {
                    if (ldMsg != null)
                    {
                        (ldMsg as LdapMessage).FreeMessage();
                    }
                }
            }
            catch (Exception e)
            {
                if (string.Equals(e.Message, "Failed to get schema"))
                {
                    const string baseDN  = "cn=aggregate,cn=schemacontext";
                    var          attribs = new string[] { ATTRIBUTETYPES, OBJECTCLASSES };
                    ILdapMessage ldMsg   = null;
                    try
                    {
                        List <ILdapEntry> response = _conn.SearchAndGetEntries(baseDN, LdapScope.SCOPE_SUBTREE, "(objectClass=*)", attribs, 0, ref ldMsg);
                        if (response.Count == 0)
                        {
                            throw new Exception("Failed to get schema, possibly server version is incompatible.");
                        }

                        LdapEntry baseEntry = (LdapEntry)response[0];
                        var       dict      = CollectData(baseEntry);
                        ParseAttributes(dict[ATTRIBUTETYPES]);
                        ParseObjectClasses(dict[OBJECTCLASSES]);
                    }
                    finally
                    {
                        if (ldMsg != null)
                        {
                            (ldMsg as LdapMessage).FreeMessage();
                        }
                    }
                }
                else
                {
                    throw e;
                }
            }
        }