Beispiel #1
0
        internal static ITorrent CreateFromHandle(TorrentHandle handle, ITorrentMetadataRepository metadataRepository)
        {
            using (handle)
            using (var file = handle.TorrentFile)
            using (var status = handle.QueryStatus())
            {
                var t = new Torrent
                {
                    InfoHash = handle.InfoHash.ToHex(),
                    Name = status.Name,
                    SavePath = status.SavePath,
                    Size = file == null ? -1 : file.TotalSize,
                    Progress = status.Progress,
                    DownloadSpeed = status.DownloadRate,
                    UploadSpeed = status.UploadRate,
                    TotalDownloadedBytes = status.TotalDownload,
                    TotalUploadedBytes = status.TotalUpload,
                    State = (Common.BitTorrent.TorrentState) (int) status.State,
                    Paused = status.Paused,
                    Files = new ITorrentFile[file == null ? 0 : file.NumFiles],
                    Peers = handle.GetPeerInfo().Select(Peer.CreateFromPeerInfo).ToArray()
                };

                t.Label = metadataRepository.GetLabel(t.InfoHash);

                // If no torrent file (ie. downloading metadata)
                if (file == null) return t;

                var progresses = handle.GetFileProgresses();
                var priorities = handle.GetFilePriorities();

                for (var i = 0; i < file.NumFiles; i++)
                {
                    var entry = file.FileAt(i);
                    var torrentFile = TorrentFile.CreateFromEntry(entry, progresses[i], priorities[i]);

                    t.Files[i] = torrentFile;
                }

                return t;
            }
        }
        public ITorrent GetByInfoHash(string infoHash)
        {
            var handle = _session.FindTorrent(infoHash);

            return(handle == null ? null : Torrent.CreateFromHandle(handle, _metadataRepository));
        }
 public IEnumerable <ITorrent> GetAll()
 {
     return(_session.GetTorrents().Select(t => Torrent.CreateFromHandle(t, _metadataRepository)));
 }