public void TestGetURLOnParsedFile(string file, string expected) { MetaInfoFile torrentFile = new MetaInfoFile(file); torrentFile.Parse(); Assert.Equal(expected, torrentFile.GetTracker()); }
/// <summary> /// Initiate torrent download. /// </summary> /// <param name="mainWindow"></param> public void Download(TorrentClient main) { try { // Update status bar for starting download Application.MainLoop.Invoke(() => { main.MainStatusBar.Display(Status.StartingUp); }); // Load torrent file and parse MetaInfoFile torrentFile = new MetaInfoFile(_fileName); torrentFile.Parse(); Application.MainLoop.Invoke(() => { main.ClientWindow.UpdatProgressBar(0); main.ClientWindow.InfoWindow.SetTracker(torrentFile.GetTracker()); }); // Create torrent context and tracker _tc = new TorrentContext(torrentFile, _selector, _diskIO, main.Configuration.DestinationDirectory) { CallBack = UpdateDownloadProgress, CallBackData = main }; _tracker = new Tracker(_tc) { CallBack = UpdateDownloadInformation, CallBackData = main }; // Hookup tracker to agent, add torrent and startup everyhing up _agent.AddTorrent(_tc); _agent.AttachPeerSwarmQueue(_tracker); _tracker.StartAnnouncing(); _agent.StartTorrent(_tc); Application.MainLoop.Invoke(() => { main.MainStatusBar.Display(Status.Downloading); }); } catch (Exception ex) { Application.MainLoop.Invoke(() => { MessageBox.Query("Error", ex.Message, "Ok"); main.MainStatusBar.Display(Status.Shutdown); }); } }
public void TestGetTrackerWithNoParseOnMetaInfoFile() { MetaInfoFile torrentFile = new MetaInfoFile(Constants.SingleFileTorrent); BitTorrentException error = Assert.Throws <BitTorrentException>(() => { string tracker = torrentFile.GetTracker(); }); Assert.Equal("BitTorrent Error: File has not been parsed.", error.Message); }