Author: alanmc
Date: 2006-11-05 08:07:49 -0500 (Sun, 05 Nov 2006)
New Revision: 67373

Modified:
   trunk/bitsharp/src/MonoTorrent.Client/Managers/ConnectionManager.cs
   trunk/bitsharp/src/MonoTorrent.Client/Managers/TorrentManager.cs
   
trunk/bitsharp/src/MonoTorrent.Interface/src/MonoTorrent.Interface/Model/TorrentsList.cs
   trunk/bitsharp/src/TestClient/main.cs
Log:
Changed TorrentManager.Progress from a method to a Property as it can now be 
called frequently with no performance penalty.

Modified: trunk/bitsharp/src/MonoTorrent.Client/Managers/ConnectionManager.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/Managers/ConnectionManager.cs 
2006-11-05 13:03:51 UTC (rev 67372)
+++ trunk/bitsharp/src/MonoTorrent.Client/Managers/ConnectionManager.cs 
2006-11-05 13:07:49 UTC (rev 67373)
@@ -389,7 +389,7 @@
                             if 
(id.TorrentManager.PieceManager.MyBitField.AllFalse())
                                 msg = new HaveNoneMessage();
 
-                            else if (id.TorrentManager.Progress() == 100.0)
+                            else if (id.TorrentManager.Progress == 100.0)
                                 msg = new HaveAllMessage();
 
                             else

Modified: trunk/bitsharp/src/MonoTorrent.Client/Managers/TorrentManager.cs
===================================================================
--- trunk/bitsharp/src/MonoTorrent.Client/Managers/TorrentManager.cs    
2006-11-05 13:03:51 UTC (rev 67372)
+++ trunk/bitsharp/src/MonoTorrent.Client/Managers/TorrentManager.cs    
2006-11-05 13:07:49 UTC (rev 67373)
@@ -317,12 +317,12 @@
             if (this.state == TorrentState.Seeding || this.state == 
TorrentState.SuperSeeding || this.state == TorrentState.Downloading)
                 throw new TorrentException("Torrent is already running");
 
-            if (this.Progress() == 100.0)
+            if (this.Progress == 100.0)
                 UpdateState(TorrentState.Seeding);
             else
                 UpdateState(TorrentState.Downloading);
 
-            this.trackerManager.Announce(0, 0, (long)((1.0 - this.Progress() / 
100.0) * this.torrent.Size), TorrentEvent.Started); // Tell server we're 
starting
+            this.trackerManager.Announce(0, 0, (long)((1.0 - this.Progress / 
100.0) * this.torrent.Size), TorrentEvent.Started); // Tell server we're 
starting
         }
 
 
@@ -336,7 +336,7 @@
             UpdateState(TorrentState.Stopped);
 
             this.fileManager.FlushAll();
