private bool DownloadTorrent(string path) { try { ClientEngine engine = new ClientEngine(new EngineSettings()); MonoTorrent.Common.Torrent torrent = MonoTorrent.Common.Torrent.Load(@"C:\WexflowTesting\Torrent\sample.torrent"); TorrentManager torrentManager = new TorrentManager(torrent, @"C:\WexflowTesting\Torrent\", new TorrentSettings()); engine.Register(torrentManager); torrentManager.Start(); // Keep running while the torrent isn't stopped or paused. while (torrentManager.State != TorrentState.Stopped && torrentManager.State != TorrentState.Paused) { Thread.Sleep(1000); if (torrentManager.Progress == 100.0) { // If we want to stop a torrent, or the engine for whatever reason, we call engine.StopAll() torrentManager.Stop(); engine.StopAll(); break; } } InfoFormat("The torrent {0} download succeeded.", path); return(true); } catch (ThreadAbortException) { throw; } catch (Exception e) { ErrorFormat("An error occured while downloading the torrent {0}: {1}", path, e.Message); return(false); } }
public void NodesIsNotAList() { torrentInfo["nodes"] = new BEncodedString("192.168.0.1:12345"); torrent = Torrent.Load(torrentInfo); Assert.IsNull(torrent.Nodes, "#1"); }
public Torrent ToTorrent() { return(Torrent.Load(ToDictionary())); }
public EditableTorrent(Torrent torrent) { Check.Torrent(torrent); Initialise(torrent.ToDictionary()); }
public bool Download() { try { string torrent = DownloadTorrentFile(Settings.ServerId); if (torrent != null) { MonoTorrent.Common.Torrent decoded = null; try { decoded = MonoTorrent.Common.Torrent.Load(torrent); } catch (Exception decEx) { decEx.ToLog(LogLevel.Error); Stop(); return(false); } External.AppendManager(decoded, Settings.DownloadPath, new TorrentSettings(5, 100, Settings.MaxDownloadSpeed, Settings.MaxUploadSpeed)); if (External.TryGetFastResume(Settings.GetResumeFile())) { if (External.FastResume.ContainsKey(decoded.InfoHash.ToHex())) { External.Manager.LoadFastResume(new FastResume((BEncodedDictionary)External.FastResume[decoded.InfoHash.ToHex()])); } } External.Engine.Register(External.Manager); External.Manager.PeersFound += OnPeersFounded; External.Manager.StartAsync().Wait(); var thread = new Thread(() => { while (External.Manager.State != TorrentState.Stopped) { var data = new TorrentData(); data.Build( FileUtils.FormatByte(External.Engine.TotalDownloadSpeed), FileUtils.FormatByte(External.Engine.DiskManager.TotalRead), FileUtils.FormatByte(External.Engine.DiskManager.TotalWritten), FileUtils.FormatByte(External.Engine.DiskManager.WriteRate), (int)External.Manager.Progress); OnChangeState?.Invoke(data); if (data.Progress == 100) { break; } Thread.Sleep(500); } DownloadStopped(); }); thread.Start(); return(true); } } catch (Exception ex) { ex.ToLog(LogLevel.Error); return(false); } return(false); }