public async Task DownloadCastImageAsync(MovieFull movie, CancellationTokenSource ct)
{
if (movie.Cast == null)
return;
var watch = Stopwatch.StartNew();
try
{
await
movie.Cast.ForEachAsync(
cast =>
DownloadFileHelper.DownloadFileTaskAsync(cast.SmallImage,
Constants.CastMovieDirectory + cast.Name + Constants.ImageFileExtension, ct: ct),
(cast, t) =>
{
if (t.Item3 == null && !string.IsNullOrEmpty(t.Item2))
cast.SmallImagePath = t.Item2;
});
}
catch (Exception exception) when (exception is TaskCanceledException)
{
Logger.Debug(
"DownloadCastImageAsync cancelled.");
}
catch (Exception exception)
{
Logger.Error(
$"DownloadCastImageAsync: {exception.Message}");
throw;
}
finally
{
watch.Stop();
var elapsedMs = watch.ElapsedMilliseconds;
Logger.Debug(
$"DownloadCastImageAsync ({movie.ImdbCode}) in {elapsedMs} milliseconds.");
}
}