private static void Process_NewRssItems(RssUrlEntry entry, RssTorrent[] new_items) { foreach (var nitem in new_items) { if (url_404.Contains(nitem.TorrentFileUrl)) { continue; } string save_path = Path.Combine(RssTorrentsStorageDirectory, Utility.CleanFileName(nitem.Name) + ".torrent"); nitem.TorrentFilePath = save_path; if (File.Exists(save_path)) { //re-load from downloaded file App.Current.Dispatcher.Invoke(new Action(() => { nitem.LastResponseMessage = "Data was already saved"; nitem.LastResponseType = DownloadRssResponse.ResonseType.OK; nitem.Success = AppState.AddTorrentRss(save_path, entry); })); continue; } if (!IsQueued(nitem)) { QueuedItems.Add(nitem); System.Threading.Tasks.Task.Factory.StartNew(new Action(() => { Debug.WriteLine("[Rssdownloader-TQ]: Work Item '{0}' has been started", nitem.Name, ""); var res = download(nitem.IsMagnetOnly ? nitem.TorrentMagnetUrl : nitem.TorrentFileUrl); nitem.LastResponse = res; Debug.WriteLine("[Rssdownloader-TQ]: Work Item '{0}' resp type is {1}", nitem.Name, res.Type); if (res.Type == DownloadRssResponse.ResonseType.OK || res.Type == DownloadRssResponse.ResonseType.MagnetLink) { byte[] data = res.Data; if (data.Length > 0) { File.WriteAllBytes(save_path, data); Debug.WriteLine("[Rssdownloader-TQ]: Work Item '{0}' succesfully downloaded", nitem.Name, ""); App.Current.Dispatcher.Invoke(new Action(() => { nitem.Success = AppState.AddTorrentRss(save_path, entry); })); } else { if (res.Type == DownloadRssResponse.ResonseType.MagnetLink) { Debug.WriteLine("[Rssdownloader-TQ]: Cannot add torrent ({0}) magnet ('{1}')", nitem.Name, nitem.TorrentMagnetUrl); } //What should we do? } } else if (res.Type == DownloadRssResponse.ResonseType.NotFound) { if (!url_404.Contains(nitem.TorrentFileUrl)) { url_404.Add(nitem.TorrentFileUrl); Debug.WriteLine("[Rssdownloader-TQ]: URL '{0}' not found, therefore banned.", nitem.TorrentFileUrl, ""); } } QueuedItems.Remove(nitem); return; })); } } }