LdapPersistSearchControl is a Server Control that allows a client to receive notifications from the server of changes to entries within the searches result set. The client can be notified when an entry is added to the result set, when an entry is deleted from the result set, when a DN has been changed or when and attribute value has been changed.
Inheritance: Novell.Directory.Ldap.LdapControl
コード例 #1
1
        // Constructor
        public PSearchEventSource(
            LdapConnection conn,
            string searchBase,
            int scope,
            string filter,
            string[] attrs,
            bool typesOnly,
            LdapSearchConstraints constraints,
            LdapEventType eventchangetype,
            bool changeonly
            )
        {
            // validate the input arguments
              if ((conn == null)
              || (searchBase == null)
              || (filter == null)
              || (attrs == null))
              {
            throw new ArgumentException("Null argument specified");
              }

              mConnection = conn;
              mSearchBase = searchBase;
              mScope = scope;
              mFilter = filter;
              mAttrs = attrs;
              mTypesOnly = typesOnly;
              mEventChangeType = eventchangetype;

              // make things ready for starting a search operation
              if (constraints == null)
              {
            mSearchConstraints = new LdapSearchConstraints();
              }
              else
              {
            mSearchConstraints = constraints;
              }

              //Create the persistent search control
              LdapPersistSearchControl psCtrl =
            new LdapPersistSearchControl((int)eventchangetype,// any change
                     changeonly, //only get changes
                     true, //return entry change controls
                     true); //control is critcal

              // add the persistent search control to the search constraints
              mSearchConstraints.setControls(psCtrl);
        }
コード例 #2
0
        static void Main(string[] args)
        {
            if ( args.Length != 5)
            {
                Console.WriteLine("Usage:   mono SearchPersist <host name> <ldap port>  <login dn>" + " <password> <search base>" );
                Console.WriteLine("Example: mono SearchPersist Acme.com 389"  + " \"cn=admin,o=Acme\"" + " secret \"ou=sales,o=Acme\"");
                return;
            }

            int ldapVersion  = LdapConnection.Ldap_V3;
            String ldapHost = args[0];
            int ldapPort = Convert.ToInt32(args[1]);;
            String loginDN = args[2];
            String password = args[3];
            String searchBase = args[4];
            LdapSearchQueue queue = null;
            LdapSearchConstraints constraints;
            LdapPersistSearchControl psCtrl;
            LdapConnection lc = new LdapConnection();
            constraints =  new LdapSearchConstraints();

            try
            {
                // connect to the server
                lc.Connect( ldapHost, ldapPort );
                // authenticate to the server
                lc.Bind(ldapVersion, loginDN, password);

                //Create the persistent search control
                psCtrl = new LdapPersistSearchControl(
                    LdapPersistSearchControl.ANY, // any change
                    true,                         //only get changes
                    true,                         //return entry change controls
                    true);                        //control is critcal

                // add the persistent search control to the search constraints
                constraints.setControls( psCtrl );

                // perform the search with no attributes returned
                String[] noAttrs = {LdapConnection.NO_ATTRS};
                queue = lc.Search(
                    searchBase,                // container to search
                    LdapConnection.SCOPE_SUB,  // search container's subtree
                    "(objectClass=*)",         // search filter, all objects
                    noAttrs,                   // don't return attributes
                    false,                     // return attrs and values, ignored
                    null,                      // use default search queue
                    constraints);              // use default search constraints
            }
            catch( LdapException e )
            {
                Console.WriteLine( "Error: " + e.ToString() );
                try { lc.Disconnect(); }
                catch(LdapException e2) {  }
                Environment.Exit(1);
            }
            catch(Exception e)
            {
                Console.WriteLine( "Error: " + e.Message );
                return;
            }

            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)
            {
                System.Console.Out.WriteLine(e.Message);
            }
            catch (System.Threading.ThreadInterruptedException e)
            {
            }

            //Disconnect from the server before exiting
            try
            {
                lc.Abandon(queue); //abandon the search
                lc.Disconnect();
            }
            catch (LdapException e)
            {
                Console.Out.WriteLine();
                Console.Out.WriteLine("Error: " + e.ToString());
            }

            Environment.Exit(0);
        }