| 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: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice shall be included in |
| 13 |
* all copies or substantial portions of the Software. |
| 14 |
* |
| 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 |
*******************************************************************************/ |
| 23 |
// |
| 24 |
// Novell.Directory.Ldap.Events.Edir.MonitorEventRequest.cs |
| 25 |
// |
| 26 |
// Author: |
| 27 |
// Anil Bhatia ([email protected]) |
| 28 |
// |
| 29 |
// (C) 2003 Novell, Inc (http://www.novell.com) |
| 30 |
// |
| 31 |
|
| 32 |
|
| 33 |
using System; |
| 34 |
using System.IO; |
| 35 |
|
| 36 |
using Novell.Directory.Ldap.Utilclass; |
| 37 |
using Novell.Directory.Ldap.Asn1; |
| 38 |
|
| 39 |
namespace Novell.Directory.Ldap.Events.Edir |
| 40 |
{ |
| 41 |
/// <summary> |
| 42 |
/// This class denotes the mechanism to specify the event of interest. |
| 43 |
/// </summary> |
| 44 |
public class MonitorEventRequest : LdapExtendedOperation |
| 45 |
{ |
| 46 |
static MonitorEventRequest() |
| 47 |
{ |
| 48 |
/* |
| 49 |
* Register the extendedresponse class which is returned by the |
| 50 |
* server in response to a MonitorEventRequest |
| 51 |
*/ |
| 52 |
try |
| 53 |
{ |
| 54 |
LdapExtendedResponse.register(EventOids.NLDAP_MONITOR_EVENTS_RESPONSE, |
| 55 |
Type.GetType("Novell.Directory.Ldap.Events.Edir.MonitorEventResponse", true)); |
| 56 |
} |
| 57 |
catch(TypeLoadException e) |
| 58 |
{ |
| 59 |
// TODO: put something in the Debug... |
| 60 |
} |
| 61 |
catch(Exception e) |
| 62 |
{ |
| 63 |
// TODO: put something in the Debug... |
| 64 |
} |
| 65 |
|
| 66 |
//Also try to register EdirEventIntermediateResponse |
| 67 |
try |
| 68 |
{ |
| 69 |
LdapIntermediateResponse.register(EventOids.NLDAP_EVENT_NOTIFICATION, |
| 70 |
Type.GetType("Novell.Directory.Ldap.Events.Edir.EdirEventIntermediateResponse", true)); |
| 71 |
} |
| 72 |
catch(TypeLoadException e) |
| 73 |
{ |
| 74 |
// TODO: put something in the Debug... |
| 75 |
} |
| 76 |
catch(Exception e) |
| 77 |
{ |
| 78 |
// TODO: put something in the Debug... |
| 79 |
} |
| 80 |
} // end of static constructor |
| 81 |
|
| 82 |
public MonitorEventRequest(EdirEventSpecifier[] specifiers) : |
| 83 |
base(EventOids.NLDAP_MONITOR_EVENTS_REQUEST, null) |
| 84 |
{ |
| 85 |
if ((specifiers == null)) |
| 86 |
{ |
| 87 |
throw new ArgumentException(ExceptionMessages.PARAM_ERROR); |
| 88 |
} |
| 89 |
|
| 90 |
MemoryStream encodedData = new MemoryStream(); |
| 91 |
LBEREncoder encoder = new LBEREncoder(); |
| 92 |
|
| 93 |
Asn1Sequence asnSequence = new Asn1Sequence(); |
| 94 |
try |
| 95 |
{ |
| 96 |
asnSequence.add(new Asn1Integer(specifiers.Length)); |
| 97 |
|
| 98 |
Asn1Set asnSet = new Asn1Set(); |
| 99 |
bool bFiltered = false; |
| 100 |
for (int nIndex = 0; nIndex < specifiers.Length; nIndex++) |
| 101 |
{ |
| 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) |
| 106 |
{ |
| 107 |
bFiltered = (null != specifiers[nIndex].EventFilter); |
| 108 |
if (bFiltered) |
| 109 |
setID(EventOids.NLDAP_FILTERED_MONITOR_EVENTS_REQUEST); |
| 110 |
} |
| 111 |
|
| 112 |
if (bFiltered) |
| 113 |
{ |
| 114 |
// A filter is expected |
| 115 |
if (null == specifiers[nIndex].EventFilter) |
| 116 |
throw new ArgumentException("Filter cannot be null,for Filter events"); |
| 117 |
|
| 118 |
specifierSequence.add(new Asn1OctetString(specifiers[nIndex].EventFilter)); |
| 119 |
} |
| 120 |
else |
| 121 |
{ |
| 122 |
// No filter is expected |
| 123 |
if (null != specifiers[nIndex].EventFilter) |
| 124 |
throw new ArgumentException("Filter cannot be specified for non Filter events"); |
| 125 |
} |
| 126 |
|
| 127 |
asnSet.add(specifierSequence); |
| 128 |
} |
| 129 |
|
| 130 |
asnSequence.add(asnSet); |
| 131 |
asnSequence.encode(encoder, encodedData); |
| 132 |
} |
| 133 |
catch(Exception e) |
| 134 |
{ |
| 135 |
throw new LdapException(ExceptionMessages.ENCODING_ERROR, |
| 136 |
LdapException.ENCODING_ERROR, |
| 137 |
null); |
| 138 |
} |
| 139 |
|
| 140 |
setValue(SupportClass.ToSByteArray(encodedData.ToArray())); |
| 141 |
} // end of the constructor MonitorEventRequest |
| 142 |
} |
| 143 |
} |