2010-03-02 Jb Evain <jbevain@novell.com>
[mcs.git] / class / Novell.Directory.Ldap / Novell.Directory.Ldap.Events.Edir / MonitorEventRequest.cs
blob236f3e32afa9a1fb5d86e2f8fb0576575b8e4c05
1 /******************************************************************************
2 * The MIT License
3 * Copyright (c) 2003 Novell Inc. www.novell.com
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the Software), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *******************************************************************************/
24 // Novell.Directory.Ldap.Events.Edir.MonitorEventRequest.cs
26 // Author:
27 // Anil Bhatia (banil@novell.com)
29 // (C) 2003 Novell, Inc (http://www.novell.com)
33 using System;
34 using System.IO;
36 using Novell.Directory.Ldap.Utilclass;
37 using Novell.Directory.Ldap.Asn1;
39 namespace Novell.Directory.Ldap.Events.Edir
41 /// <summary>
42 /// This class denotes the mechanism to specify the event of interest.
43 /// </summary>
44 public class MonitorEventRequest : LdapExtendedOperation
46 static MonitorEventRequest()
49 * Register the extendedresponse class which is returned by the
50 * server in response to a MonitorEventRequest
52 try
54 LdapExtendedResponse.register(EventOids.NLDAP_MONITOR_EVENTS_RESPONSE,
55 Type.GetType("Novell.Directory.Ldap.Events.Edir.MonitorEventResponse", true));
57 catch(TypeLoadException e)
59 // TODO: put something in the Debug...
61 catch(Exception e)
63 // TODO: put something in the Debug...
66 //Also try to register EdirEventIntermediateResponse
67 try
69 LdapIntermediateResponse.register(EventOids.NLDAP_EVENT_NOTIFICATION,
70 Type.GetType("Novell.Directory.Ldap.Events.Edir.EdirEventIntermediateResponse", true));
72 catch(TypeLoadException e)
74 // TODO: put something in the Debug...
76 catch(Exception e)
78 // TODO: put something in the Debug...
80 } // end of static constructor
82 public MonitorEventRequest(EdirEventSpecifier[] specifiers) :
83 base(EventOids.NLDAP_MONITOR_EVENTS_REQUEST, null)
85 if ((specifiers == null))
87 throw new ArgumentException(ExceptionMessages.PARAM_ERROR);
90 MemoryStream encodedData = new MemoryStream();
91 LBEREncoder encoder = new LBEREncoder();
93 Asn1Sequence asnSequence = new Asn1Sequence();
94 try
96 asnSequence.add(new Asn1Integer(specifiers.Length));
98 Asn1Set asnSet = new Asn1Set();
99 bool bFiltered = false;
100 for (int nIndex = 0; nIndex < specifiers.Length; nIndex++)
102 Asn1Sequence specifierSequence = new Asn1Sequence();
103 specifierSequence.add(new Asn1Integer((int)(specifiers[nIndex].EventType)));
104 specifierSequence.add(new Asn1Enumerated((int)(specifiers[nIndex].EventResultType)));
105 if (0 == nIndex)
107 bFiltered = (null != specifiers[nIndex].EventFilter);
108 if (bFiltered)
109 setID(EventOids.NLDAP_FILTERED_MONITOR_EVENTS_REQUEST);
112 if (bFiltered)
114 // A filter is expected
115 if (null == specifiers[nIndex].EventFilter)
116 throw new ArgumentException("Filter cannot be null,for Filter events");
118 specifierSequence.add(new Asn1OctetString(specifiers[nIndex].EventFilter));
120 else
122 // No filter is expected
123 if (null != specifiers[nIndex].EventFilter)
124 throw new ArgumentException("Filter cannot be specified for non Filter events");
127 asnSet.add(specifierSequence);
130 asnSequence.add(asnSet);
131 asnSequence.encode(encoder, encodedData);
133 catch(Exception e)
135 throw new LdapException(ExceptionMessages.ENCODING_ERROR,
136 LdapException.ENCODING_ERROR,
137 null);
140 setValue(SupportClass.ToSByteArray(encodedData.ToArray()));
141 } // end of the constructor MonitorEventRequest