diff --git a/src/FilterLists.Agent/Core/Interfaces/Repositories/IListInfoRepository.cs b/src/FilterLists.Agent/Core/Interfaces/Repositories/IListInfoRepository.cs index e28dc61de..bc5dc3efc 100644 --- a/src/FilterLists.Agent/Core/Interfaces/Repositories/IListInfoRepository.cs +++ b/src/FilterLists.Agent/Core/Interfaces/Repositories/IListInfoRepository.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using FilterLists.Agent.Core.Entities; @@ -6,6 +7,6 @@ namespace FilterLists.Agent.Core.Interfaces.Repositories { public interface IListInfoRepository { - Task> GetAllAsync(); + Task> GetAllAsync(CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/src/FilterLists.Agent/Core/Interfaces/Repositories/IUrlRepository.cs b/src/FilterLists.Agent/Core/Interfaces/Repositories/IUrlRepository.cs index be20d8c4d..4ece488dd 100644 --- a/src/FilterLists.Agent/Core/Interfaces/Repositories/IUrlRepository.cs +++ b/src/FilterLists.Agent/Core/Interfaces/Repositories/IUrlRepository.cs @@ -8,7 +8,7 @@ namespace FilterLists.Agent.Core.Interfaces.Repositories { public interface IUrlRepository { - Task> GetAllAsync(); + Task> GetAllAsync(CancellationToken cancellationToken); Task ValidateAsync(Uri u, CancellationToken cancellationToken); } diff --git a/src/FilterLists.Agent/Features/Lists/ArchiveLists.cs b/src/FilterLists.Agent/Features/Lists/ArchiveLists.cs index 615ec40a4..1dc6228fa 100644 --- a/src/FilterLists.Agent/Features/Lists/ArchiveLists.cs +++ b/src/FilterLists.Agent/Features/Lists/ArchiveLists.cs @@ -24,7 +24,7 @@ public Handler(IMediator mediator, IListInfoRepository listInfoRepository) protected override async Task Handle(Command request, CancellationToken cancellationToken) { - var lists = await _repo.GetAllAsync(); + var lists = await _repo.GetAllAsync(cancellationToken); await _mediator.Send(new DownloadLists.Command(lists), cancellationToken); await _mediator.Send(new CommitLists.Command(), cancellationToken); } diff --git a/src/FilterLists.Agent/Features/Urls/ValidateAllUrls.cs b/src/FilterLists.Agent/Features/Urls/ValidateAllUrls.cs index 42cf42fbf..14e7dd564 100644 --- a/src/FilterLists.Agent/Features/Urls/ValidateAllUrls.cs +++ b/src/FilterLists.Agent/Features/Urls/ValidateAllUrls.cs @@ -30,28 +30,28 @@ protected override async Task Handle(Command request, CancellationToken cancella { var results = new List(); - var licenseUrls = await _repo.GetAllAsync(); + var licenseUrls = await _repo.GetAllAsync(cancellationToken); var licenseUrlErrors = await _mediator.Send(new ValidateUrls.Command(licenseUrls), cancellationToken); if (licenseUrlErrors.Any()) results.Add(new DataFileUrlValidationResults("License.json", licenseUrlErrors)); - var listUrls = await _repo.GetAllAsync(); + var listUrls = await _repo.GetAllAsync(cancellationToken); var listUrlErrors = await _mediator.Send(new ValidateUrls.Command(listUrls), cancellationToken); if (listUrlErrors.Any()) results.Add(new DataFileUrlValidationResults("FilterList.json", listUrlErrors)); - var maintainerUrls = await _repo.GetAllAsync(); + var maintainerUrls = await _repo.GetAllAsync(cancellationToken); var maintainerUrlErrors = await _mediator.Send(new ValidateUrls.Command(maintainerUrls), cancellationToken); if (maintainerUrlErrors.Any()) results.Add(new DataFileUrlValidationResults("Maintainer.json", maintainerUrlErrors)); - var softwareUrls = await _repo.GetAllAsync(); + var softwareUrls = await _repo.GetAllAsync(cancellationToken); var softwareUrlErrors = await _mediator.Send(new ValidateUrls.Command(softwareUrls), cancellationToken); if (softwareUrlErrors.Any()) results.Add(new DataFileUrlValidationResults("Software.json", softwareUrlErrors)); - var syntaxUrls = await _repo.GetAllAsync(); + var syntaxUrls = await _repo.GetAllAsync(cancellationToken); var syntaxUrlErrors = await _mediator.Send(new ValidateUrls.Command(syntaxUrls), cancellationToken); if (syntaxUrlErrors.Any()) results.Add(new DataFileUrlValidationResults("Syntax.json", syntaxUrlErrors)); diff --git a/src/FilterLists.Agent/Infrastructure/Clients/FilterListsApiClient.cs b/src/FilterLists.Agent/Infrastructure/Clients/FilterListsApiClient.cs index 3ed3f55ac..24ce11f7c 100644 --- a/src/FilterLists.Agent/Infrastructure/Clients/FilterListsApiClient.cs +++ b/src/FilterLists.Agent/Infrastructure/Clients/FilterListsApiClient.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using System.Threading.Tasks; using FilterLists.Agent.AppSettings; using Microsoft.Extensions.Localization; @@ -19,9 +20,9 @@ public FilterListsApiClient(IStringLocalizer stringLocaliz _restClient = new RestClient(filterListsApiOptions.Value.BaseUrl) {UserAgent = "FilterLists.Agent"}; } - public async Task ExecuteAsync(IRestRequest request) + public async Task ExecuteAsync(IRestRequest request, CancellationToken cancellationToken) { - var response = await _restClient.ExecuteTaskAsync(request); + var response = await _restClient.ExecuteTaskAsync(request, cancellationToken); if (response.ErrorException == null) return response.Data; throw new ApplicationException(_localizer["Error retrieving response from the FilterLists API."], diff --git a/src/FilterLists.Agent/Infrastructure/Clients/IFilterListsApiClient.cs b/src/FilterLists.Agent/Infrastructure/Clients/IFilterListsApiClient.cs index e87e41109..e9a94e70b 100644 --- a/src/FilterLists.Agent/Infrastructure/Clients/IFilterListsApiClient.cs +++ b/src/FilterLists.Agent/Infrastructure/Clients/IFilterListsApiClient.cs @@ -1,10 +1,11 @@ -using System.Threading.Tasks; +using System.Threading; +using System.Threading.Tasks; using RestSharp; namespace FilterLists.Agent.Infrastructure.Clients { public interface IFilterListsApiClient { - Task ExecuteAsync(IRestRequest request); + Task ExecuteAsync(IRestRequest request, CancellationToken cancellationToken); } } \ No newline at end of file diff --git a/src/FilterLists.Agent/Infrastructure/Repositories/ListInfoRepository.cs b/src/FilterLists.Agent/Infrastructure/Repositories/ListInfoRepository.cs index 53ad911eb..cfb42e28c 100644 --- a/src/FilterLists.Agent/Infrastructure/Repositories/ListInfoRepository.cs +++ b/src/FilterLists.Agent/Infrastructure/Repositories/ListInfoRepository.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using FilterLists.Agent.Core.Entities; using FilterLists.Agent.Core.Interfaces.Repositories; @@ -16,10 +17,10 @@ public ListInfoRepository(IFilterListsApiClient apiClient) _apiClient = apiClient; } - public async Task> GetAllAsync() + public async Task> GetAllAsync(CancellationToken cancellationToken) { var listsRequest = new RestRequest("lists"); - return await _apiClient.ExecuteAsync>(listsRequest); + return await _apiClient.ExecuteAsync>(listsRequest, cancellationToken); } } } \ No newline at end of file diff --git a/src/FilterLists.Agent/Infrastructure/Repositories/UrlRepository.cs b/src/FilterLists.Agent/Infrastructure/Repositories/UrlRepository.cs index 44d886f25..dca9ebcaa 100644 --- a/src/FilterLists.Agent/Infrastructure/Repositories/UrlRepository.cs +++ b/src/FilterLists.Agent/Infrastructure/Repositories/UrlRepository.cs @@ -50,17 +50,16 @@ public UrlRepository(IFilterListsApiClient apiClient, HttpClient httpClient, _logger = logger; } - public async Task> GetAllAsync() + public async Task> GetAllAsync(CancellationToken cancellationToken) { if (!EntityUrlsEndpoints.ContainsKey(typeof(TModel).Name)) throw new InvalidEnumArgumentException(_localizer["The type of TModel is not valid."]); var request = new RestRequest($"{EntityUrlsEndpoints[typeof(TModel).Name]}/seed"); - var response = await _apiClient.ExecuteAsync>(request); + var response = await _apiClient.ExecuteAsync>(request, cancellationToken); return response.SelectMany(r => r.GetType().GetProperties().Where(p => p.GetValue(r) != null).Select(p => (Uri)p.GetValue(r))); } - public async Task ValidateAsync(Uri u, CancellationToken cancellationToken) { var result = new UrlValidationResult(u);