This class denotes the mechanism to specify the event of interest.
コード例 #1
0
ファイル: MonitorEventRequest.cs プロジェクト: nickchal/pash
    } // end of static constructor

    public MonitorEventRequest(EdirEventSpecifier[] specifiers) :
      base(EventOids.NLDAP_MONITOR_EVENTS_REQUEST, null)
    {
      if ((specifiers == null)) 
      {
	throw new ArgumentException(ExceptionMessages.PARAM_ERROR);
      }

      MemoryStream encodedData = new MemoryStream();
      LBEREncoder encoder = new LBEREncoder();

      Asn1Sequence asnSequence = new Asn1Sequence();
      try
      {
	asnSequence.add(new Asn1Integer(specifiers.Length));

	Asn1Set asnSet = new Asn1Set();
	bool bFiltered = false;
	for (int nIndex = 0; nIndex < specifiers.Length; nIndex++)
	{
	  Asn1Sequence specifierSequence = new Asn1Sequence();
	  specifierSequence.add(new Asn1Integer((int)(specifiers[nIndex].EventType)));
	  specifierSequence.add(new Asn1Enumerated((int)(specifiers[nIndex].EventResultType)));
	  if (0 == nIndex)
	  {
	    bFiltered = (null != specifiers[nIndex].EventFilter);
	    if (bFiltered)
	      setID(EventOids.NLDAP_FILTERED_MONITOR_EVENTS_REQUEST);
	  }
	  
	  if (bFiltered)
	  {
	    // A filter is expected
	    if (null == specifiers[nIndex].EventFilter)
	      throw new ArgumentException("Filter cannot be null,for Filter events");

	    specifierSequence.add(new Asn1OctetString(specifiers[nIndex].EventFilter));
	  }
	  else
	  {
	    // No filter is expected
	    if (null != specifiers[nIndex].EventFilter)
	      throw new ArgumentException("Filter cannot be specified for non Filter events");	 
	  }

	  asnSet.add(specifierSequence);
	}

	asnSequence.add(asnSet);
	asnSequence.encode(encoder, encodedData);
      }
      catch(Exception e)
      {
	throw new LdapException(ExceptionMessages.ENCODING_ERROR,
				LdapException.ENCODING_ERROR, 
				null);
      }

      setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
    } // end of the constructor MonitorEventRequest
コード例 #2
0
        public MonitorEventResponse(RfcLdapMessage message)
            : base(message)
        {
            sbyte[] returnedValue = Value;

            if (null == returnedValue)
            {
                throw new LdapException(LdapException.resultCodeToString(ResultCode),
                                        ResultCode,
                                        null);
            }

            LBERDecoder decoder = new LBERDecoder();

            Asn1Sequence sequence = (Asn1Sequence)decoder.decode(returnedValue);

            int     length      = ((Asn1Integer)sequence.get_Renamed(0)).intValue();
            Asn1Set sequenceSet = (Asn1Set)sequence.get_Renamed(1);

            specifier_list = new EdirEventSpecifier[length];

            for (int i = 0; i < length; i++)
            {
                Asn1Sequence eventspecifiersequence =
                    (Asn1Sequence)sequenceSet.get_Renamed(i);
                int classfication =
                    ((Asn1Integer)eventspecifiersequence.get_Renamed(0)).intValue();
                int enumtype =
                    ((Asn1Enumerated)eventspecifiersequence.get_Renamed(1)).intValue();
                specifier_list[i] =
                    new EdirEventSpecifier((EdirEventType)classfication, (EdirEventResultType)enumtype);
            }
        }
