public void AddTorrent(string pathToTorrentFile) { Messenger.Default.Send(new AddTorrentShowDialog((dialogResult) => { if (dialogResult == true) { ViewModelLocator locator = new ViewModelLocator(); var addTorrentViewModel = locator.AddTorrent; TorrentManager manager = new TorrentManager(addTorrentViewModel.Torrent, addTorrentViewModel.PathToFolder, tSettings); if (!engine.Contains(manager.InfoHash)) { saveLoadManager.Add(manager); engine.Register(manager); manager.Start(); TorrentManagerWrapper wrapper = new TorrentManagerWrapper(manager); Torrents.Add(wrapper); } } }, pathToTorrentFile)); }
public void OnTorrentAdded(object sender, TorrentActionEventArgs args) { Torrent torrent = bitTorrentManager.GetTorrent(args.Handle); // Marshall the collection call back to the window thread, torrent will be captured Action dispatchAction = () => Torrents.Add(torrent); this.currentDispatcher.BeginInvoke(dispatchAction); }
public PeriodicTorrent AddTorrent(TorrentWrapper torrent, bool startImmediately) { // Apply settings torrent.Settings.UseDht = SettingsManager.EnableDHT; torrent.Settings.MaxConnections = SettingsManager.MaxConnectionsPerTorrent; torrent.Settings.MaxDownloadSpeed = SettingsManager.MaxDownloadSpeed; torrent.Settings.MaxUploadSpeed = SettingsManager.MaxUploadSpeed; torrent.Settings.UploadSlots = SettingsManager.UploadSlotsPerTorrent; var periodicTorrent = new PeriodicTorrent(torrent); Task.Factory.StartNew(() => { Client.Register(torrent); if (startImmediately) { torrent.Start(); } }); Application.Current.Dispatcher.BeginInvoke(new Action(() => Torrents.Add(periodicTorrent))); return(periodicTorrent); }
void uTorrent_ListRefreshedEvent(ListRefreshedEventArgs ev) { if (ev.Torrents.Count != Torrents.Count) { System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate() { Torrents.Clear(); ViewTorrents.Refresh(); }); } long dSpeed = 0, uSpeed = 0; // new or updated torrents foreach (Torrent tor in ev.Torrents) { dSpeed += tor.DownloadSpeed; uSpeed += tor.UploadSpeed; //logger.Trace(tor.ToString()); bool foundTorrent = false; foreach (Torrent torExisting in Torrents) { if (tor.Hash == torExisting.Hash) { foundTorrent = true; // update details torExisting.Availability = tor.Availability; torExisting.Downloaded = tor.Downloaded; torExisting.DownloadSpeed = tor.DownloadSpeed; torExisting.ETA = tor.ETA; torExisting.Label = tor.Label; torExisting.Name = tor.Name; torExisting.PeersConnected = tor.PeersConnected; torExisting.PeersInSwarm = tor.PeersInSwarm; torExisting.PercentProgress = tor.PercentProgress; torExisting.Ratio = tor.Ratio; torExisting.Remaining = tor.Remaining; torExisting.SeedsConnected = tor.SeedsConnected; torExisting.SeedsInSwarm = tor.SeedsInSwarm; torExisting.Size = tor.Size; torExisting.Status = tor.Status; torExisting.TorrentQueueOrder = tor.TorrentQueueOrder; torExisting.Uploaded = tor.Uploaded; torExisting.UploadSpeed = tor.UploadSpeed; break; } } if (!foundTorrent) { System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate() { Torrents.Add(tor); }); } } DownloadSpeedSummaryFormatted = Utils.FormatByteSize((long)dSpeed) + "/sec"; UploadSpeedSummaryFormatted = Utils.FormatByteSize((long)uSpeed) + "/sec"; System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate() { ViewTorrents.Refresh(); }); }