mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
resolve some CA1303 warnings by adding localization defaults
This commit is contained in:
parent
97b86eea2b
commit
ac3ed5eac4
6 changed files with 22 additions and 11 deletions
|
|
@ -185,4 +185,5 @@
|
|||
<s:Boolean x:Key="/Default/CodeStyle/Naming/CSharpNaming/ApplyAutoDetectedRules/@EntryValue">False</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=appsettings/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=downloader/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=Localizer/@EntryIndexedValue">True</s:Boolean>
|
||||
</wpf:ResourceDictionary>
|
||||
|
|
@ -19,6 +19,7 @@ public static class ServiceCollectionExtensions
|
|||
public static void RegisterAgentServices(this IServiceCollection services)
|
||||
{
|
||||
services.AddConfiguration();
|
||||
services.AddLocalization();
|
||||
services.AddLoggingCustom();
|
||||
services.AddTransient<Parser>();
|
||||
services.AddMediatR(AppDomain.CurrentDomain.GetAssemblies());
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Localization" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="2.2.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.10.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.2.0" />
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Agent.AppSettings;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using Octokit;
|
||||
|
|
@ -18,15 +19,17 @@ public interface IAgentGitHubClient
|
|||
|
||||
public class AgentGitHubClient : IAgentGitHubClient
|
||||
{
|
||||
private const string ExceptionMessageSuffix = " from the GitHub API.";
|
||||
private readonly GitHubClient _gitHubClient;
|
||||
private readonly GitHubSettings _gitHubSettings;
|
||||
private readonly IStringLocalizer<AgentGitHubClient> _localizer;
|
||||
private readonly ILogger<AgentGitHubClient> _logger;
|
||||
|
||||
public AgentGitHubClient(IOptions<GitHubSettings> gitHubOptions, ILogger<AgentGitHubClient> logger)
|
||||
public AgentGitHubClient(IOptions<GitHubSettings> gitHubOptions, ILogger<AgentGitHubClient> logger,
|
||||
IStringLocalizer<AgentGitHubClient> stringLocalizer)
|
||||
{
|
||||
_gitHubSettings = gitHubOptions.Value;
|
||||
_logger = logger;
|
||||
_localizer = stringLocalizer;
|
||||
_gitHubClient = new GitHubClient(new ProductHeaderValue(_gitHubSettings.ProductHeaderValue))
|
||||
{
|
||||
Credentials = new Credentials(_gitHubSettings.PersonalAccessToken)
|
||||
|
|
@ -42,7 +45,7 @@ public async Task<IReadOnlyList<Issue>> GetAllIssues(RepositoryIssueRequest repo
|
|||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Failed getting all Issues{ExceptionMessageSuffix}");
|
||||
_logger.LogError(ex, _localizer["Failed getting all Issues from the GitHub API."]);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,7 +59,7 @@ public async Task<Issue> CreateIssue(NewIssue newIssue)
|
|||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Failed creating Issue{ExceptionMessageSuffix}");
|
||||
_logger.LogError(ex, _localizer["Failed creating Issue with the GitHub API."]);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
@ -70,7 +73,7 @@ public async Task<Issue> UpdateIssue(int issueNumber, IssueUpdate issueUpdate)
|
|||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
_logger.LogError(ex, $"Failed updating Issue{ExceptionMessageSuffix}");
|
||||
_logger.LogError(ex, _localizer["Failed updating Issue with the GitHub API."]);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using RestSharp;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.Clients
|
||||
|
|
@ -12,11 +13,12 @@ public interface IFilterListsApiClient
|
|||
public class FilterListsApiClient : IFilterListsApiClient
|
||||
{
|
||||
private const string FilterListsApiBaseUrl = "https://filterlists.com/api/v1";
|
||||
private const string ExceptionMessage = "Error retrieving response from the FilterLists API.";
|
||||
private readonly IStringLocalizer<FilterListsApiClient> _localizer;
|
||||
private readonly IRestClient _restClient;
|
||||
|
||||
public FilterListsApiClient()
|
||||
public FilterListsApiClient(IStringLocalizer<FilterListsApiClient> stringLocalizer)
|
||||
{
|
||||
_localizer = stringLocalizer;
|
||||
_restClient = new RestClient(FilterListsApiBaseUrl) {UserAgent = "FilterLists.Agent"};
|
||||
}
|
||||
|
||||
|
|
@ -25,7 +27,8 @@ public async Task<TResponse> ExecuteAsync<TResponse>(IRestRequest request)
|
|||
var response = await _restClient.ExecuteTaskAsync<TResponse>(request);
|
||||
if (response.ErrorException == null)
|
||||
return response.Data;
|
||||
throw new ApplicationException(ExceptionMessage, response.ErrorException);
|
||||
throw new ApplicationException(_localizer["Error retrieving response from the FilterLists API."],
|
||||
response.ErrorException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
using FilterLists.Agent.Core.Interfaces;
|
||||
using FilterLists.Agent.Features.Urls.Models.DataFileUrls;
|
||||
using FilterLists.Agent.Infrastructure.Clients;
|
||||
using Microsoft.Extensions.Localization;
|
||||
using RestSharp;
|
||||
|
||||
namespace FilterLists.Agent.Infrastructure.Repositories
|
||||
|
|
@ -22,17 +23,18 @@ public class UrlRepository : IUrlRepository
|
|||
};
|
||||
|
||||
private readonly IFilterListsApiClient _apiClient;
|
||||
private readonly IStringLocalizer<UrlRepository> _localizer;
|
||||
|
||||
public UrlRepository(IFilterListsApiClient apiClient)
|
||||
public UrlRepository(IFilterListsApiClient apiClient, IStringLocalizer<UrlRepository> stringLocalizer)
|
||||
{
|
||||
_apiClient = apiClient;
|
||||
_localizer = stringLocalizer;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Uri>> GetAllAsync<TModel>()
|
||||
{
|
||||
if (!EntityUrlsEndpoints.ContainsKey(typeof(TModel).Name))
|
||||
throw new InvalidEnumArgumentException("The type of TModel is not valid.");
|
||||
|
||||
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<IEnumerable<TModel>>(request);
|
||||
return response.SelectMany(r =>
|
||||
|
|
|
|||
Loading…
Reference in a new issue