Author: borisk
Date: 2005-03-31 01:19:04 -0500 (Thu, 31 Mar 2005)
New Revision: 42415
Modified:
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/ChangeLog
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/DirectoryEntry.cs
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/PropertyCollection.cs
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/PropertyValueCollection.cs
Log:
DirectoryEntry.cs :
- Implemented UsePropertyCache.
- Refresh entry after Rename and MoveTo.
- CommitChanges : do not send request to server if no properties changed. Drop
new flag after committing newly created entry.
- Disconnect only if connected in Close(). Clean up Dispose().
- Removed unnecessary console output.
PropertyCollection.cs : Hold reference to parent DirectoryEntry.
PropertyValueCollection.cs : Hold reference to parent DirectoryEntry. Call
parent's CommitDeferred on collection changes.
Modified:
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/ChangeLog
===================================================================
--- trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/ChangeLog
2005-03-31 06:16:18 UTC (rev 42414)
+++ trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/ChangeLog
2005-03-31 06:19:04 UTC (rev 42415)
@@ -1,5 +1,15 @@
2005-03-31 Boris Kirzner <[EMAIL PROTECTED]>
+ * DirectoryEntry.cs :
+ - Implemented UsePropertyCache.
+ - Refresh entry after Rename and MoveTo.
+ - CommitChanges : do not send request to server if no
properties changed. Drop new flag after committing newly created entry.
+ - Disconnect only if connected in Close(). Clean up Dispose().
+ - Removed unnecessary console output.
+ * PropertyCollection.cs : Hold reference to parent DirectoryEntry.
+ * PropertyValueCollection.cs : Hold reference to parent DirectoryEntry.
Call parent's CommitDeferred on collection changes.
+2005-03-31 Boris Kirzner <[EMAIL PROTECTED]>
+
* DirectorySearcher.cs :
- Use common TimeSpan object to initialize properties default
values.
- DoSearch uses SizeLimit and ServerTimeLimit. Do not throw if
sie limit or time limit occurs on the server.
Modified:
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/DirectoryEntry.cs
===================================================================
---
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/DirectoryEntry.cs
2005-03-31 06:16:18 UTC (rev 42414)
+++
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/DirectoryEntry.cs
2005-03-31 06:19:04 UTC (rev 42415)
@@ -60,15 +60,16 @@
private PropertyCollection _Properties = null;
private string _SchemaClassName=null;
private bool _Nflag = false;
- private bool _disposed;
+ private bool _usePropertyCache=true;
+ private bool _inPropertiesLoading;
/// <summary>
/// Returns entry's Fully distinguished name.
/// </summary>
internal string Fdn
{
- get {
- if (_Fdn == null)
{
+ get {
+ if (_Fdn == null) {
LdapUrl lUrl = new LdapUrl(Path);
string fDn=lUrl.getDN();
if(fDn != null)
@@ -123,11 +124,9 @@
_conn.Bind(Username,Password);
}
catch(LdapException ex) {
- Console.WriteLine("Error:" +
ex.LdapErrorMessage);
throw ex;
}
catch(Exception e) {
- Console.WriteLine("Error:" + e.Message);
throw e;
}
}
@@ -389,15 +388,13 @@
[DefaultValue (true)]
public bool UsePropertyCache
{
- [MonoTODO]
get
{
- throw new NotImplementedException();
+ return _usePropertyCache;
}
- [MonoTODO]
set
{
- throw new NotImplementedException();
+ _usePropertyCache = value;
}
}
@@ -506,7 +503,8 @@
get {
if ( _Properties == null )
{
- _Properties = new PropertyCollection();
+ _Properties = new
PropertyCollection(this);
+ _inPropertiesLoading = true;
try
{
LdapSearchResults
lsc=conn.Search( Fdn,
@@ -521,7 +519,6 @@
nextEntry =
lsc.next();
}
catch(LdapException e)
{
-
Console.WriteLine("Error: " + e.LdapErrorMessage);
// Exception is
thrown, go for next entry
throw e;
}
@@ -544,7 +541,9 @@
if(le.ResultCode ==
LdapException.NO_SUCH_OBJECT)
{ }
}
-
+ finally {
+ _inPropertiesLoading = false;
+ }
}
return _Properties;
}
@@ -580,7 +579,7 @@
public DirectoryEntry SchemaEntry
{
[MonoTODO]
- get {
+ get {
throw new NotImplementedException();
}
}
@@ -606,7 +605,6 @@
nextEntry = lsc.next();
}
catch(LdapException e) {
- Console.WriteLine("Error: " +
e.LdapErrorMessage);
// Exception is thrown, go for next
entry
throw e;
}
@@ -672,7 +670,6 @@
}
catch(LdapException e)
{
- Console.WriteLine("Error: " +
e.LdapErrorMessage);
// Exception is thrown, go for
next entry
throw e;
}
@@ -708,7 +705,9 @@
/// </remarks>
public void Close()
{
- conn.Disconnect();
+ if (conn.Connected) {
+ conn.Disconnect();
+ }
}
/// <summary>
@@ -772,7 +771,11 @@
/// </param>
public void MoveTo(DirectoryEntry newParent)
{
+ string oldParentFdn = Parent.Fdn;
conn.Rename(Fdn, Name, newParent.Fdn, true);
+ // TBD : threat multiple name instance in path
+ Path = Path.Replace(oldParentFdn,newParent.Fdn);
+ RefreshEntry();
}
/// <summary>
@@ -788,7 +791,11 @@
public void MoveTo( DirectoryEntry newParent,
string newName )
{
+ string oldParentFdn = Parent.Fdn;
conn.Rename(Fdn, newName, newParent.Fdn, true);
+ // TBD : threat multiple name instance in path
+ Path =
Path.Replace(oldParentFdn,newParent.Fdn).Replace(Name,newName);
+ RefreshEntry();
}
/// <summary>
@@ -802,7 +809,11 @@
/// </remarks>
public void Rename( string newName )
{
+ string oldName = Name;
conn.Rename( Fdn, newName, true);
+ // TBD : threat multiple name instance in path
+ Path = Path.Replace(oldName,newName);
+ RefreshEntry();
}
/// <summary>
@@ -851,6 +862,14 @@
/// </remarks>
public void CommitChanges()
{
+ if(UsePropertyCache)
+ {
+ CommitEntry();
+ }
+ }
+
+ private void CommitEntry()
+ {
if(!Nflag)
{
System.Collections.ArrayList modList = new
System.Collections.ArrayList();
@@ -876,12 +895,13 @@
modList.Add( new
LdapModification(LdapModification.REPLACE, attr));
Properties[attribute].Mbit=false;
}
-// Console.WriteLine(attribute + "Total no
of attr value" + Properties[attribute].Count);
}
- LdapModification[] mods = new
LdapModification[modList.Count];
- Type
mtype=Type.GetType("System.DirectoryServices.LdapModification");
- mods =
(LdapModification[])modList.ToArray(typeof(LdapModification));
- ModEntry(mods);
+ if (modList.Count > 0) {
+ LdapModification[] mods = new
LdapModification[modList.Count];
+ Type
mtype=Type.GetType("System.DirectoryServices.LdapModification");
+ mods =
(LdapModification[])modList.ToArray(typeof(LdapModification));
+ ModEntry(mods);
+ }
}
else
{
@@ -890,7 +910,6 @@
while(id.MoveNext())
{
string attribute=(string)id.Key;
-// Console.WriteLine("attribute:" +
attribute + "Vals:" + Properties[attribute][0]);
if(Properties[attribute].Count==1)
{
String val =
(String)Properties[attribute].Value;
@@ -905,10 +924,29 @@
}
}
LdapEntry newEntry = new LdapEntry( Fdn,
attributeSet );
- conn.Add( newEntry );
+ conn.Add( newEntry );
+ Nflag = false;
}
}
+ internal void CommitDeferred()
+ {
+ if (!_inPropertiesLoading && !UsePropertyCache &&
!Nflag)
+ {
+ CommitEntry();
+ }
+ }
+
+ void RefreshEntry()
+ {
+ _Properties = null;
+ _Fdn = null;
+ _Name = null;
+ _Parent = null;
+ _SchemaClassName = null;
+ InitEntry();
+ }
+
[MonoTODO]
public void RefreshCache ()
{
@@ -923,9 +961,8 @@
protected override void Dispose (bool disposing)
{
- if (!_disposed && disposing) {
+ if (disposing) {
Close ();
- _disposed = true;
}
base.Dispose (disposing);
}
Modified:
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/PropertyCollection.cs
===================================================================
---
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/PropertyCollection.cs
2005-03-31 06:16:18 UTC (rev 42414)
+++
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/PropertyCollection.cs
2005-03-31 06:19:04 UTC (rev 42415)
@@ -40,11 +40,17 @@
{
private ArrayList m_oKeys = new ArrayList();
private Hashtable m_oValues = new Hashtable();
+ private DirectoryEntry _parent;
- internal PropertyCollection()
+ internal PropertyCollection(): this(null)
{
}
+ internal PropertyCollection(DirectoryEntry parent)
+ {
+ _parent=parent;
+ }
+
public int Count
{
get{return m_oValues.Count;}
@@ -167,7 +173,7 @@
}
else
{
- PropertyValueCollection _pValColl=new
PropertyValueCollection();
+ PropertyValueCollection _pValColl=new
PropertyValueCollection(_parent);
// String tstr=new
String(propertyName.ToCharArray());
// Add((string)tstr.ToLower(),
(PropertyValueCollection)_pValColl);
Add((string)propertyName.ToLower(),
(PropertyValueCollection)_pValColl);
Modified:
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/PropertyValueCollection.cs
===================================================================
---
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/PropertyValueCollection.cs
2005-03-31 06:16:18 UTC (rev 42414)
+++
trunk/mcs/class/System.DirectoryServices/System.DirectoryServices/PropertyValueCollection.cs
2005-03-31 06:19:04 UTC (rev 42415)
@@ -38,10 +38,12 @@
{
private bool _Mbit;
+ private DirectoryEntry _parent;
- internal PropertyValueCollection():base()
+ internal PropertyValueCollection(DirectoryEntry parent):base()
{
_Mbit = false;
+ _parent = parent;
}
internal bool Mbit
@@ -133,24 +135,32 @@
copy_to[index++] = o;
}
- [MonoTODO]
protected override void OnClearComplete ()
{
+ if (_parent != null) {
+ _parent.CommitDeferred();
+ }
}
- [MonoTODO]
protected override void OnInsertComplete (int index, object
value)
{
+ if (_parent != null) {
+ _parent.CommitDeferred();
+ }
}
- [MonoTODO]
protected override void OnRemoveComplete (int index, object
value)
{
+ if (_parent != null) {
+ _parent.CommitDeferred();
+ }
}
- [MonoTODO]
protected override void OnSetComplete (int index, object
oldValue, object newValue)
{
+ if (_parent != null) {
+ _parent.CommitDeferred();
+ }
}
public object Value
@@ -166,7 +176,7 @@
// System.Object[] oArray= new
System.Object[this.Count];
// object[] oArray= new object[this.Count];
//
Array.Copy((System.Array)List,0,(System.Array)oArray,0,this.Count);
- Array LArray =
Array.CreateInstance( Type.GetType("System.Object"), this.Count );
+ Array LArray = new
object[Count];
for ( int i =
LArray.GetLowerBound(0); i <= LArray.GetUpperBound(0); i++ )
LArray.SetValue(
List[i], i );
return LArray;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches