Esempio n. 1
0
        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);
                                }
                            }
                        }
                    }
                }
        }
Esempio n. 2
0
        /// <summary>
        /// Remove torrent without data.
        /// </summary>
        /// <param name="id">Torrent id.</param>
        private async void RemoveTorrent(uint id)
        {
            if (_transmissionClient is not null)
            {
                var toRemoveIds = new[] { id };

                var result = await _transmissionClient.TorrentRemoveAsync(toRemoveIds, new CancellationToken(), false);


                foreach (var toRemoveId in toRemoveIds)
                {
                    var itm = TorrentList.First(x => x.Id == toRemoveId);
                    TorrentList.Remove(itm);

                    //FOR WHAT IS THAT?!
                    //TODO: Remove maybe
                    allTorrents.Torrents = allTorrents.Torrents.Where(torrentInfo => torrentInfo.Id == toRemoveId).ToArray();
                }
            }
        }
Esempio n. 3
0
 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));
                 }
             }
     }
 }