Popcorn.Services.Movie.MovieService.DownloadCastImageAsync C# (CSharp) Метод

DownloadCastImageAsync() публичный Метод

Download actors' image for a movie
public DownloadCastImageAsync ( MovieFull movie, CancellationTokenSource ct ) : Task
movie Popcorn.Models.Movie.Full.MovieFull The movie to process
ct System.Threading.CancellationTokenSource Used to cancel downloading actor image
Результат Task
        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.");
            }
        }