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; } }