private void TorrentRemovedAlert(Core.torrent_removed_alert a) { Interlocked.MemoryBarrier(); using (Core.Sha1Hash sha1hash = a.info_hash) { string hash = sha1hash.ToString(); if (TorrentList.ToList().Any(e => e.Hash == hash)) { Models.TorrentItem ti = TorrentList.ToList().First(f => f.Hash == hash); log.Debug("removing {0}", ti.Name); Application.Current.Dispatcher.BeginInvoke( System.Windows.Threading.DispatcherPriority.Normal, (Action) delegate() { TorrentList.Remove(ti); }); log.Info("{0} removed", ti.Name); } if (File.Exists("./Fastresume/" + hash + ".fastresume")) { File.Delete("./Fastresume/" + hash + ".fastresume"); } if (File.Exists("./Fastresume/" + hash + ".torrent")) { File.Delete("./Fastresume/" + hash + ".torrent"); } } }
private void PieceFinishedAlert(piece_finished_alert a) { Interlocked.MemoryBarrier(); using (Core.TorrentHandle th = a.handle) using (Core.Sha1Hash hash = th.info_hash()) { if (TorrentList.ToList().Any(x => x.Hash == hash.ToString())) { Models.TorrentItem ti = TorrentList.First(z => z.Hash == hash.ToString()); if (!ReferenceEquals(null, ti.Pieces.Parts) && ti.Pieces.Parts.Any(q => q.Id == a.piece_index)) { ti.Pieces.Parts[a.piece_index].Downloaded = true; log.Debug("{0} for {1}", a.piece_index, ti.Name); foreach (Models.FileEntry item in ti.FileList) { foreach (Models.Part part in item.Pieces.Where(k => k.Id == a.piece_index)) { part.Downloaded = true; } } if (ti.SequentialDownload) { if (ti.Pieces.Parts.Any(w => w.Downloaded == false)) { Models.Part mp = ti.Pieces.Parts.First(w => w.Downloaded == false); mp.Priority = 7; th.piece_priority(mp.Id, 7); } } } } } }
private async void StateUpdateAlert(Core.state_update_alert a) { Interlocked.MemoryBarrier(); log.Trace("state update alert for {0} torrents", a.status.Count()); if (a.status.Count() > 0 && log.IsDebugEnabled) { log.Debug("state update alert for {0} torrents", a.status.Count()); } foreach (Core.TorrentStatus ts in a.status) { using (ts) using (Core.Sha1Hash hash = ts.info_hash) { if (TorrentList.ToList().Any(z => z.Hash == hash.ToString())) { Models.TorrentItem ti = TorrentList.First(e => e.Hash == hash.ToString()); await System.Threading.Tasks.Task.Run(() => ti.Update(ts)); } } } }