コード例 #3
0
ファイル: MonitorEventResponse.cs プロジェクト: nickchal/pash
    public MonitorEventResponse(RfcLdapMessage message)
      : base(message)
    {
      sbyte[] returnedValue = Value;
      
      if (null == returnedValue)
      {
	throw new LdapException(LdapException.resultCodeToString(ResultCode),
				ResultCode, 
				null);
      }

      LBERDecoder decoder = new LBERDecoder();

      Asn1Sequence sequence = (Asn1Sequence) decoder.decode(returnedValue);
      
      int length = ((Asn1Integer) sequence.get_Renamed(0)).intValue();
      Asn1Set sequenceSet = (Asn1Set) sequence.get_Renamed(1);
      specifier_list = new EdirEventSpecifier[length];

      for (int i = 0; i < length; i++) 
      {
	Asn1Sequence eventspecifiersequence =
                (Asn1Sequence) sequenceSet.get_Renamed(i);
	int classfication =
                ((Asn1Integer) eventspecifiersequence.get_Renamed(0)).intValue();
	int enumtype =
	  ((Asn1Enumerated) eventspecifiersequence.get_Renamed(1)).intValue();
	specifier_list[i] =
	  new EdirEventSpecifier((EdirEventType)classfication, (EdirEventResultType)enumtype);
        }
    }
コード例 #4
0
        public EdirEventSource(EdirEventSpecifier[] specifier, LdapConnection conn)
        {
            if ((null == specifier) || (null == conn))
            throw new ArgumentException("Null argument specified");

              mRequestOperation = new MonitorEventRequest(specifier);
              mConnection = conn;
        }
コード例 #5
0
    protected void Execute(string ldapHost, 
        string ldapPort,
        string loginDN,
        string password)
    {
        // Connect to the LDAP Server
        LdapConnection connection = new LdapConnection();

        try
        {
          connection.Connect(ldapHost, int.Parse(ldapPort));
          connection.Bind(loginDN, password);
        }
        catch(Exception e)
        {
          Console.WriteLine("Exception occurred: {0}", e.Message);
          try
          {
        connection.Disconnect();
          }
          catch(Exception e2)
          {
          }
          Environment.Exit(1);
        }

        Console.WriteLine(STARTING_PROMPT);

        EdirEventSpecifier[] specifier = new EdirEventSpecifier[1];
        specifier[0] = new EdirEventSpecifier(
                      EdirEventType.EVT_CREATE_ENTRY,
                      EdirEventResultType.EVT_STATUS_ALL
                      //, we could have optionally specified a filter here like "(attributeName=city)"
                      );

        // Make an object of EdirEventSource
        EdirEventSource objEventSource = new EdirEventSource(specifier, connection);

        // register for events
        objEventSource.EdirEvent += new EdirEventSource.EdirEventHandler(MyEdirEventHandler);

        // Another listener can be easily added
        objEventSource.EdirEvent += new EdirEventSource.EdirEventHandler(MyEdirEventHandler02);

        // Add a listener for generic directory event
        objEventSource.DirectoryEvent += new EdirEventSource.DirectoryEventHandler(MyDirectoryEventHandler);

        // Add a listener for exception event
        objEventSource.DirectoryExceptionEvent += new EdirEventSource.DirectoryExceptionEventHandler(MyDirectoryExceptionEventHandler);

        string input;
        bool bContinue;
        do
        {
          Console.WriteLine(QUIT_PROMPT);
          input = Console.ReadLine();
          bContinue = (input != null) && !(input.StartsWith("q")) && !( input.StartsWith("Q"));
        } while(bContinue);

        // time to unregister
        objEventSource.EdirEvent -= new EdirEventSource.EdirEventHandler(MyEdirEventHandler);

        objEventSource.EdirEvent -= new EdirEventSource.EdirEventHandler(MyEdirEventHandler02);

        objEventSource.DirectoryEvent -= new EdirEventSource.DirectoryEventHandler(MyDirectoryEventHandler);

        objEventSource.DirectoryExceptionEvent -= new EdirEventSource.DirectoryExceptionEventHandler(MyDirectoryExceptionEventHandler);

        // Disconnect
        try
        {
          connection.Disconnect();
        }
        catch(Exception e)
        {
        }
    }
コード例 #6
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);
    }