private async Task CreateAndAddTorrentAsync(StageTorrentDto torrentDto) { var tempDir = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); var torrentFilePath = Path.Combine(tempDir, torrentDto.Name + ".torrent"); var torrentDataDir = Path.Combine(tempDir, torrentDto.Name); Directory.CreateDirectory(torrentDataDir); var torrentFileMappings = await CreateTorrentFilesAsync(torrentDto, torrentDataDir).ConfigureAwait(false); var newTorrentFile = new NewTorrentFile { Name = torrentDto.Name, TrackerAnnounceUrls = new string[] { torrentDto.TrackerAnnounceUrl1, torrentDto.TrackerAnnounceUrl2 } .Where(s => !string.IsNullOrWhiteSpace(s)) .ToList(), FileMappings = torrentFileMappings }; await _torrentFileHelper.CreateTorrentAsync(torrentFilePath, newTorrentFile); await _torrentClient.AddTorrentAsync(torrentDto.Name, torrentFilePath, torrentDto.Location, newTorrentFile.FileMappings.Count()).ConfigureAwait(false); DI.Get <Dictionary <string, string> >("TorrentDataFolders")[torrentDto.Name] = torrentDataDir; }