Ejemplo n.º 1
0
        IADConnection EstablishConnectionWithLDAP()
        {
            LDAPConnection ldapConnection = new LDAPConnection(Server, Port, Credential);

            Trace.WriteLine("Trying LDAP connection");
            ldapConnection.EstablishConnection();
            Trace.WriteLine("LDAP connection successful");
            return(ldapConnection);
        }
Ejemplo n.º 2
0
        private void EstablishConnection()
        {
            ADWSConnection adwsConnection = null;
            LDAPConnection ldapConnection = new LDAPConnection(Server, Port, Credential);

            try
            {
                adwsConnection = new ADWSConnection(Server, Port, Credential);
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Unable to load ADWS - .Net 2 only ? (" + ex.Message + ")");
            }
            switch (ConnectionType)
            {
            case ADConnectionType.ADWSOnly:
                Trace.WriteLine("Trying ADWS connection");
                adwsConnection.EstablishConnection();
                Trace.WriteLine("ADWS connection successful");
                connection = adwsConnection;
                break;

            case ADConnectionType.LDAPOnly:
                Trace.WriteLine("Trying LDAP connection");
                ldapConnection.EstablishConnection();
                Trace.WriteLine("LDAP connection successful");
                connection = ldapConnection;
                break;

            case ADConnectionType.ADWSThenLDAP:
                try
                {
                    Trace.WriteLine("Trying ADWS connection");
                    adwsConnection.EstablishConnection();
                    Trace.WriteLine("ADWS connection successful");
                    connection = adwsConnection;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Unable to connect to ADWS - trying LDAP");
                    try
                    {
                        ldapConnection.EstablishConnection();
                        Trace.WriteLine("Connected with LDAP");
                        connection = ldapConnection;
                    }
                    catch (Exception ex2)
                    {
                        Trace.WriteLine("LDAP exception: " + ex2.Message);
                        Trace.WriteLine(ex2.StackTrace);
                        Trace.WriteLine("Throwing ADWS Exception again");
                        throw new ActiveDirectoryServerDownException(ex.Message);
                    }
                }
                break;

            case ADConnectionType.LDAPThenADWS:
                try
                {
                    Trace.WriteLine("Trying LDAP connection");
                    ldapConnection.EstablishConnection();
                    Trace.WriteLine("LDAP connection successful");
                    connection = ldapConnection;
                }
                catch (Exception ex)
                {
                    Trace.WriteLine("Unable to connect to LDAP - trying ADWS");
                    try
                    {
                        adwsConnection.EstablishConnection();
                        Trace.WriteLine("Connected with ADWS");
                        connection = adwsConnection;
                    }
                    catch (Exception ex2)
                    {
                        Trace.WriteLine("ADWS exception: " + ex2.Message);
                        Trace.WriteLine(ex2.StackTrace);
                        Trace.WriteLine("Throwing LDAP Exception again");
                        throw new ActiveDirectoryServerDownException(ex.Message);
                    }
                }
                break;
            }
        }