public double GetOverallProgress() { long bytesToTransfer = 0; long totalSize = 0; lock (_transferLock) //Acquire the transfer lock { if (Transfers.Any()) { try { totalSize = Transfers.Sum(x => x.ActualDiskSize); } catch (OverflowException) { totalSize = long.MaxValue; } bytesToTransfer = totalSize - Transfers.Sum(x => x.BytesTransfered); _totalTransferSize = Math.Max(_totalTransferSize, totalSize); } else if (_totalTransferSize == 0) { return(0.0); } else { _totalTransferSize = 1; return(1.0); } } //Represent progress as remaining bytes to tranfer from the largest observed size of all transfers. This should better reflect % complete with a large queue, and prevent jumping as items are finished return(Convert.ToDouble(_totalTransferSize - bytesToTransfer) / Convert.ToDouble(_totalTransferSize)); }
private void WorkThreadWrapper() { while (_shutdownRequested == false) { if (_IsPaused == false) { bool workToDo = false; lock (_transferLock) //Acquire the transfer lock { workToDo = Transfers.Any(x => (x.Status != Interfaces.TransferStatus.Blocked) || (x.CanCopy)); } if (workToDo) { DoWork(); } else { Thread.Sleep(3000); } } else { Thread.Sleep(3000); } } }
private void Initialize() { if (!Transfers.Any()) { Transfers.Add(new Transfer { Carrying = 1000, Name = "Transfer 1", Status = 0 }); Transfers.Add(new Transfer { Carrying = 2000, Name = "Transfer 2", Status = 0 }); Transfers.Add(new Transfer { Carrying = 3000, Name = "Transfer 3", Status = 0 }); Transfers.Add(new Transfer { Carrying = 4000, Name = "Transfer 4", Status = 0 }); Transfers.Add(new Transfer { Carrying = 5000, Name = "Transfer 5", Status = 0 }); Transfers.Add(new Transfer { Carrying = 6000, Name = "Transfer 6", Status = 0 }); Transfers.Add(new Transfer { Carrying = 7000, Name = "Transfer 7", Status = 0 }); Transfers.Add(new Transfer { Carrying = 8000, Name = "Transfer 81", Status = 0 }); Transfers.Add(new Transfer { Carrying = 8000, Name = "Transfer 82", Status = 0 }); Transfers.Add(new Transfer { Carrying = 8000, Name = "Transfer 83", Status = 0 }); Transfers.Add(new Transfer { Carrying = 8000, Name = "Transfer 84", Status = 0 }); SaveChanges(); } }
private void AddTransfer(string path) { if (path != null && Path.GetExtension(path) != ".torrent") { IOService.ShowErrorMessage("Not a valid torrent file", "Only files with a .torrent extension are recognized as valid."); return; } try { string filePath = path == null?IOService.OpenFile("Torrent files|*.torrent") : path; string saveFolder = null; if (!string.IsNullOrEmpty(filePath)) { saveFolder = IOService.OpenFolder(Path.GetFileName(path)); } if (filePath != null && saveFolder != null) { var transfer = new Transfer(new TorrentTransfer(filePath, saveFolder)); if (!Transfers.Any(t => t.InfoHash == transfer.InfoHash)) { Transfers.Add(transfer); } else { IOService.ShowErrorMessage("Torrent transfer already exists", string.Format("{0} is already added and can not be added again.", path)); } } } catch (Exception e) { Trace.WriteLine("Exception when adding transfer " + e); IOService.ShowErrorMessage("Adding transfer failed", string.Format("Adding transfer failed due to: {0}", e.Message)); } }