From 4391b4a852ef4a7744c9aa7d5f5392f2db31fe53 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 24 Feb 2020 11:07:46 +0300 Subject: [PATCH] refactor --- .../Services/AbpNuGetIndexUrlService.cs | 48 +++++++++++++++++++ .../Volo/Abp/Cli/Commands/SuiteCommand.cs | 38 +++------------ 2 files changed, 54 insertions(+), 32 deletions(-) create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/AbpNuGetIndexUrlService.cs diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/AbpNuGetIndexUrlService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/AbpNuGetIndexUrlService.cs new file mode 100644 index 0000000000..0e1f987d4e --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/Services/AbpNuGetIndexUrlService.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; +using Volo.Abp.Cli.Licensing; +using Volo.Abp.DependencyInjection; + +namespace Volo.Abp.Cli.Commands.Services +{ + public class AbpNuGetIndexUrlService : ITransientDependency + { + private readonly IApiKeyService _apiKeyService; + public ILogger Logger { get; set; } + + public AbpNuGetIndexUrlService(IApiKeyService apiKeyService) + { + _apiKeyService = apiKeyService; + Logger = NullLogger.Instance; + } + + public async Task GetAsync() + { + var apiKeyResult = await _apiKeyService.GetApiKeyOrNullAsync(); + + if (apiKeyResult == null) + { + Logger.LogWarning("You are not signed in! Use the CLI command \"abp login \" to sign in, then try again."); + return null; + } + + if (!string.IsNullOrWhiteSpace(apiKeyResult.ErrorMessage)) + { + Logger.LogWarning(apiKeyResult.ErrorMessage); + return null; + } + + if (string.IsNullOrEmpty(apiKeyResult.ApiKey)) + { + Logger.LogError("Couldn't retrieve your NuGet API key! You can re-sign in with the CLI command \"abp login \"."); + return null; + } + + return CliUrls.GetNuGetServiceIndexUrl(apiKeyResult.ApiKey); + } + } +} diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs index a13621ea22..b4a4ff8bdd 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/SuiteCommand.cs @@ -1,11 +1,10 @@ using System; -using System.IO; using System.Text; using System.Threading.Tasks; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Args; -using Volo.Abp.Cli.Licensing; +using Volo.Abp.Cli.Commands.Services; using Volo.Abp.Cli.Utils; using Volo.Abp.DependencyInjection; @@ -13,13 +12,13 @@ namespace Volo.Abp.Cli.Commands { public class SuiteCommand : IConsoleCommand, ITransientDependency { + private readonly AbpNuGetIndexUrlService _nuGetIndexUrlService; private const string SuitePackageName = "Volo.Abp.Suite"; public ILogger Logger { get; set; } - private readonly IApiKeyService _apiKeyService; - public SuiteCommand(IApiKeyService apiKeyService) + public SuiteCommand(AbpNuGetIndexUrlService nuGetIndexUrlService) { - _apiKeyService = apiKeyService; + _nuGetIndexUrlService = nuGetIndexUrlService; Logger = NullLogger.Instance; } @@ -53,7 +52,7 @@ namespace Volo.Abp.Cli.Commands private async Task InstallSuiteAsync() { - var nugetIndexUrl = await GetNuGetIndexUrlAsync(); + var nugetIndexUrl = await _nuGetIndexUrlService.GetAsync(); if (nugetIndexUrl == null) { @@ -71,7 +70,7 @@ namespace Volo.Abp.Cli.Commands private async Task UpdateSuiteAsync() { - var nugetIndexUrl = await GetNuGetIndexUrlAsync(); + var nugetIndexUrl = await _nuGetIndexUrlService.GetAsync(); if (nugetIndexUrl == null) { @@ -104,31 +103,6 @@ namespace Volo.Abp.Cli.Commands CmdHelper.RunCmd("abp-suite"); } - private async Task GetNuGetIndexUrlAsync() - { - var apiKeyResult = await _apiKeyService.GetApiKeyOrNullAsync(); - - if (apiKeyResult == null) - { - Logger.LogWarning("You are not signed in! Use the CLI command \"abp login \" to sign in, then try again."); - return null; - } - - if (!string.IsNullOrWhiteSpace(apiKeyResult.ErrorMessage)) - { - Logger.LogWarning(apiKeyResult.ErrorMessage); - return null; - } - - if (string.IsNullOrEmpty(apiKeyResult.ApiKey)) - { - Logger.LogError("Couldn't retrieve your NuGet API key! You can re-sign in with the CLI command \"abp login \"."); - return null; - } - - return CliUrls.GetNuGetServiceIndexUrl(apiKeyResult.ApiKey); - } - public string GetUsageInfo() { var sb = new StringBuilder();