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"); } } }
/// <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(); } } }
public bool UpdateData() { lock (lockUpdate) { string response = GetResponse("web.update_ui", DelugeAPI.UpdateParams); if (response == null || response.Length == 0) { return(false); } TorrentLabelList lbls = new TorrentLabelList(); UpdateResponse update = js.Deserialize <UpdateResponse>(response); foreach (object[] lbl in update.filters.label) { TorrentLabel label = new TorrentLabel(); label.Name = (string)lbl[0]; label.Count = (int)lbl[1]; lbls.Add(label); } _labels = lbls; TorrentList oldTorrentsAll = _torrentsAll; TorrentList newTorrentsAll = new TorrentList(); foreach (KeyValuePair <string, DelugeTorrent> pair in update.torrents) { DelugeTorrent tor = pair.Value; Torrent torrent = new Torrent(this); try { torrent.Hash = pair.Key; torrent.Status = 0;// get Status code torrent.Name = tor.name; torrent.Size = tor.total_size; torrent.Progress = tor.progress; torrent.Downloaded = tor.total_done; torrent.Uploaded = tor.total_uploaded; torrent.Ratio = (long)Math.Round(tor.ratio); torrent.UploadSpeed = (long)Math.Round(tor.upload_payload_rate); torrent.DownloadSpeed = (long)Math.Round(tor.download_payload_rate); torrent.ETA = (int)Math.Round(tor.eta); torrent.Label = tor.label; torrent.PeersConnected = tor.num_peers; torrent.PeersInSwarm = tor.total_peers; torrent.SeedsConnected = tor.num_seeds; torrent.SeedsInSwarm = tor.total_seeds; torrent.Availability = (int)Math.Round(tor.distributed_copies); torrent.TorrentQueueOrder = (int)Math.Round(tor.queue); torrent.Remaining = tor.total_size - tor.total_done; torrent.DownloadURL = ""; torrent.RSSFeedURL = ""; torrent.StatusMessage = tor.state; torrent.StreamID = ""; torrent.AddedOn = (int)Math.Round(tor.time_added); torrent.CompletedOn = 0; torrent.AppUpdateURL = ""; torrent.TorrentSavePath = tor.save_path; } catch { } newTorrentsAll.Add(torrent); } TorrentList newTorrentsActive = new TorrentList(); foreach (Torrent torrent in newTorrentsAll) { if (torrent.HasStatus((int)Torrent.UTorrentStatus.Started)) { newTorrentsActive.Add(torrent); } if (oldTorrentsAll != null) { Torrent oldTorrent = oldTorrentsAll.TorrentByHash(torrent.Hash); if (oldTorrent == null) { //this is new torrent! Send event! TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1)); int now = (int)t.TotalSeconds; if (TorrentAdded != null && ((now - torrent.AddedOn) < Math.Max(60, Convert.ToInt32(_outtimer) * 2))) { TorrentAdded(torrent); } } else { if (torrent.Progress == 100 && oldTorrent.Progress < 100) { TorrentCompleted(torrent); } oldTorrentsAll.Remove(oldTorrent); } } } if (oldTorrentsAll != null && newTorrentsAll != null && oldTorrentsAll.Count != 0) { if (newTorrentsAll.Count / oldTorrentsAll.Count > 0.95) { foreach (Torrent torrent in oldTorrentsAll) { //there are all removed torrents, send events! if (TorrentRemoved != null) { TorrentRemoved(torrent); } } } } //create no label label! TorrentLabel nolabel = new TorrentLabel(); nolabel.Name = ""; foreach (Torrent torrent in newTorrentsAll) { if (torrent.Label == "") { torrent.Label = nolabel.Name; nolabel.Count = nolabel.Count + 1; } } if (!_labels.Exists(e => e.Name == "")) { _labels.Insert(0, nolabel); } if (_torrentsAll == null) { _torrentsAll = new TorrentList(); } _torrentsAll.Clear(); foreach (Torrent torrent in newTorrentsAll) { _torrentsAll.Add(torrent); } } return(true); }
public bool UpdateData() { lock (lockUpdate) { prot.DownloadManager.Update(); TorrentList __torrentsAll = new TorrentList(); TorrentList __torrentsActive = new TorrentList(); Dictionary <string, global::AzureusEngine.AzCommunication.Download> _torrentMapping = new Dictionary <string, global::AzureusEngine.AzCommunication.Download>(); Dictionary <string, int> categories = new Dictionary <string, int>(); foreach (Download dl in prot.DownloadManager.Downloads) { Sohvaperuna.TorrentEngine.Torrent tor = toUtorrent(dl); if (!categories.ContainsKey(tor.Label)) { categories.Add(tor.Label, 1); } else { categories[tor.Label] = categories[tor.Label] + 1; } __torrentsAll.Add(tor); if (!torrentMapping.ContainsKey(tor.Hash)) { torrentMapping.Add(tor.Hash, dl); if (TorrentAdded != null) { TorrentAdded(tor); } } if (tor.Status == 1) { __torrentsActive.Add(tor); } } foreach (Sohvaperuna.TorrentEngine.Torrent tor in __torrentsAll) { Sohvaperuna.TorrentEngine.Torrent _tor = _torrentsAll.TorrentByHash(tor.Hash); if (tor != null) { _torrentsAll.Remove(tor); } } _torrentsActive = __torrentsActive; _torrentsAll = __torrentsAll; TorrentLabelList labels = new TorrentLabelList(); //_labels.Clear(); foreach (string s in categories.Keys) { TorrentLabel lbl = new TorrentLabel(); lbl.Name = s; lbl.Count = categories[s]; labels.Add(lbl); } _labels = labels; /* * string response = GetResponse("list=1"); * Regex re = new Regex("\\[\"(.*?)\",([0-9])+]"); * MatchCollection matches = re.Matches(response); * _labels = new UTorrentLabelList(); * foreach (Match match in matches) * { * UTorrentLabel label = new UTorrentLabel(); * label.Name = match.Groups[1].Value.Replace(@"\\", @"\"); ; * label.Count = Convert.ToInt32( match.Groups[2].Value ); * _labels.Add(label); * } * * re = new Regex("\\[\"(.*?)\",([0-9-]+),\"(.*)\",([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),\"(.*)\",([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+)]"); * matches = re.Matches(response); * * UTorrentList oldTorrentsAll = _torrentsAll; * UTorrentList newTorrentsAll = new UTorrentList(); * foreach (Match match in matches) * { * UTorrent torrent = new UTorrent( this ); * torrent.Hash = match.Groups[1].Value; * torrent.Status = Convert.ToInt32(match.Groups[2].Value); * torrent.Name = match.Groups[3].Value; * torrent.Size = Convert.ToInt64(match.Groups[4].Value); * torrent.Progress = Convert.ToInt32(match.Groups[5].Value) / 10.0; * torrent.Downloaded = Convert.ToInt64(match.Groups[6].Value); * torrent.Uploaded = Convert.ToInt64(match.Groups[7].Value); * torrent.Ratio = Convert.ToInt64(match.Groups[8].Value); * torrent.UploadSpeed = Convert.ToInt64(match.Groups[9].Value); * torrent.DownloadSpeed = Convert.ToInt64(match.Groups[10].Value); * torrent.ETA = Convert.ToInt32(match.Groups[11].Value); * torrent.Label = match.Groups[12].Value.Replace( @"\\", @"\" ); * torrent.PeersConnected = Convert.ToInt32(match.Groups[13].Value); * torrent.PeersInSwarm = Convert.ToInt32(match.Groups[14].Value); * torrent.SeedsConnected = Convert.ToInt32(match.Groups[15].Value); * torrent.SeedsInSwarm = Convert.ToInt32(match.Groups[16].Value); * torrent.Availability = Convert.ToInt32(match.Groups[17].Value); * torrent.TorrentQueueOrder = Convert.ToInt32(match.Groups[18].Value); * torrent.Remaining = Convert.ToInt64(match.Groups[19].Value); * * newTorrentsAll.Add(torrent); * } * * UTorrentList newTorrentsActive = new UTorrentList(); * * foreach (UTorrent torrent in newTorrentsAll) * { * if (torrent.HasStatus((int)UTorrent.UTorrentStatus.Started)) * { * newTorrentsActive.Add(torrent); * } * * if (oldTorrentsAll != null) * { * UTorrent oldTorrent = oldTorrentsAll.TorrentByHash(torrent.Hash); * if (oldTorrent == null) * { * //this is new torrent! Send event! * if (TorrentAdded != null) * { * TorrentAdded(torrent); * } * } * else * { * oldTorrentsAll.Remove(oldTorrent); * } * } * } * * if (oldTorrentsAll != null) * { * foreach (UTorrent torrent in oldTorrentsAll) * { * //there are all removed torrents, send events! * if (TorrentRemoved != null) * { * TorrentRemoved(torrent); * } * } * } * * //create no label label! * UTorrentLabel nolabel = new UTorrentLabel(); * nolabel.Name = ""; * * foreach (UTorrent torrent in newTorrentsAll) * { * if (torrent.Label == "") * { * torrent.Label = nolabel.Name; * nolabel.Count = nolabel.Count + 1; * } * } * * _labels.Insert(0, nolabel); * * if (_torrentsActive == null) * { * _torrentsActive = new UTorrentList(); * } * _torrentsActive.Clear(); * foreach (UTorrent torrent in newTorrentsActive) * { * _torrentsActive.Add(torrent); * } * if (_torrentsAll == null) * { * _torrentsAll = new UTorrentList(); * } * _torrentsAll.Clear(); * foreach (UTorrent torrent in newTorrentsAll) * { * _torrentsAll.Add(torrent); * }*/ } return(true); }