Author: alanmc
Date: 2007-05-02 14:17:46 -0400 (Wed, 02 May 2007)
New Revision: 76582

Modified:
   trunk/bitsharp/src/MonoTorrent/BEncoding/BEncodedString.cs
   trunk/bitsharp/src/MonoTorrent/Client/TrackerTier.cs
   trunk/bitsharp/src/MonoTorrent/Collections/BlockCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/IBEncodedValueCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/ITorrentWatcherCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/IntCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/PeerCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/PeerConnectionIDCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/PieceCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/StringCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/TorrentManagerCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/TraceListenerCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/TrackerCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/UInt32Collection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/UntypedCollection.cs
   trunk/bitsharp/src/MonoTorrent/Collections/WaitHandleCollection.cs
   trunk/bitsharp/src/MonoTorrent/Common/ToolBox.cs
   trunk/bitsharp/src/MonoTorrent/Common/Torrent.cs
Log:
Some fixes for the last commit.

Modified: trunk/bitsharp/src/MonoTorrent/BEncoding/BEncodedString.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/BEncoding/BEncodedString.cs  2007-05-02 
17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/BEncoding/BEncodedString.cs  2007-05-02 
18:17:46 UTC (rev 76582)
@@ -206,6 +206,7 @@
             return this.textBytes.Length > other.textBytes.Length ? 1 : -1;
         }
 
+#warning Throw an invalid cast exception?
         public int CompareTo(object obj)
         {
             BEncodedString other = obj as BEncodedString;

Modified: trunk/bitsharp/src/MonoTorrent/Client/TrackerTier.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Client/TrackerTier.cs        2007-05-02 
17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Client/TrackerTier.cs        2007-05-02 
18:17:46 UTC (rev 76582)
@@ -43,8 +43,8 @@
                         AsyncCallback scrapeCallback, EngineSettings 
engineSettings)
         {
             this.trackers = new TrackerCollection(trackerUrls.Count);
-            for (int i = 0; i < trackerUrls.Count; i++)
-                this.trackers[i] = new Tracker(trackerUrls[i], 
announceCallback, scrapeCallback, engineSettings);
+            foreach (string trackerUrl in trackerUrls)
+                this.trackers.Add(new Tracker(trackerUrl, announceCallback, 
scrapeCallback, engineSettings));
         }
 
         #endregion Constructors

Modified: trunk/bitsharp/src/MonoTorrent/Collections/BlockCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/BlockCollection.cs       
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/BlockCollection.cs       
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,15 +1,14 @@
 using System;
 using System.Text;
 using System.Collections;
+using MonoTorrent.Client;
 #if NET_2_0
 using System.Collections.Generic;
 #endif
 
-using MonoTorrent.Client;
-
 namespace MonoTorrent
 {
-       public class BlockCollection : IList
+       public class BlockCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -57,7 +56,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -68,6 +67,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       BlockCollection clone = new BlockCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(Block value)
                {
                        return list.Contains(value);
@@ -110,7 +117,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot

Modified: trunk/bitsharp/src/MonoTorrent/Collections/IBEncodedValueCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/IBEncodedValueCollection.cs      
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/IBEncodedValueCollection.cs      
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,16 +1,14 @@
 using System;
 using System.Text;
 using System.Collections;
-
 using MonoTorrent.BEncoding;
-
 #if NET_2_0
 using System.Collections.Generic;
 #endif
 
 namespace MonoTorrent
 {
-       public class IBEncodedValueCollection : IList
+       public class IBEncodedValueCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -58,7 +56,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -69,6 +67,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       IBEncodedValueCollection clone = new 
IBEncodedValueCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(IBEncodedValue value)
                {
                        return list.Contains(value);
@@ -111,7 +117,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -167,5 +173,5 @@
                }
 
                #endregion
-    }
+       }
 }
\ No newline at end of file

Modified: 
trunk/bitsharp/src/MonoTorrent/Collections/ITorrentWatcherCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/ITorrentWatcherCollection.cs     
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/ITorrentWatcherCollection.cs     
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,15 +1,16 @@
+
+
 using System;
 using System.Text;
 using System.Collections;
+using MonoTorrent.Common;
 #if NET_2_0
 using System.Collections.Generic;
 #endif
 