-            handle = this.trackerManager.Announce(this.dataBytesDownloaded, 
this.dataBytesUploaded, (long)((1.0 - this.Progress() / 100.0) * 
this.torrent.Size), TorrentEvent.Stopped);
+            handle = this.trackerManager.Announce(this.dataBytesDownloaded, 
this.dataBytesUploaded, (long)((1.0 - this.Progress / 100.0) * 
this.torrent.Size), TorrentEvent.Stopped);
             lock (this.listLock)
             {
                 while (this.connectingTo.Count > 0)
@@ -473,20 +473,20 @@
 
                 if (counter % 100 == 0)
                 {
-                    if(this.Progress() == 100.0)
+                    if(this.Progress == 100.0)
                         UpdateState(TorrentState.Seeding);
                     // If the last connection succeeded, then update at the 
regular interval
                     if (this.trackerManager.UpdateSucceeded)
                     {
                         if (DateTime.Now > 
(this.trackerManager.LastUpdated.AddSeconds(this.trackerManager.CurrentTracker.UpdateInterval)))
                         {
-                            
this.trackerManager.Announce(this.dataBytesDownloaded, this.dataBytesUploaded, 
(long)((1.0 - this.Progress() / 100.0) * this.torrent.Size), TorrentEvent.None);
+                            
this.trackerManager.Announce(this.dataBytesDownloaded, this.dataBytesUploaded, 
(long)((1.0 - this.Progress / 100.0) * this.torrent.Size), TorrentEvent.None);
                         }
                     }
                     // Otherwise update at the min interval
                     else if (DateTime.Now > 
(this.trackerManager.LastUpdated.AddSeconds(this.trackerManager.CurrentTracker.MinUpdateInterval)))
                     {
-                        this.trackerManager.Announce(this.dataBytesDownloaded, 
this.dataBytesUploaded, (long)((1.0 - this.Progress() / 100.0) * 
this.torrent.Size), TorrentEvent.None);
+                        this.trackerManager.Announce(this.dataBytesDownloaded, 
this.dataBytesUploaded, (long)((1.0 - this.Progress / 100.0) * 
this.torrent.Size), TorrentEvent.None);
                     }
                 }
                 if (counter % 40 == 0)
@@ -794,9 +794,9 @@
         /// <summary>
         /// The current progress of the torrent in percent
         /// </summary>
-        public double Progress()
+        public double Progress
         {
-            return ((this.pieceManager.MyBitField.TrueCount * 100.0) / 
this.pieceManager.MyBitField.Length);
+            get { return ((this.pieceManager.MyBitField.TrueCount * 100.0) / 
this.pieceManager.MyBitField.Length); }
         }
 
 

Modified: 
trunk/bitsharp/src/MonoTorrent.Interface/src/MonoTorrent.Interface/Model/TorrentsList.cs
===================================================================
--- 
trunk/bitsharp/src/MonoTorrent.Interface/src/MonoTorrent.Interface/Model/TorrentsList.cs
    2006-11-05 13:03:51 UTC (rev 67372)
+++ 
trunk/bitsharp/src/MonoTorrent.Interface/src/MonoTorrent.Interface/Model/TorrentsList.cs
    2006-11-05 13:07:49 UTC (rev 67373)
@@ -138,7 +138,7 @@
 
         private void UpdateStats(TreeIter row, TorrentManager torrent)
         {
-            SetValue(row, 3, Formatter.FormatPercent(torrent.Progress()));
+            SetValue(row, 3, Formatter.FormatPercent(torrent.Progress));
             SetValue(row, 4, 
Formatter.FormatSize(torrent.DataBytesDownloaded));
             SetValue(row, 5, Formatter.FormatSize(torrent.DataBytesUploaded));
             SetValue(row, 6, Formatter.FormatSpeed(torrent.DownloadSpeed()));

Modified: trunk/bitsharp/src/TestClient/main.cs
===================================================================
--- trunk/bitsharp/src/TestClient/main.cs       2006-11-05 13:03:51 UTC (rev 
67372)
+++ trunk/bitsharp/src/TestClient/main.cs       2006-11-05 13:07:49 UTC (rev 
67373)
@@ -111,7 +111,7 @@
                         Console.WriteLine("Uploading to:     " + 
manager.UploadingTo.ToString());
                         Console.WriteLine("Half opens:       " + 
ClientEngine.ConnectionManager.HalfOpenConnections);
                         Console.WriteLine("Max open:         " + 
ClientEngine.ConnectionManager.MaxOpenConnections);
-                        Console.WriteLine("Progress:         " + 
string.Format(manager.Progress().ToString(), ("{0:0.00}")));
+                        Console.WriteLine("Progress:         " + 
string.Format(manager.Progress.ToString(), ("{0:0.00}")));
                         Console.WriteLine("Download Speed:   " + 
string.Format("{0:0.00}", manager.DownloadSpeed() / 1024));
                         Console.WriteLine("Upload Speed:     " + 
string.Format("{0:0.00}", manager.UploadSpeed() / 1024));
                         Console.WriteLine("Torrent State:    " + 
manager.State.ToString());

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

Reply via email to