Example #1
0
 internal void Update(bool blockingUpdates)
 {
     if (Thread.CurrentThread == Dispatcher.CurrentDispatcher.Thread)
     {
         blockingUpdates = false;
         Task.Factory.StartNew(() => BlockingUpdate(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
     }
     if (Torrent.State == TorrentState.Seeding && (State == TorrentState.Stopped || State == TorrentState.Hashing))
         CompletedOnAdd = true;
     State = Torrent.State;
     if (Torrent.Progress == 100 && CompletionTime == DateTime.MinValue)
         CompletionTime = DateTime.Now;
     Progress = Torrent.Progress;
     Complete = Torrent.Complete;
     DownloadSpeed = Torrent.Monitor.DownloadSpeed;
     UploadSpeed = Torrent.Monitor.UploadSpeed;
     if (Torrent.StartTime != DateTime.MinValue)
         ElapsedTime = DateTime.Now - Torrent.StartTime;
     if (Torrent.Complete)
         EstimatedTime = CompletionTime - DateTime.Now;
     else
     {
         if (Torrent.State == TorrentState.Metadata || DownloadSpeed == 0)
             EstimatedTime = TimeSpan.MaxValue;
         else
             EstimatedTime = TimeSpan.FromSeconds((Size - (Size * (Progress / 100))) / DownloadSpeed);
     }
     TotalDownloaded = Torrent.Monitor.DataBytesDownloaded;
     TotalUploaded = Torrent.Monitor.DataBytesUploaded;
     Ratio = (double)TotalDownloaded / TotalUploaded;
     if ((Torrent.State == TorrentState.Downloading || Torrent.State == TorrentState.Seeding) && files == null)
     {
         files = new PeriodicFile[Torrent.Torrent.Files.Length];
         for (int i = 0; i < files.Length; i++)
         {
             if (TorrentInfo.FilePriority != null && i < TorrentInfo.FilePriority.Length)
                 Torrent.Torrent.Files[i].Priority = TorrentInfo.FilePriority[i];
             files[i] = new PeriodicFile(Torrent.Torrent.Files[i]);
         }
         if (PropertyChanged != null)
             PropertyChanged(this, new PropertyChangedEventArgs("Files"));
     }
     if (Torrent.IsMagnet && (Torrent.State == TorrentState.Downloading || Torrent.State == TorrentState.Seeding) && Torrent.Size == -1)
         Size = Torrent.Torrent.Files.Select(f => f.Length).Aggregate((a, b) => a + b);
     if (files != null)
     {
         foreach (var file in files)
         {
             if (file != null)
                 file.Update();
         }
     }
     if (blockingUpdates)
         BlockingUpdate();
     else
     {
         Peers = Seeders = Leechers = 0;
     }
 }
Example #2
0
 internal void Update()
 {
     State = Torrent.State;
     Progress = Torrent.Progress;
     Complete = Torrent.Complete;
     DownloadSpeed = Torrent.Monitor.DownloadSpeed;
     UploadSpeed = Torrent.Monitor.UploadSpeed;
     ElapsedTime = DateTime.Now - Torrent.StartTime;
     if (Torrent.State == TorrentState.Metadata)
         EstimatedTime = TimeSpan.MaxValue;
     else
         EstimatedTime = new TimeSpan((long)((DateTime.Now - Torrent.StartTime).Ticks / (Torrent.Progress / 100)));
     TotalDownloaded = Torrent.Monitor.DataBytesDownloaded;
     TotalUploaded = Torrent.Monitor.DataBytesUploaded;
     Ratio = (double)Torrent.Monitor.DataBytesUploaded / Torrent.Monitor.DataBytesDownloaded;
     if ((Torrent.State == TorrentState.Downloading || Torrent.State == TorrentState.Seeding) && files == null)
     {
         files = new PeriodicFile[Torrent.Torrent.Files.Length];
         for (int i = 0; i < files.Length; i++)
             files[i] = new PeriodicFile(Torrent.Torrent.Files[i]);
         if (PropertyChanged != null)
             PropertyChanged(this, new PropertyChangedEventArgs("Files"));
     }
     if (Torrent.IsMagnet && (Torrent.State == TorrentState.Downloading || Torrent.State == TorrentState.Seeding) && Torrent.Size == -1)
         Size = Torrent.Torrent.Files.Select(f => f.Length).Aggregate((a, b) => a + b);
     if (files != null)
     {
         foreach (var file in files)
             file.Update();
     }
     Peers = Torrent.Peers.Available;
     Seeders = Torrent.Peers.Seeds;
     Leechers = Torrent.Peers.Leechs;
     var peerList = Torrent.GetPeers();
     foreach (var peer in peerList)
     {
         if (!PeerList.Contains(peer))
             PeerList.Add(peer);
     }
     for (int i = 0; i < PeerList.Count; i++)
     {
         if (!peerList.Contains(PeerList[i]))
             PeerList.RemoveAt(i--);
     }
 }
 internal void Update()
 {
     if (Torrent.State == TorrentState.Seeding && (State == TorrentState.Stopped || State == TorrentState.Hashing))
         CompletedOnAdd = true;
     State = Torrent.State;
     if (Torrent.Progress == 100 && CompletionTime == DateTime.MinValue)
         CompletionTime = DateTime.Now;
     Progress = Torrent.Progress;
     Complete = Torrent.Complete;
     DownloadSpeed = Torrent.Monitor.DownloadSpeed;
     UploadSpeed = Torrent.Monitor.UploadSpeed;
     if (Torrent.StartTime != DateTime.MinValue)
         ElapsedTime = DateTime.Now - Torrent.StartTime;
     if (Torrent.Complete)
         EstimatedTime = CompletionTime - DateTime.Now;
     else
     {
         if (Torrent.State == TorrentState.Metadata || DownloadSpeed == 0)
             EstimatedTime = TimeSpan.MaxValue;
         else
             EstimatedTime = TimeSpan.FromSeconds((Size - (Size * (Progress / 100))) / DownloadSpeed);
     }
     TotalDownloaded = Torrent.Monitor.DataBytesDownloaded;
     TotalUploaded = Torrent.Monitor.DataBytesUploaded;
     Ratio = (double)TotalDownloaded / TotalUploaded;
     if ((Torrent.State == TorrentState.Downloading || Torrent.State == TorrentState.Seeding) && files == null)
     {
         files = new PeriodicFile[Torrent.Torrent.Files.Length];
         for (int i = 0; i < files.Length; i++)
         {
             if (TorrentInfo.FilePriority != null && i < TorrentInfo.FilePriority.Length)
                 Torrent.Torrent.Files[i].Priority = TorrentInfo.FilePriority[i];
             files[i] = new PeriodicFile(Torrent.Torrent.Files[i]);
         }
         if (PropertyChanged != null)
             PropertyChanged(this, new PropertyChangedEventArgs("Files"));
     }
     if (Torrent.IsMagnet && (Torrent.State == TorrentState.Downloading || Torrent.State == TorrentState.Seeding) && Torrent.Size == -1)
         Size = Torrent.Torrent.Files.Select(f => f.Length).Aggregate((a, b) => a + b);
     if (files != null)
     {
         foreach (var file in files)
             file.Update();
     }
     Peers = Torrent.Peers.Available;
     Seeders = Torrent.Peers.Seeds;
     Leechers = Torrent.Peers.Leechs;
     var peerList = Torrent.GetPeers();
     foreach (var peer in peerList)
     {
         if (!PeerList.Contains(peer))
             PeerList.Add(peer);
     }
     for (int i = 0; i < PeerList.Count; i++)
     {
         if (!peerList.Contains(PeerList[i]))
             PeerList.RemoveAt(i--);
     }
 }
Example #4
0
 internal void Update(bool blockingUpdates)
 {
     if (Thread.CurrentThread == Dispatcher.CurrentDispatcher.Thread)
     {
         blockingUpdates = false;
         Task.Factory.StartNew(() => BlockingUpdate(), CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
     }
     if (Torrent.State == TorrentState.Seeding && (State == TorrentState.Stopped || State == TorrentState.Hashing))
     {
         CompletedOnAdd = true;
     }
     State = Torrent.State;
     if (Torrent.Progress == 100 && CompletionTime == DateTime.MinValue)
     {
         CompletionTime = DateTime.Now;
     }
     Progress      = Torrent.Progress;
     Complete      = Torrent.Complete;
     DownloadSpeed = Torrent.Monitor.DownloadSpeed;
     UploadSpeed   = Torrent.Monitor.UploadSpeed;
     if (Torrent.StartTime != DateTime.MinValue)
     {
         ElapsedTime = DateTime.Now - Torrent.StartTime;
     }
     if (Torrent.Complete)
     {
         EstimatedTime = CompletionTime - DateTime.Now;
     }
     else
     {
         if (Torrent.State == TorrentState.Metadata || DownloadSpeed == 0)
         {
             EstimatedTime = TimeSpan.MaxValue;
         }
         else
         {
             EstimatedTime = TimeSpan.FromSeconds((Size - (Size * (Progress / 100))) / DownloadSpeed);
         }
     }
     TotalDownloaded = Torrent.Monitor.DataBytesDownloaded;
     TotalUploaded   = Torrent.Monitor.DataBytesUploaded;
     Ratio           = (double)TotalDownloaded / TotalUploaded;
     if ((Torrent.State == TorrentState.Downloading || Torrent.State == TorrentState.Seeding) && files == null)
     {
         files = new PeriodicFile[Torrent.Torrent.Files.Length];
         for (int i = 0; i < files.Length; i++)
         {
             if (TorrentInfo.FilePriority != null && i < TorrentInfo.FilePriority.Length)
             {
                 Torrent.Torrent.Files[i].Priority = TorrentInfo.FilePriority[i];
             }
             files[i] = new PeriodicFile(Torrent.Torrent.Files[i]);
         }
         if (PropertyChanged != null)
         {
             PropertyChanged(this, new PropertyChangedEventArgs("Files"));
         }
     }
     if (Torrent.IsMagnet && (Torrent.State == TorrentState.Downloading || Torrent.State == TorrentState.Seeding) && Torrent.Size == -1)
     {
         Size = Torrent.Torrent.Files.Select(f => f.Length).Aggregate((a, b) => a + b);
     }
     if (files != null)
     {
         foreach (var file in files)
         {
             if (file != null)
             {
                 file.Update();
             }
         }
     }
     if (blockingUpdates)
     {
         BlockingUpdate();
     }
     else
     {
         Peers = Seeders = Leechers = 0;
     }
 }