-using MonoTorrent.Common;
-
 namespace MonoTorrent
 {
-       public class ITorrentWatcherCollection : IList
+       public class ITorrentWatcherCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -57,7 +58,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -68,6 +69,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       ITorrentWatcherCollection clone = new 
ITorrentWatcherCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(ITorrentWatcher value)
                {
                        return list.Contains(value);
@@ -110,7 +119,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -167,4 +176,4 @@
 
                #endregion
        }
-}
\ No newline at end of file
+}

Modified: trunk/bitsharp/src/MonoTorrent/Collections/IntCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/IntCollection.cs 2007-05-02 
17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/IntCollection.cs 2007-05-02 
18:17:46 UTC (rev 76582)
@@ -1,4 +1,3 @@
-
 using System;
 using System.Text;
 using System.Collections;
@@ -8,7 +7,7 @@
 
 namespace MonoTorrent
 {
-       public class IntCollection : IList
+       public class IntCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -56,7 +55,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -67,6 +66,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       IntCollection clone = new IntCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(int value)
                {
                        return list.Contains(value);
@@ -109,7 +116,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot

Modified: trunk/bitsharp/src/MonoTorrent/Collections/PeerCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/PeerCollection.cs        
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/PeerCollection.cs        
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,15 +1,16 @@
+
+
 using System;
 using System.Text;
 using System.Collections;
+using MonoTorrent.Client;
 #if NET_2_0
 using System.Collections.Generic;
 #endif
 
-using MonoTorrent.Client;
-
 namespace MonoTorrent
 {
-       public class PeerCollection : IList
+       public class PeerCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -57,7 +58,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -68,6 +69,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       PeerCollection clone = new PeerCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(Peer value)
                {
                        return list.Contains(value);
@@ -110,7 +119,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -167,4 +176,4 @@
 
                #endregion
        }
-}
\ No newline at end of file
+}

Modified: 
trunk/bitsharp/src/MonoTorrent/Collections/PeerConnectionIDCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/PeerConnectionIDCollection.cs    
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/PeerConnectionIDCollection.cs    
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,15 +1,16 @@
+
+
 using System;
 using System.Text;
 using System.Collections;
+using MonoTorrent.Client;
 #if NET_2_0
 using System.Collections.Generic;
 #endif
 
-using MonoTorrent.Client;
-
 namespace MonoTorrent
 {
-       public class PeerIdCollection : IList
+       public class PeerIdCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -57,7 +58,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -68,6 +69,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       PeerIdCollection clone = new 
PeerIdCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(PeerId value)
                {
                        return list.Contains(value);
@@ -110,7 +119,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -167,4 +176,4 @@
 
                #endregion
        }
-}
\ No newline at end of file
+}

Modified: trunk/bitsharp/src/MonoTorrent/Collections/PieceCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/PieceCollection.cs       
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/PieceCollection.cs       
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,15 +1,16 @@
+
+
 using System;
 using System.Text;
 using System.Collections;
+using MonoTorrent.Client;
 #if NET_2_0
 using System.Collections.Generic;
 #endif
 
-using MonoTorrent.Client;
-
 namespace MonoTorrent
 {
-       public class PieceCollection : IList
+       public class PieceCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -57,7 +58,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -68,6 +69,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       PieceCollection clone = new PieceCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(Piece value)
                {
                        return list.Contains(value);
@@ -110,7 +119,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -167,4 +176,4 @@
 
                #endregion
        }
-}
\ No newline at end of file
+}

Modified: trunk/bitsharp/src/MonoTorrent/Collections/StringCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/StringCollection.cs      
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/StringCollection.cs      
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,3 +1,5 @@
+
+
 using System;
 using System.Text;
 using System.Collections;
@@ -7,7 +9,7 @@
 
 namespace MonoTorrent
 {
-       public class stringCollection : IList
+       public class stringCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -55,7 +57,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -66,6 +68,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       stringCollection clone = new 
stringCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(string value)
                {
                        return list.Contains(value);
@@ -108,7 +118,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -165,4 +175,4 @@
 
                #endregion
        }
-}
\ No newline at end of file
+}

