public override async Task Refresh() { var client = CreateClient(); var torrents = await client.GetListAsync(); var completeds = torrents.Result.Torrents.Where(t => t.Downloaded > 0 && t.Remaining == 0); foreach (var completed in completeds) { var hash = completed.Hash; var files = (await client.GetFilesAsync(hash)).Result.Files; var fileNames = files.SelectMany(fc => fc.Value.Select(f => f.Name)); var sourcePath = completed.Path; var args = new DownloadCompletedEventArgs(hash, sourcePath, fileNames); OnDownloadCompleted(args); if (args.Found && Settings.DeleteCompletedTorrents) { await client.DeleteTorrentAsync(hash); await Task.Delay(1618); if (args.Moved) Helper.DeleteDirectory(sourcePath); } } }
public override Task Refresh() { return Task.Run(() => { var client = CreateClient(); var torrents = client.GetTorrents(new[] {Fields.ID, Fields.HASH_STRING, Fields.PERCENT_DONE, Fields.DOWNLOAD_DIR, Fields.FILES}); var completeds = torrents.Torrents.Where(t => t.PercentDone >= 1); foreach (var completedTmp in completeds) { var completed = completedTmp; var sourcePath = completed.DownloadDir; var files = completed.Files.Select(f => Path.GetFileName(Path.Combine(completed.DownloadDir, f.Name))); var args = new DownloadCompletedEventArgs(completed.HashString, sourcePath, files); OnDownloadCompleted(args); if (args.Found && Settings.DeleteCompletedTorrents) { client.RemoveTorrents(new[] { completed.ID }, args.Moved); if (args.Moved) Helper.DeleteDirectory(sourcePath); } } }); }