public async Task DownloadEpisodeAsync(Episode episode)
{
var file = await fileDownloadManager.DownloadFileAsync(
appFolderName: AppName,
folderName: episode.Podcast.Title,
fileName: string.Format("{0:dd.MM.yyyy} - {1} - {2}", episode.Published, episode.Author, episode.Title),
fileUrl: episode.Path,
callback: c =>
{
var bytesReceived = c.Progress.BytesReceived;
var bytesToReceive = c.Progress.TotalBytesToReceive;
double percent = (bytesReceived * 100) / bytesToReceive;
Debug.WriteLine(string.Format("Received: {0}/{1} ({2:P1})", bytesReceived, bytesToReceive, percent / 100.0));
},
errorCallback: ex =>
{
Debug.WriteLine(string.Format(ex.Message));
}
);
if (file != null)
{
var podcast = episode.Podcast;
var episodeToUpdate = podcast.Episodes.Where(e => e.Guid == episode.Guid).SingleOrDefault();
episodeToUpdate.Path = file.Path;
await storageService.SaveAsync(episode.Podcast);
}
}