コード例 #1
0
        public ICollection <TorrentContext> TorrentList => _agent.TorrentList; // List of all managed torrents
        /// <summary>
        /// Update download information. This is used as the tracker callback to be invoked
        /// when the next announce response is recieved back for the torrent being downloaded.
        /// </summary>
        /// <param name="obj"></param>
        private void UpdateDownloadInformation(Object obj)
        {
            TorrentClient  main           = (TorrentClient)obj;
            TorrentDetails torrentDetails = _agent.GetTorrentDetails(_tc);

            main.ClientWindow.InfoWindow.Update(torrentDetails);
        }
コード例 #2
0
        public void TestGetTorrentDetailsReturnsCorrectDetails()
        {
            MetaInfoFile file = new MetaInfoFile(Constants.SingleFileTorrent);

            file.Parse();
            Manager manager = new Manager();
            Mock <IAgentNetwork> networkMock = new Mock <IAgentNetwork>();
            Agent agent = new Agent(new Manager(), new Assembler(), networkMock.Object);

            agent.Startup();
            TorrentContext tc = new TorrentContext(file, new Selector(), new DiskIO(manager), Constants.DestinationDirectory);

            _ = new Tracker(tc);
            agent.AddTorrent(tc);
            TorrentDetails details = agent.GetTorrentDetails(tc);

            Assert.Equal(0, details.deadPeers);
            Assert.Equal(0, (int)details.downloadedBytes);
            Assert.Equal(Constants.SingleFileTorrent, details.fileName);
            Assert.Equal(file.GetInfoHash(), details.infoHash);
            Assert.Equal(22, details.missingPiecesCount);
            Assert.Equal(0, (int)details.peers.Count);
            Assert.Equal(TorrentStatus.Initialised, details.status);
            Assert.Equal(0, details.swarmSize);
            Assert.Equal(TrackerStatus.Stopped, details.trackerStatus);
            Assert.Null(details.trackerStatusMessage);
            Assert.Equal(0, (int)details.uploadedBytes);
        }
コード例 #3
0
        }                                         // List view to display seeding torrent information

        /// <summary>
        /// Build seeder display line for listview.
        /// </summary>
        /// <param name="seederDetails"></param>
        /// <returns></returns>
        private string BuildSeederDisplayLine(TorrentDetails seederDetails)
        {
            return(String.Format("File[{0,-12}] Tracker[{1,3}] Status[{2,1}] Uploaded[{3, 11}] Swarm[{4, 5}]",
                                 Path.GetFileNameWithoutExtension(seederDetails.fileName),
                                 seederDetails.trackerStatus.ToString().Substring(0, 3),
                                 seederDetails.status.ToString().Substring(0, 1),
                                 seederDetails.uploadedBytes, seederDetails.swarmSize));
        }
コード例 #4
0
        public async Task <TorrentDetails> GetTorrentDetails(string hash)
        {
            var torrentDetails = await _client.Get <qBittorrentDetails>("admin", "8tfunqBessie", null, "/query/propertiesGeneral/" + hash);

            TorrentDetails details = new TorrentDetails();

            details.Downloaded = torrentDetails.Total_downloaded;
            details.Uploaded   = torrentDetails.Total_uploaded;
            details.SavePath   = torrentDetails.Save_path;

            return(details);
        }
コード例 #5
0
 /// <summary>
 /// Update torrent information window.
 /// </summary>
 /// <param name="torrentDetails"></param>
 private void UpdateInformation(TorrentDetails torrentDetails)
 {
     _infoTextFields[0].Text = InfoHashToString(torrentDetails.infoHash);
     _infoTextFields[1].Text = torrentDetails.downloadedBytes.ToString();
     _infoTextFields[2].Text = torrentDetails.uploadedBytes.ToString();
     _infoTextFields[3].Text = torrentDetails.missingPiecesCount.ToString();
     _infoTextFields[4].Text = torrentDetails.status.ToString();
     _infoTextFields[5].Text = torrentDetails.swarmSize.ToString();
     _infoTextFields[6].Text = torrentDetails.deadPeers.ToString();
     _infoTextFields[7].Text = torrentDetails.trackerStatus.ToString();
     _infoTextFields[8].Text = DownloadRate(torrentDetails.bytesPerSecond);
 }
