diff --git a/src/FilterLists.Agent/Core/IListRepository.cs b/src/FilterLists.Agent/Core/List/IListRepository.cs similarity index 53% rename from src/FilterLists.Agent/Core/IListRepository.cs rename to src/FilterLists.Agent/Core/List/IListRepository.cs index 5f83ce311..3850b34a5 100644 --- a/src/FilterLists.Agent/Core/IListRepository.cs +++ b/src/FilterLists.Agent/Core/List/IListRepository.cs @@ -1,9 +1,10 @@ using System.Net.Http; -namespace FilterLists.Agent.Core +namespace FilterLists.Agent.Core.List { public interface IListRepository { + //TODO: expose GetList() method rather than HttpClient HttpClient HttpClient { get; } } } \ No newline at end of file diff --git a/src/FilterLists.Agent/Core/List/IListUrlRepository.cs b/src/FilterLists.Agent/Core/List/IListUrlRepository.cs new file mode 100644 index 000000000..c5f49f0e3 --- /dev/null +++ b/src/FilterLists.Agent/Core/List/IListUrlRepository.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; + +namespace FilterLists.Agent.Core.List +{ + public interface IListUrlRepository + { + Task> GetAllAsync(CancellationToken cancellationToken); + } +} \ No newline at end of file diff --git a/src/FilterLists.Agent/Core/ListInfo/ListInfo.cs b/src/FilterLists.Agent/Core/List/ListUrl.cs similarity index 75% rename from src/FilterLists.Agent/Core/ListInfo/ListInfo.cs rename to src/FilterLists.Agent/Core/List/ListUrl.cs index 465f061d9..ddc84c959 100644 --- a/src/FilterLists.Agent/Core/ListInfo/ListInfo.cs +++ b/src/FilterLists.Agent/Core/List/ListUrl.cs @@ -1,10 +1,10 @@ using System; using JetBrains.Annotations; -namespace FilterLists.Agent.Core.ListInfo +namespace FilterLists.Agent.Core.List { [UsedImplicitly] - public class ListInfo + public class ListUrl { public int Id { get; [UsedImplicitly] private set; } public Uri ViewUrl { get; [UsedImplicitly] private set; } diff --git a/src/FilterLists.Agent/Core/ListInfo/IListInfoRepository.cs b/src/FilterLists.Agent/Core/ListInfo/IListInfoRepository.cs deleted file mode 100644 index 2d1c0b649..000000000 --- a/src/FilterLists.Agent/Core/ListInfo/IListInfoRepository.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Collections.Generic; -using System.Threading; -using System.Threading.Tasks; - -namespace FilterLists.Agent.Core.ListInfo -{ - public interface IListInfoRepository - { - Task> GetAllAsync(CancellationToken cancellationToken); - } -} \ No newline at end of file diff --git a/src/FilterLists.Agent/Extensions/UriExtensions.cs b/src/FilterLists.Agent/Extensions/UriExtensions.cs index ce1b2508e..a2a010855 100644 --- a/src/FilterLists.Agent/Extensions/UriExtensions.cs +++ b/src/FilterLists.Agent/Extensions/UriExtensions.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using FilterLists.Agent.Core.ListInfo; +using FilterLists.Agent.Core.List; namespace FilterLists.Agent.Extensions { @@ -35,7 +35,7 @@ public static IEnumerable DistributeByHost(this IEnumerable listInfo) return listInfoList.Where(u => !u.IsValidUrl()).Concat(distributedLists); } - public static IEnumerable DistributeByHost(this IEnumerable listInfo) + public static IEnumerable DistributeByHost(this IEnumerable listInfo) { return listInfo.GroupBy(l => l.ViewUrl.Host) .SelectMany((g, gi) => g.Select((l, i) => new {Index = i, GroupIndex = gi, ListInfo = l})) diff --git a/src/FilterLists.Agent/Features/Lists/ArchiveLists.cs b/src/FilterLists.Agent/Features/Lists/ArchiveLists.cs index 80254d41d..7d35828ee 100644 --- a/src/FilterLists.Agent/Features/Lists/ArchiveLists.cs +++ b/src/FilterLists.Agent/Features/Lists/ArchiveLists.cs @@ -1,6 +1,6 @@ using System.Threading; using System.Threading.Tasks; -using FilterLists.Agent.Core.ListInfo; +using FilterLists.Agent.Core.List; using MediatR; namespace FilterLists.Agent.Features.Lists @@ -14,12 +14,12 @@ public class Command : IRequest public class Handler : AsyncRequestHandler { private readonly IMediator _mediator; - private readonly IListInfoRepository _repo; + private readonly IListUrlRepository _repo; - public Handler(IMediator mediator, IListInfoRepository listInfoRepository) + public Handler(IMediator mediator, IListUrlRepository listUrlRepository) { _mediator = mediator; - _repo = listInfoRepository; + _repo = listUrlRepository; } protected override async Task Handle(Command request, CancellationToken cancellationToken) diff --git a/src/FilterLists.Agent/Features/Lists/DownloadLists.cs b/src/FilterLists.Agent/Features/Lists/DownloadLists.cs index 56e2ce649..f602ef773 100644 --- a/src/FilterLists.Agent/Features/Lists/DownloadLists.cs +++ b/src/FilterLists.Agent/Features/Lists/DownloadLists.cs @@ -4,7 +4,7 @@ using System.Threading; using System.Threading.Tasks; using System.Threading.Tasks.Dataflow; -using FilterLists.Agent.Core.ListInfo; +using FilterLists.Agent.Core.List; using FilterLists.Agent.Extensions; using MediatR; using Microsoft.Extensions.Logging; @@ -15,20 +15,20 @@ public static class DownloadLists { public class Command : IRequest { - public Command(IEnumerable listInfo) + public Command(IEnumerable listInfo) { ListInfo = listInfo; } - public IEnumerable ListInfo { get; } + public IEnumerable ListInfo { get; } } public class Handler : AsyncRequestHandler { private const int MaxDegreeOfParallelism = 5; - private static readonly Dictionary> CommandsByExtension - = new Dictionary> + private static readonly Dictionary> CommandsByExtension + = new Dictionary> { {"", l => new DownloadRawText.Command(l)}, {".7z", l => new DownloadSevenZip.Command(l)}, @@ -76,9 +76,9 @@ protected override async Task Handle(Command request, CancellationToken cancella await downloader.Completion; } - private ActionBlock BuildDownloader(CancellationToken cancellationToken) + private ActionBlock BuildDownloader(CancellationToken cancellationToken) { - return new ActionBlock( + return new ActionBlock( async l => { var errorMessage = $"Error downloading list {l.Id} from {l.ViewUrl}."; diff --git a/src/FilterLists.Agent/Features/Lists/DownloadRawText.cs b/src/FilterLists.Agent/Features/Lists/DownloadRawText.cs index 442771250..39df44452 100644 --- a/src/FilterLists.Agent/Features/Lists/DownloadRawText.cs +++ b/src/FilterLists.Agent/Features/Lists/DownloadRawText.cs @@ -4,7 +4,7 @@ using System.Threading; using System.Threading.Tasks; using FilterLists.Agent.Core; -using FilterLists.Agent.Core.ListInfo; +using FilterLists.Agent.Core.List; using FilterLists.Agent.Extensions; using MediatR; using Microsoft.Extensions.Logging; @@ -15,12 +15,12 @@ public static class DownloadRawText { public class Command : IRequest { - public Command(ListInfo listInfo) + public Command(ListUrl listUrl) { - ListInfo = listInfo; + ListUrl = listUrl; } - public ListInfo ListInfo { get; } + public ListUrl ListUrl { get; } } public class Handler : AsyncRequestHandler @@ -38,10 +38,10 @@ public Handler(IListRepository listRepository, ILogger logger) protected override async Task Handle(Command request, CancellationToken cancellationToken) { - var sourceExtension = request.ListInfo.ViewUrl.GetExtension(); + var sourceExtension = request.ListUrl.ViewUrl.GetExtension(); var destinationExtension = _extensionsToRewrite.Contains(sourceExtension) ? ".txt" : sourceExtension; - var destinationPath = Path.Combine(RepoDirectory, $"{request.ListInfo.Id}{destinationExtension}"); - using (var response = await _httpClient.GetAsync(request.ListInfo.ViewUrl, cancellationToken)) + var destinationPath = Path.Combine(RepoDirectory, $"{request.ListUrl.Id}{destinationExtension}"); + using (var response = await _httpClient.GetAsync(request.ListUrl.ViewUrl, cancellationToken)) { if (response.IsSuccessStatusCode) using (var input = await response.Content.ReadAsStreamAsync()) @@ -51,7 +51,7 @@ protected override async Task Handle(Command request, CancellationToken cancella } else _logger.LogError( - $"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}. {response.StatusCode}"); + $"Error downloading list {request.ListUrl.Id} from {request.ListUrl.ViewUrl}. {response.StatusCode}"); } } } diff --git a/src/FilterLists.Agent/Features/Lists/DownloadSevenZip.cs b/src/FilterLists.Agent/Features/Lists/DownloadSevenZip.cs index 1c81ff8c3..59c857cc2 100644 --- a/src/FilterLists.Agent/Features/Lists/DownloadSevenZip.cs +++ b/src/FilterLists.Agent/Features/Lists/DownloadSevenZip.cs @@ -3,7 +3,7 @@ using System.Threading; using System.Threading.Tasks; using FilterLists.Agent.Core; -using FilterLists.Agent.Core.ListInfo; +using FilterLists.Agent.Core.List; using MediatR; using Microsoft.Extensions.Logging; using SharpCompress.Archives; @@ -16,12 +16,12 @@ public static class DownloadSevenZip { public class Command : IRequest { - public Command(ListInfo listInfo) + public Command(ListUrl listUrl) { - ListInfo = listInfo; + ListUrl = listUrl; } - public ListInfo ListInfo { get; } + public ListUrl ListUrl { get; } } public class Handler : AsyncRequestHandler @@ -38,8 +38,8 @@ public Handler(IListRepository listRepository, ILogger logger) protected override async Task Handle(Command request, CancellationToken cancellationToken) { - var destinationDirectoryPath = Path.Combine(RepoDirectory, $"{request.ListInfo.Id}"); - using (var response = await _httpClient.GetAsync(request.ListInfo.ViewUrl, cancellationToken)) + var destinationDirectoryPath = Path.Combine(RepoDirectory, $"{request.ListUrl.Id}"); + using (var response = await _httpClient.GetAsync(request.ListUrl.ViewUrl, cancellationToken)) { if (response.IsSuccessStatusCode) using (var input = await response.Content.ReadAsStreamAsync()) @@ -52,7 +52,7 @@ protected override async Task Handle(Command request, CancellationToken cancella } else _logger.LogError( - $"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}. {response.StatusCode}"); + $"Error downloading list {request.ListUrl.Id} from {request.ListUrl.ViewUrl}. {response.StatusCode}"); } } } diff --git a/src/FilterLists.Agent/Features/Lists/DownloadZip.cs b/src/FilterLists.Agent/Features/Lists/DownloadZip.cs index ea3087bcf..29956452e 100644 --- a/src/FilterLists.Agent/Features/Lists/DownloadZip.cs +++ b/src/FilterLists.Agent/Features/Lists/DownloadZip.cs @@ -3,7 +3,7 @@ using System.Threading; using System.Threading.Tasks; using FilterLists.Agent.Core; -using FilterLists.Agent.Core.ListInfo; +using FilterLists.Agent.Core.List; using MediatR; using Microsoft.Extensions.Logging; using SharpCompress.Common; @@ -15,12 +15,12 @@ public static class DownloadZip { public class Command : IRequest { - public Command(ListInfo listInfo) + public Command(ListUrl listUrl) { - ListInfo = listInfo; + ListUrl = listUrl; } - public ListInfo ListInfo { get; } + public ListUrl ListUrl { get; } } public class Handler : AsyncRequestHandler @@ -37,8 +37,8 @@ public Handler(IListRepository listRepository, ILogger logger) protected override async Task Handle(Command request, CancellationToken cancellationToken) { - var destinationDirectoryPath = Path.Combine(RepoDirectory, $"{request.ListInfo.Id}"); - using (var response = await _httpClient.GetAsync(request.ListInfo.ViewUrl, cancellationToken)) + var destinationDirectoryPath = Path.Combine(RepoDirectory, $"{request.ListUrl.Id}"); + using (var response = await _httpClient.GetAsync(request.ListUrl.ViewUrl, cancellationToken)) { if (response.IsSuccessStatusCode) using (var input = await response.Content.ReadAsStreamAsync()) @@ -51,7 +51,7 @@ protected override async Task Handle(Command request, CancellationToken cancella } else _logger.LogError( - $"Error downloading list {request.ListInfo.Id} from {request.ListInfo.ViewUrl}. {response.StatusCode}"); + $"Error downloading list {request.ListUrl.Id} from {request.ListUrl.ViewUrl}. {response.StatusCode}"); } } } diff --git a/src/FilterLists.Agent/Infrastructure/DependencyInjection/ServiceCollectionExtensions.cs b/src/FilterLists.Agent/Infrastructure/DependencyInjection/ServiceCollectionExtensions.cs index 170ac9f63..9c9534d48 100644 --- a/src/FilterLists.Agent/Infrastructure/DependencyInjection/ServiceCollectionExtensions.cs +++ b/src/FilterLists.Agent/Infrastructure/DependencyInjection/ServiceCollectionExtensions.cs @@ -4,6 +4,7 @@ using CommandLine; using FilterLists.Agent.AppSettings; using FilterLists.Agent.Core; +using FilterLists.Agent.Core.List; using FilterLists.Agent.Infrastructure.FilterListsApi; using FilterLists.Agent.Infrastructure.GitHub; using LibGit2Sharp; diff --git a/src/FilterLists.Agent/Infrastructure/FilterListsApi/ListInfoRepository.cs b/src/FilterLists.Agent/Infrastructure/FilterListsApi/ListUrlRepository.cs similarity index 59% rename from src/FilterLists.Agent/Infrastructure/FilterListsApi/ListInfoRepository.cs rename to src/FilterLists.Agent/Infrastructure/FilterListsApi/ListUrlRepository.cs index ce51c3bf1..fc82c7ec2 100644 --- a/src/FilterLists.Agent/Infrastructure/FilterListsApi/ListInfoRepository.cs +++ b/src/FilterLists.Agent/Infrastructure/FilterListsApi/ListUrlRepository.cs @@ -1,31 +1,31 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using FilterLists.Agent.Core.ListInfo; +using FilterLists.Agent.Core.List; using Microsoft.Extensions.Localization; using Microsoft.Extensions.Logging; using RestSharp; namespace FilterLists.Agent.Infrastructure.FilterListsApi { - public class ListInfoRepository : IListInfoRepository + public class ListUrlRepository : IListUrlRepository { private readonly IRestClient _apiClient; - private readonly IStringLocalizer _localizer; - private readonly ILogger _logger; + private readonly IStringLocalizer _localizer; + private readonly ILogger _logger; - public ListInfoRepository(IRestClient apiClient, IStringLocalizer stringLocalizer, - ILogger logger) + public ListUrlRepository(IRestClient apiClient, IStringLocalizer stringLocalizer, + ILogger logger) { _apiClient = apiClient; _localizer = stringLocalizer; _logger = logger; } - public async Task> GetAllAsync(CancellationToken cancellationToken) + public async Task> GetAllAsync(CancellationToken cancellationToken) { var listsRequest = new RestRequest("lists"); - var response = await _apiClient.ExecuteTaskAsync>(listsRequest, cancellationToken); + var response = await _apiClient.ExecuteTaskAsync>(listsRequest, cancellationToken); if (response.ErrorException != null) _logger.LogError(response.ErrorException, _localizer["Error retrieving response from the FilterLists API."]); diff --git a/src/FilterLists.Agent/Infrastructure/FilterListsApi/ServiceCollectionExtensions.cs b/src/FilterLists.Agent/Infrastructure/FilterListsApi/ServiceCollectionExtensions.cs index 916b16bc5..cf4a8ca9f 100644 --- a/src/FilterLists.Agent/Infrastructure/FilterListsApi/ServiceCollectionExtensions.cs +++ b/src/FilterLists.Agent/Infrastructure/FilterListsApi/ServiceCollectionExtensions.cs @@ -1,5 +1,5 @@ using FilterLists.Agent.AppSettings; -using FilterLists.Agent.Core.ListInfo; +using FilterLists.Agent.Core.List; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using RestSharp; @@ -15,7 +15,7 @@ public static void AddFilterListsApiResources(this IServiceCollection services) var filterListsApiSettings = b.GetService>().Value; return new RestClient(filterListsApiSettings.BaseUrl) {UserAgent = "FilterLists.Agent"}; }); - services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/src/FilterLists.Agent/Infrastructure/ListRepository.cs b/src/FilterLists.Agent/Infrastructure/ListRepository.cs index 3aed139c7..982542f00 100644 --- a/src/FilterLists.Agent/Infrastructure/ListRepository.cs +++ b/src/FilterLists.Agent/Infrastructure/ListRepository.cs @@ -2,6 +2,7 @@ using System.Net.Http; using System.Net.Http.Headers; using FilterLists.Agent.Core; +using FilterLists.Agent.Core.List; using JetBrains.Annotations; namespace FilterLists.Agent.Infrastructure