/** * Check the queue for a response. If a response has been received, * print the response information. */ static private bool checkForAChange(LdapResponseQueue queue) { LdapMessage message; bool result = true; try { //check if a response has been received so we don't block //when calling getResponse() if (queue.isResponseReceived()) { message = queue.getResponse(); if (message != null) { // is the response a search result reference? if (message is MonitorEventResponse) { MonitorEventResponse eventerrorresponse = (MonitorEventResponse)message; Console.WriteLine("\nError in Registration ResultCode = " + eventerrorresponse.ResultCode); EdirEventSpecifier[] specifiers = eventerrorresponse.SpecifierList; for (int i = 0; i < specifiers.Length; i++) { Console.WriteLine("Specifier:" + "EventType = " + specifiers[i].EventType); } Environment.Exit(-1); } // is the response a event response ? else if (message is EdirEventIntermediateResponse) { Console.WriteLine("Edir Event Occured"); EdirEventIntermediateResponse eventresponse = (EdirEventIntermediateResponse)message; //process the eventresponse Data, depending on the // type of response processEventData(eventresponse.EventResponseDataObject, eventresponse.EventType); } // the message is a Unknown response else { Console.WriteLine("UnKnown Message =" + message); } } } } catch (LdapException e) { Console.WriteLine("Error: " + e.ToString()); result = false; } return(result); }
protected override void StartSearchAndPolling() { mQueue = mConnection.ExtendedOperation(mRequestOperation, null, null); int[] ids = mQueue.MessageIDs; if (ids.Length != 1) { throw new LdapException( null, LdapException.LOCAL_ERROR, "Unable to Obtain Message Id" ); } StartEventPolling(mQueue, mConnection, ids[0]); }
protected override void StartSearchAndPolling() { mQueue = mConnection.ExtendedOperation(mRequestOperation, null, null); int[] ids = mQueue.MessageIDs; if (ids.Length != 1) { throw new LdapException( null, LdapException.LOCAL_ERROR, "Unable to Obtain Message Id" ); } StartEventPolling(mQueue, mConnection, ids[0]); }
public static void Main(String[] args) { if (args.Length != 3) { Console.WriteLine( "Usage: mono EdirEventSample <host name> <login dn>" + " <password> "); Console.WriteLine( "Example: mono EdirEventSample Acme.com \"cn=admin,o=Acme\"" + " secret "); Environment.Exit(0); } int ldapPort = LdapConnection.DEFAULT_PORT; int ldapVersion = LdapConnection.Ldap_V3; String ldapHost = args[0]; String loginDN = args[1]; String password = args[2]; LdapResponseQueue queue = null; LdapConnection lc = new LdapConnection(); try { // connect to the server lc.Connect(ldapHost, ldapPort); // authenticate to the server lc.Bind(ldapVersion, loginDN, password); //Create an Array of EdirEventSpecifier EdirEventSpecifier[] specifier = new EdirEventSpecifier[1]; //Register for all Add Value events. specifier[0] = new EdirEventSpecifier(EdirEventType.EVT_CREATE_ENTRY, //Generate an Value Event of Type Add Value EdirEventResultType.EVT_STATUS_ALL //Generate Event for all status ); //Create an MonitorEventRequest using the specifiers. MonitorEventRequest requestoperation = new MonitorEventRequest(specifier); //Send the request to server and get the response queue. queue = lc.ExtendedOperation(requestoperation, null, null); } catch (LdapException e) { Console.WriteLine("Error: " + e.ToString()); try { lc.Disconnect(); } catch (LdapException e2) { Console.WriteLine("Error: " + e2.ToString()); } Environment.Exit(1); } catch (Exception e) { Console.WriteLine("Error: " + e.ToString()); } Console.WriteLine("Monitoring the events for {0} minutes..", TIME_OUT_IN_MINUTES); Console.WriteLine(); //Set the timeout value timeOut = DateTime.Now.AddMinutes(TIME_OUT_IN_MINUTES); try { //Monitor till the timeout happens while (DateTime.Now.CompareTo(timeOut) < 0) { if (!checkForAChange(queue)) { break; } System.Threading.Thread.Sleep(10); } } catch (System.IO.IOException e) { Console.WriteLine(e.Message); } catch (System.Threading.ThreadInterruptedException e) { Console.WriteLine(e.Message); } //disconnect from the server before exiting try { lc.Abandon(queue); //abandon the search lc.Disconnect(); } catch (LdapException e) { Console.WriteLine(); Console.WriteLine("Error: " + e.ToString()); } Environment.Exit(0); } // end main
/// <summary> Merges two message queues. It appends the current and /// future contents from another queue to this one. /// /// After the operation, queue2.getMessageIDs() /// returns an empty array, and its outstanding responses /// have been removed and appended to this queue. /// /// </summary> /// <param name="queue2"> The queue that is merged from. Following /// the merge, this queue object will no /// longer receive any data, and calls made /// to its methods will fail with a RuntimeException. /// The queue can be reactivated by using it in an /// Ldap request, after which it will receive responses /// for that request.. /// </param> public virtual void merge(LdapMessageQueue queue2) { LdapResponseQueue q = (LdapResponseQueue)queue2; agent.merge(q.MessageAgent); }