コード例 #6
0
        /// <summary>
        /// Update whole information window
        /// </summary>
        /// <param name="torrentDetails"></param>
        public void Update(TorrentDetails torrentDetails)
        {
            List <string> peers = new List <string>();

            foreach (var peer in torrentDetails.peers)
            {
                peers.Add(peer.ip + ":" + peer.port.ToString());
            }
            Application.MainLoop.Invoke(() =>
            {
                UpdatePeers(peers.ToArray());
                UpdateInformation(torrentDetails);
                if (torrentDetails.trackerStatus == TrackerStatus.Stalled)
                {
                    MessageBox.Query("Error", torrentDetails.trackerStatusMessage, "Ok");
                }
            });
        }
コード例 #7
0
        public void TestSucessfullyCreateTrackerAndStartAnnoucing()
        {
            MockAnnouncerFactory mockAnnoucerFactory = new MockAnnouncerFactory();
            Mock <IAgentNetwork> networkMock         = new Mock <IAgentNetwork>();
            MetaInfoFile         file = new MetaInfoFile(Constants.SingleFileTorrent);

            file.Parse();
            Manager manager = new Manager();
            Agent   agent   = new Agent(new Manager(), new Assembler(), networkMock.Object);

            agent.Startup();
            TorrentContext tc      = new TorrentContext(file, new Selector(), new DiskIO(manager), Constants.DestinationDirectory);
            Tracker        tracker = new Tracker(tc, mockAnnoucerFactory);

            agent.AddTorrent(tc);
            agent.AttachPeerSwarmQueue(tracker);
            tracker.StartAnnouncing();
            TorrentDetails torrentDetails = agent.GetTorrentDetails(tc);

            Assert.Equal(TrackerStatus.Running, torrentDetails.trackerStatus);
        }
コード例 #8
0
        public TorrentDetails ParseTorrentDetails(string page)
        {
            if (page == null)
            {
                throw new ArgumentNullException(nameof(page));
            }

            TorrentDetails details = new TorrentDetails();

            var dom = CQ.Create(page);

            details.Description  = dom.Select("div.block.description article").Html();
            details.Name         = dom.Select("div.accordion div:nth-of-type(1) table tr:nth-of-type(1) td").Text();
            details.Categoryname = dom.Select("div.accordion div:nth-of-type(1) table tr:nth-of-type(3) td").Text();
            details.Category     = MapCategory(details.Categoryname);
            details.Privacy      = Privacy.Normal;
            details.Owner        = 0;
            details.Username     = dom.Select("div.accordion div:nth-of-type(1) table tr:nth-of-type(6) td").Text();
            details.IsVerified   = dom.Select("div.block.description .torrent-status.verify").Any();

            return(details);
        }
コード例 #9
0
        public void TestGetTorrentDetailsOfTorrentNotAddedToAgent()
        {
            MetaInfoFile file = new MetaInfoFile(Constants.SingleFileTorrent);

            file.Parse();
            Manager manager = new Manager();
            Mock <IAgentNetwork> networkMock = new Mock <IAgentNetwork>();
            Agent agent = new Agent(new Manager(), new Assembler(), networkMock.Object);

            agent.Startup();
            TorrentContext      tc      = new TorrentContext(file, new Selector(), new DiskIO(manager), Constants.DestinationDirectory);
            Tracker             tracker = new Tracker(tc);
            BitTorrentException error   = Assert.Throws <BitTorrentException>(() => { TorrentDetails details = agent.GetTorrentDetails(tc); });

            Assert.Equal("BitTorrent Error: Failure to get torrent details.Torrent hasnt been added to agent.", error.Message);
        }