private static void OnTorrentAddAlert(Core.torrent_added_alert a) { Core.TorrentHandle th = a.handle; if (TorrentHandles.TryAdd(th.info_hash().ToString(), th)) { using (Core.TorrentStatus ts = th.status()) { var stat = "Paused"; if (!ts.paused) { stat = Utils.GiveMeStateFromEnum(ts.state); } var evnt = new EventsArgs.OnTorrentAddedEventArgs { Hash = th.info_hash().ToString(), Name = ts.name, Progress = ts.progress, QueuePosition = ts.queue_position, Status = stat }; //log.Debug("torrent added: name {0}; status {1}; hash {2}", ts.name, ts.state.ToString(), ts.info_hash.ToString()); // notify web that a new id must be requested via webapi if (webServer != null) { var context = Microsoft.AspNet.SignalR.GlobalHost.ConnectionManager.GetHubContext <www.SignalRHub>(); context.Clients.All.notifyTorrentAdded(evnt.Hash); } TorrentAdded?.Invoke(null, evnt); } } }
public static void Terminate() { _sessionStatusDispatcherTimer.Stop(); _sessionStatusDispatcherTimer.Dispose(); _dispatcherTimer.Stop(); _dispatcherTimer.Dispose(); stopWeb(); _torrentSession.pause(); /* http://libtorrent.org/reference-Core.html#save_resume_data() */ foreach (var item in TorrentHandles) { if (item.Value.is_valid()) { Core.TorrentStatus ts = item.Value.status(); if (ts.has_metadata && ts.need_save_resume) { /* http://libtorrent.org/reference-Core.html#save_resume_flags_t */ item.Value.save_resume_data(1 | 2 | 4); ++outstanding_resume_data; } } } no_more_resume = true; if (outstanding_resume_data != 0) { no_more_data.WaitOne(); } TerminateSaveResume(); }