Returns a count of the number of entries (objects) in the specified partition. To obtain the count of entries, you must create an instance of this class and then call the extendedOperation method with this object as the required LdapExtendedOperation parameter. The returned LdapExtendedResponse object can then be converted to a PartitionEntryCountResponse object. This class contains methods for retrieving the returned count. The PartitionEntryCountRequest extension uses the following OID: 2.16.840.1.113719.1.27.100.13 The requestValue has the following format: requestValue ::= dn LdapDN
Inheritance: Novell.Directory.Ldap.LdapExtendedOperation
Ejemplo n.º 1
0
    public static void Main(System.String[] args)
    {
        if (args.Length != 5)
        {
            System.Console.Error.WriteLine("Usage:   mono PartitionEntryCount <host Name> " + "<port number> <login dn> <password>" + "\n         <partition dn>");
            System.Console.Error.WriteLine("Example: mono PartitionEntryCount Acme.com 389 " + "\"cn=Admin,o=Acme\" secret" + "\n         \"ou=Sales,o=Acme\"");
            System.Environment.Exit(1);
        }

        int LdapVersion = LdapConnection.Ldap_V3;
        System.String LdapHost = args[0];
        int LdapPort = System.Int32.Parse(args[1]);
        System.String loginDN = args[2];
        System.String password = args[3];
        System.String partitionDN = args[4];
        int count = 0;
        LdapConnection ld = new LdapConnection();

        try
        {
            // connect to the server
            ld.Connect(LdapHost, LdapPort);
            // bind to the server
            ld.Bind(LdapVersion, loginDN, password);
            System.Console.Out.WriteLine("\nLogin succeeded");

            LdapExtendedOperation request = new PartitionEntryCountRequest(partitionDN);

            LdapExtendedResponse response = ld.ExtendedOperation(request);

            if ((response.ResultCode == LdapException.SUCCESS) && (response is PartitionEntryCountResponse))
            {
                count = ((PartitionEntryCountResponse) response).Count;
                System.Console.Out.WriteLine("\n    Entry count of partition " + partitionDN + " is: " + count);

                System.Console.Out.WriteLine("\nPartitionEntryCount succeeded\n");
            }
            else
            {
                System.Console.Out.WriteLine("\nPartitionEntryCount Failed");
                throw new LdapException(response.ErrorMessage, response.ResultCode, (System.String) null);
            }

            /* Done, so disconnect */
            if (ld.Connected)
                ld.Disconnect();
        }
        catch (LdapException e)
        {
            System.Console.Out.WriteLine("Error: " + e.LdapErrorMessage);
        }
        catch(Exception e)
        {
            Console.WriteLine("Error:" + e.Message);
            return;
        }
    }
    public static void  Main(System.String[] args)
    {
        if (args.Length != 5)
        {
            System.Console.Error.WriteLine("Usage:   mono PartitionEntryCount <host Name> " + "<port number> <login dn> <password>" + "\n         <partition dn>");
            System.Console.Error.WriteLine("Example: mono PartitionEntryCount Acme.com 389 " + "\"cn=Admin,o=Acme\" secret" + "\n         \"ou=Sales,o=Acme\"");
            System.Environment.Exit(1);
        }

        int LdapVersion = LdapConnection.Ldap_V3;

        System.String LdapHost = args[0];
        int           LdapPort = System.Int32.Parse(args[1]);

        System.String  loginDN     = args[2];
        System.String  password    = args[3];
        System.String  partitionDN = args[4];
        int            count       = 0;
        LdapConnection ld          = new LdapConnection();

        try
        {
            // connect to the server
            ld.Connect(LdapHost, LdapPort);
            // bind to the server
            ld.Bind(LdapVersion, loginDN, password);
            System.Console.Out.WriteLine("\nLogin succeeded");

            LdapExtendedOperation request = new PartitionEntryCountRequest(partitionDN);

            LdapExtendedResponse response = ld.ExtendedOperation(request);

            if ((response.ResultCode == LdapException.SUCCESS) && (response is PartitionEntryCountResponse))
            {
                count = ((PartitionEntryCountResponse)response).Count;
                System.Console.Out.WriteLine("\n    Entry count of partition " + partitionDN + " is: " + count);

                System.Console.Out.WriteLine("\nPartitionEntryCount succeeded\n");
            }
            else
            {
                System.Console.Out.WriteLine("\nPartitionEntryCount Failed");
                throw new LdapException(response.ErrorMessage, response.ResultCode, (System.String)null);
            }

            /* Done, so disconnect */
            if (ld.Connected)
            {
                ld.Disconnect();
            }
        }
        catch (LdapException e)
        {
            System.Console.Out.WriteLine("Error: " + e.LdapErrorMessage);
        }
        catch (Exception e)
        {
            Console.WriteLine("Error:" + e.Message);
            return;
        }
    }