Modified: trunk/bitsharp/src/MonoTorrent/Collections/TorrentManagerCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/TorrentManagerCollection.cs      
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/TorrentManagerCollection.cs      
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,15 +1,16 @@
+
+
 using System;
 using System.Text;
 using System.Collections;
+using MonoTorrent.Client;
 #if NET_2_0
 using System.Collections.Generic;
 #endif
 
-using MonoTorrent.Client;
-
 namespace MonoTorrent
 {
-       public class TorrentManagerCollection : IList
+       public class TorrentManagerCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -57,7 +58,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -68,6 +69,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       TorrentManagerCollection clone = new 
TorrentManagerCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(TorrentManager value)
                {
                        return list.Contains(value);
@@ -110,7 +119,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -167,4 +176,4 @@
 
                #endregion
        }
-}
\ No newline at end of file
+}

Modified: trunk/bitsharp/src/MonoTorrent/Collections/TraceListenerCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/TraceListenerCollection.cs       
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/TraceListenerCollection.cs       
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,3 +1,5 @@
+
+
 using System;
 using System.Text;
 using System.Collections;
@@ -8,7 +10,7 @@
 
 namespace MonoTorrent
 {
-       public class TraceListenerCollection : IList
+       public class TraceListenerCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -56,7 +58,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -67,6 +69,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       TraceListenerCollection clone = new 
TraceListenerCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(TraceListener value)
                {
                        return list.Contains(value);
@@ -109,7 +119,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -166,4 +176,4 @@
 
                #endregion
        }
-}
\ No newline at end of file
+}

Modified: trunk/bitsharp/src/MonoTorrent/Collections/TrackerCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/TrackerCollection.cs     
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/TrackerCollection.cs     
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,3 +1,5 @@
+
+
 using System;
 using System.Text;
 using System.Collections;
@@ -7,7 +9,7 @@
 
 namespace MonoTorrent
 {
-       public class TrackerCollection : IList
+       public class TrackerCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -55,7 +57,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -66,6 +68,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       TrackerCollection clone = new 
TrackerCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(MonoTorrent.Client.Tracker value)
                {
                        return list.Contains(value);
@@ -108,7 +118,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -164,15 +174,5 @@
                }
 
                #endregion
-
-               internal TrackerCollection Clone()
-               {
-                       TrackerCollection clone = new 
TrackerCollection(list.Count);
-                       for (int i = 0; i < list.Count; i++)
-                               clone.Add(this[i]);
-
-                       return clone;
-               }
        }
 }
-

Modified: trunk/bitsharp/src/MonoTorrent/Collections/UInt32Collection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/UInt32Collection.cs      
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/UInt32Collection.cs      
2007-05-02 18:17:46 UTC (rev 76582)
@@ -1,3 +1,5 @@
+
+
 using System;
 using System.Text;
 using System.Collections;
@@ -7,7 +9,7 @@
 
 namespace MonoTorrent
 {
-       public class UInt32Collection : IList
+       public class UInt32Collection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -55,7 +57,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -66,6 +68,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       UInt32Collection clone = new 
UInt32Collection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(UInt32 value)
                {
                        return list.Contains(value);
@@ -108,7 +118,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -165,4 +175,4 @@
 
                #endregion
        }
-}
\ No newline at end of file
+}

