Browse Source

add Poly to Abp.Cli.Core and use it GetApiKeyOrNullAsync method.

pull/2457/head
Alper Ebicoglu 7 years ago
parent
commit
f0e275a0c8
  1. 2
      framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj
  2. 16
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs
  3. 40
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs

2
framework/src/Volo.Abp.Cli.Core/Volo.Abp.Cli.Core.csproj

@ -19,6 +19,8 @@
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.0" /> <PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.0" />
<PackageReference Include="System.Security.Permissions" Version="4.6.0" /> <PackageReference Include="System.Security.Permissions" Version="4.6.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" /> <PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.1" />
<PackageReference Include="Polly" Version="7.2.0" />
<PackageReference Include="Polly.Extensions.Http" Version="3.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

16
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs

@ -60,6 +60,12 @@ namespace Volo.Abp.Cli.Commands
private async Task InstallSuiteAsync() private async Task InstallSuiteAsync()
{ {
var nugetIndexUrl = await GetNuGetIndexUrlAsync(); var nugetIndexUrl = await GetNuGetIndexUrlAsync();
if (nugetIndexUrl == null)
{
return;
}
var result = CmdHelper.RunCmd("dotnet tool install " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g"); var result = CmdHelper.RunCmd("dotnet tool install " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g");
if (result == 0) if (result == 0)
@ -72,6 +78,12 @@ namespace Volo.Abp.Cli.Commands
private async Task UpdateSuiteAsync() private async Task UpdateSuiteAsync()
{ {
var nugetIndexUrl = await GetNuGetIndexUrlAsync(); var nugetIndexUrl = await GetNuGetIndexUrlAsync();
if (nugetIndexUrl == null)
{
return;
}
CmdHelper.RunCmd("dotnet tool update " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g"); CmdHelper.RunCmd("dotnet tool update " + SuitePackageName + " --add-source " + nugetIndexUrl + " -g");
} }
@ -101,8 +113,8 @@ namespace Volo.Abp.Cli.Commands
private async Task<string> GetNuGetIndexUrlAsync() private async Task<string> GetNuGetIndexUrlAsync()
{ {
var apiKeyResult = await _apiKeyService.GetApiKeyOrNullAsync(); var apiKeyResult = await _apiKeyService.GetApiKeyOrNullAsync();
if (apiKeyResult == null ||
string.IsNullOrEmpty(apiKeyResult.ApiKey)) if (apiKeyResult == null || string.IsNullOrEmpty(apiKeyResult.ApiKey))
{ {
Logger.LogError("Couldn't retrieve your NuGet API key!"); Logger.LogError("Couldn't retrieve your NuGet API key!");
Logger.LogWarning(File.Exists(CliPaths.AccessToken) Logger.LogWarning(File.Exists(CliPaths.AccessToken)

40
framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Licensing/AbpIoApiKeyService.cs

@ -1,5 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Polly;
using Polly.Extensions.Http;
using Volo.Abp.Cli.Http; using Volo.Abp.Cli.Http;
using Volo.Abp.Cli.ProjectBuilding; using Volo.Abp.Cli.ProjectBuilding;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -10,22 +17,45 @@ namespace Volo.Abp.Cli.Licensing
public class AbpIoApiKeyService : IApiKeyService, ITransientDependency public class AbpIoApiKeyService : IApiKeyService, ITransientDependency
{ {
protected IJsonSerializer JsonSerializer { get; } protected IJsonSerializer JsonSerializer { get; }
protected IRemoteServiceExceptionHandler RemoteServiceExceptionHandler { get; } protected IRemoteServiceExceptionHandler RemoteServiceExceptionHandler { get; }
private readonly ILogger<AbpIoApiKeyService> _logger;
public AbpIoApiKeyService(IJsonSerializer jsonSerializer, IRemoteServiceExceptionHandler remoteServiceExceptionHandler) public AbpIoApiKeyService(IJsonSerializer jsonSerializer, IRemoteServiceExceptionHandler remoteServiceExceptionHandler, ILogger<AbpIoApiKeyService> logger)
{ {
JsonSerializer = jsonSerializer; JsonSerializer = jsonSerializer;
RemoteServiceExceptionHandler = remoteServiceExceptionHandler; RemoteServiceExceptionHandler = remoteServiceExceptionHandler;
_logger = logger;
} }
public async Task<DeveloperApiKeyResult> GetApiKeyOrNullAsync() public async Task<DeveloperApiKeyResult> GetApiKeyOrNullAsync()
{ {
using (var client = new CliHttpClient()) using (var client = new CliHttpClient())
{ {
var url = $"{CliUrls.WwwAbpIo}api/license/api-key"; var response = await HttpPolicyExtensions
.HandleTransientHttpError()
var response = await client.GetAsync(url); .OrResult(msg => !msg.IsSuccessStatusCode)
.WaitAndRetryAsync(new[]
{
TimeSpan.FromSeconds(1),
TimeSpan.FromSeconds(3),
TimeSpan.FromSeconds(7)
},
(responseMessage, timeSpan, retryCount, context) =>
{
if (responseMessage.Exception != null)
{
_logger.LogWarning(
$"{retryCount}. request attempt failed with an error: \"{responseMessage.Exception.Message}\". " +
$"Waiting {timeSpan.TotalSeconds} secs for the next try...");
}
else if (responseMessage.Result != null)
{
_logger.LogWarning(
$"{retryCount}. request attempt failed with {responseMessage.Result.StatusCode}-{responseMessage.Result.ReasonPhrase}. " +
$"Waiting {timeSpan.TotalSeconds} secs for the next try...");
}
})
.ExecuteAsync(async () => await client.GetAsync($"{CliUrls.WwwAbpIo}api/license/api-key"));
if (!response.IsSuccessStatusCode) if (!response.IsSuccessStatusCode)
{ {

Loading…
Cancel
Save