small tidies

This commit is contained in:
Collin M. Barrett 2019-06-28 16:10:20 -05:00
parent 88dc9174f6
commit 5e34720754
3 changed files with 15 additions and 8 deletions

View file

@ -73,11 +73,13 @@ protected override async Task Handle(Command request, CancellationToken cancella
}
catch (NotImplementedException)
{
_logger.LogWarning($"File extension not supported for list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}.");
_logger.LogWarning(
$"File extension not supported for list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}.");
}
catch (ArgumentException ex)
{
_logger.LogError(ex, $"Could not determine the file extension for list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}.");
_logger.LogError(ex,
$"Could not determine the file extension for list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}.");
}
}
@ -86,12 +88,15 @@ private async Task DownloadByFileExtension(Command request, CancellationToken ca
var extension = Path.GetExtension(request.ListInfo.ViewUrl.AbsolutePath);
if (DownloadRequestsByFileExtension.ContainsKey(extension))
{
_logger.LogInformation($"Downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}...");
await _mediator.Send(DownloadRequestsByFileExtension[extension].Invoke(request.ListInfo), cancellationToken);
_logger.LogInformation(
$"Downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}...");
await _mediator.Send(DownloadRequestsByFileExtension[extension].Invoke(request.ListInfo),
cancellationToken);
}
else
{
_logger.LogWarning($"File extension not recognized for list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}.");
_logger.LogWarning(
$"File extension not recognized for list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}.");
}
}
}

View file

@ -36,7 +36,7 @@ protected override async Task Handle(Command request, CancellationToken cancella
new ExecutionDataflowBlockOptions {MaxDegreeOfParallelism = MaxDegreeOfParallelism}
);
foreach (var list in request.ListInfo)
await downloader.SendAsync(list, cancellationToken);
await downloader.SendAsync(list, cancellationToken);
downloader.Complete();
await downloader.Completion;
}

View file

@ -38,7 +38,8 @@ protected override async Task Handle(Command request, CancellationToken cancella
if (response.IsSuccessStatusCode)
try
{
using (Stream output = File.OpenWrite(Path.Combine("archives", $"{request.ListInfo.Id}.txt")))
using (Stream output =
File.OpenWrite(Path.Combine("archives", $"{request.ListInfo.Id}.txt")))
using (var input = await response.Content.ReadAsStreamAsync())
{
input.CopyTo(output);
@ -46,7 +47,8 @@ protected override async Task Handle(Command request, CancellationToken cancella
}
catch (HttpRequestException ex)
{
_logger.LogError(ex, $"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}.");
_logger.LogError(ex,
$"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}.");
}
}
}