Пример #1
0
        public async Task NoAnnouncesTest()
        {
            rig.TorrentDict.Remove("announce-list");
            rig.TorrentDict.Remove("announce");
            Torrent t = Torrent.Load(rig.TorrentDict);
            await rig.Engine.Unregister(rig.Manager);

            TorrentManager manager = new TorrentManager(t, "", new TorrentSettings());
            await rig.Engine.Register(manager);

            AutoResetEvent handle = new AutoResetEvent(false);

            manager.TorrentStateChanged += delegate(object o, TorrentStateChangedEventArgs e) {
                if (e.NewState == TorrentState.Downloading || e.NewState == TorrentState.Stopped)
                {
                    handle.Set();
                }
            };
            await manager.StartAsync();

            handle.WaitOne();
            System.Threading.Thread.Sleep(1000);
            await manager.StopAsync();

            Assert.IsTrue(handle.WaitOne(10000, true), "#1");
            await manager.TrackerManager.Announce();
        }
Пример #2
0
        private async Task OnMetadataLoaded(object sender, TorrentStateChangedEventArgs e)
        {
            Debug.Assert(_manager.HasMetadata, "Metadata was not found");
            Console.WriteLine("Metadata found, stopping to load fast resume");
            await _manager.StopAsync();

            await ChangePicker();
            await LoadFastResumeData();

            _dataAccessor.SetTorrentFile(_manager.Torrent.Files.First());
            await _matroskaPlayer.OnTorrentLoaded(sender, e);

            if (_onMetadataLoadedListener != null)
            {
                MetadataLoaded           -= _onMetadataLoadedListener;
                _onMetadataLoadedListener = null;
            }

            await _manager.StartAsync();
        }
        /// <summary>
        /// Downloads the .torrent metadata for the provided MagnetLink.
        /// </summary>
        /// <param name="magnetLink">The MagnetLink to get the metadata for.</param>
        /// <param name="token">The cancellation token used to to abort the download. This method will
        /// only complete if the metadata successfully downloads, or the token is cancelled.</param>
        /// <returns></returns>
        public async Task<ReadOnlyMemory<byte>> DownloadMetadataAsync (MagnetLink magnetLink, CancellationToken token)
        {
            await MainLoop;

            var manager = new TorrentManager (this, magnetLink, "", new TorrentSettings ());
            var metadataCompleted = new TaskCompletionSource<ReadOnlyMemory<byte>> ();
            using var registration = token.Register (() => metadataCompleted.TrySetResult (null));
            manager.MetadataReceived += (o, e) => metadataCompleted.TrySetResult (e);

            await Register (manager, isPublic: false);
            await manager.StartAsync (metadataOnly: true);
            var data = await metadataCompleted.Task;
            await manager.StopAsync ();
            await RemoveAsync (manager);

            token.ThrowIfCancellationRequested ();
            return data;
        }
Пример #4
0
        /// <summary>
        /// Downloads the .torrent metadata for the provided MagnetLink.
        /// </summary>
        /// <param name="magnetLink">The MagnetLink to get the metadata for.</param>
        /// <param name="token">The cancellation token used to to abort the download. This method will
        /// only complete if the metadata successfully downloads, or the token is cancelled.</param>
        /// <returns></returns>
        public async Task <byte[]> DownloadMetadataAsync(MagnetLink magnetLink, CancellationToken token)
        {
            var manager           = new TorrentManager(magnetLink);
            var metadataCompleted = new TaskCompletionSource <byte[]> ();

            using var registration    = token.Register(() => metadataCompleted.TrySetResult(null));
            manager.MetadataReceived += (o, e) => metadataCompleted.TrySetResult(e);

            await Register(manager, isPublic : false);

            await manager.StartAsync(metadataOnly : true);

            var data = await metadataCompleted.Task;
            await manager.StopAsync();

            await Unregister(manager);

            token.ThrowIfCancellationRequested();
            return(data);
        }