From bf09ea36f9286f21e453e0fa2f136d9d2f020320 Mon Sep 17 00:00:00 2001 From: NextTurn <45985406+NextTurn@users.noreply.github.com> Date: Sun, 7 Apr 2019 00:00:00 +0800 Subject: [PATCH] Update downloading --- src/Core/ServiceWrapper/Main.cs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/Core/ServiceWrapper/Main.cs b/src/Core/ServiceWrapper/Main.cs index a47f3f4..fac16a6 100644 --- a/src/Core/ServiceWrapper/Main.cs +++ b/src/Core/ServiceWrapper/Main.cs @@ -211,23 +211,32 @@ namespace winsw tasks[i] = download.PerformAsync(); } - Task.WhenAll(tasks); - for (int i = 0; i < tasks.Length; i++) + try { - if (tasks[i].IsFaulted) + Task.WaitAll(tasks); + } + catch (AggregateException e) + { + List exceptions = new List(e.InnerExceptions.Count); + for (int i = 0; i < tasks.Length; i++) { - Download download = downloads[i]; - string errorMessage = $"Failed to download {download.From} to {download.To}"; - AggregateException exception = tasks[i].Exception!; - LogEvent($"{errorMessage}. {exception.Message}"); - Log.Error(errorMessage, exception); - - // TODO: move this code into the download logic - if (download.FailOnError) + if (tasks[i].IsFaulted) { - throw new IOException(errorMessage, exception); + Download download = downloads[i]; + string errorMessage = $"Failed to download {download.From} to {download.To}"; + AggregateException exception = tasks[i].Exception!; + LogEvent($"{errorMessage}. {exception.Message}"); + Log.Error(errorMessage, exception); + + // TODO: move this code into the download logic + if (download.FailOnError) + { + exceptions.Add(new IOException(errorMessage, exception)); + } } } + + throw new AggregateException(exceptions); } #else foreach (Download download in _descriptor.Downloads)