Modified: trunk/bitsharp/src/MonoTorrent/Collections/UntypedCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/UntypedCollection.cs     
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/UntypedCollection.cs     
2007-05-02 18:17:46 UTC (rev 76582)
@@ -9,7 +9,7 @@
 
 namespace MonoTorrent
 {
-       public class @[EMAIL PROTECTED] : IList
+       public class @[EMAIL PROTECTED] : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -57,7 +57,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -68,6 +68,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       @[EMAIL PROTECTED] clone = new @[EMAIL 
PROTECTED](list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(@TYPE@ value)
                {
                        return list.Contains(value);
@@ -110,7 +118,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -168,5 +176,4 @@
                #endregion
        }
 }
-
-*/
+*/
\ No newline at end of file

Modified: trunk/bitsharp/src/MonoTorrent/Collections/WaitHandleCollection.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Collections/WaitHandleCollection.cs  
2007-05-02 17:53:45 UTC (rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Collections/WaitHandleCollection.cs  
2007-05-02 18:17:46 UTC (rev 76582)
@@ -8,7 +8,7 @@
 
 namespace MonoTorrent
 {
-       public class WaitHandleCollection : IList
+       public class WaitHandleCollection : MonoTorrentCollectionBase
        {
                #region Private Fields
 
@@ -46,11 +46,6 @@
 
                #region Methods
 
-        public WaitHandle[] ToArray()
-        {
-            return this.ToArray();
-        }
-
                public WaitHandle this[int index]
                {
                        get { return (WaitHandle)list[index]; }
@@ -61,7 +56,7 @@
                {
 #if NET_2_0
                        list.Add(value);
-                       return 0;
+                       return list.Count;
 #else
                        return this.list.Add(value);
 #endif
@@ -72,6 +67,14 @@
                        this.list.Clear();
                }
 
+               public MonoTorrentCollectionBase Clone()
+               {
+                       WaitHandleCollection clone = new 
WaitHandleCollection(list.Count);
+                       for (int i = 0; i < list.Count; i++)
+                               clone.Add(this[i]);
+                       return clone;
+               }
+
                public bool Contains(WaitHandle value)
                {
                        return list.Contains(value);
@@ -114,7 +117,7 @@
 
                public void RemoveAt(int index)
                {
-                       RemoveAt(index);
+                       list.RemoveAt(index);
                }
 
                public object SyncRoot
@@ -170,5 +173,10 @@
                }
 
                #endregion
+
+               internal WaitHandle[] ToArray()
+               {
+                       return (WaitHandle[])list.ToArray();
+               }
        }
 }
\ No newline at end of file

Modified: trunk/bitsharp/src/MonoTorrent/Common/ToolBox.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Common/ToolBox.cs    2007-05-02 17:53:45 UTC 
(rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Common/ToolBox.cs    2007-05-02 18:17:46 UTC 
(rev 76582)
@@ -29,8 +29,10 @@
 
 
 using System;
+using System.Collections;
 using System.Collections.Generic;
 using System.Text;
+using System.Reflection;
 
 namespace MonoTorrent.Common
 {
@@ -38,38 +40,24 @@
     {
                private static Random r = new Random();
 
-#warning This is broken. it won't work. The strings collection is being 
cleared, it needs to be cloned first
-        public static void RandomizeStringCollection(stringCollection strings)
-        {
-            stringCollection clone = new stringCollection(strings.Count);
-            strings.Clear();
-
-            while (clone.Count > 0)
-            {
-                int index = r.Next(0, clone.Count);
-                strings.Add(clone[index]);
-                clone.RemoveAt(index);
-            }
-        }
-
-               public static void Randomize(TrackerCollection array)
+               public static void Randomize(MonoTorrentCollectionBase 
collection)
                {
-                       TrackerCollection clone = array.Clone();
-                       array.Clear();
+                       MonoTorrentCollectionBase clone = collection.Clone();
+                       collection.Clear();
 
                        while (clone.Count > 0)
                        {
                                int index = r.Next(0, clone.Count);
-                               array.Add(clone[index]);
+                               collection.Add(clone[index]);
                                clone.RemoveAt(index);
                        }
                }
 
-               public static void Switch(TrackerCollection array, int first, 
int second)
+               public static void Switch(MonoTorrentCollectionBase collection, 
int first, int second)
                {
-                       MonoTorrent.Client.Tracker obj = array[first];
-                       array[first] = array[second];
-                       array[second] = obj;
+                       object obj = collection[first];
+                       collection[first] = collection[second];
+                       collection[second] = obj;
                }
 
         public static string GetHex(byte[] infoHash)

Modified: trunk/bitsharp/src/MonoTorrent/Common/Torrent.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent/Common/Torrent.cs    2007-05-02 17:53:45 UTC 
(rev 76581)
+++ trunk/bitsharp/src/MonoTorrent/Common/Torrent.cs    2007-05-02 18:17:46 UTC 
(rev 76582)
@@ -598,7 +598,7 @@
                                                        for (int k = 0; k < 
bencodedTier.Count; k++)
                                                                
tier.Add(bencodedTier[k].ToString());
 
-                                                       
ToolBox.RandomizeStringCollection(tier);
+                                                       ToolBox.Randomize(tier);
                                                        
this.announceUrls.Add(tier);
                                                }
                         break;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to