Make CLI available when abp.io is offline

pull/3338/head
liangshiwei 5 years ago
parent 2a900fc8a8
commit 63b764da8d

@ -51,7 +51,8 @@ namespace Volo.Abp.Cli.ProjectBuilding
var latestVersion = await GetLatestSourceCodeVersionAsync(name, type);
if (version == null)
{
version = latestVersion;
version = latestVersion ?? throw new CliUsageException(
"The remote service is currently unavailable, please specify the version (like abp new Acme.BookStore -v 2.3.0(Make sure you have a template cache locally))!");
}
var nugetVersion = (await GetTemplateNugetVersionAsync(name, type, version)) ?? version;
@ -122,7 +123,7 @@ namespace Volo.Abp.Cli.ProjectBuilding
catch (Exception ex)
{
Console.WriteLine("Error occured while getting the latest version from {0} : {1}", url, ex.Message);
throw;
return null;
}
}

@ -1,4 +1,5 @@
using System.Net.Http;
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
@ -32,27 +33,37 @@ namespace Volo.Abp.Cli.ProjectBuilding.Analyticses
public async Task CollectAsync(CliAnalyticsCollectInputDto input)
{
var postData = _jsonSerializer.Serialize(input);
using (var client = new CliHttpClient())
var url = $"{CliUrls.WwwAbpIo}api/clianalytics/collect";
try
{
var responseMessage = await client.PostAsync(
$"{CliUrls.WwwAbpIo}api/clianalytics/collect",
new StringContent(postData, Encoding.UTF8, MimeTypes.Application.Json),
_cancellationTokenProvider.Token
);
if (!responseMessage.IsSuccessStatusCode)
using (var client = new CliHttpClient())
{
var exceptionMessage = "Remote server returns '" + (int)responseMessage.StatusCode + "-" + responseMessage.ReasonPhrase + "'. ";
var remoteServiceErrorMessage = await _remoteServiceExceptionHandler.GetAbpRemoteServiceErrorAsync(responseMessage);
var responseMessage = await client.PostAsync(
url,
new StringContent(postData, Encoding.UTF8, MimeTypes.Application.Json),
_cancellationTokenProvider.Token
);
if (remoteServiceErrorMessage != null)
if (!responseMessage.IsSuccessStatusCode)
{
exceptionMessage += remoteServiceErrorMessage;
}
var exceptionMessage = "Remote server returns '" + (int)responseMessage.StatusCode + "-" + responseMessage.ReasonPhrase + "'. ";
var remoteServiceErrorMessage = await _remoteServiceExceptionHandler.GetAbpRemoteServiceErrorAsync(responseMessage);
if (remoteServiceErrorMessage != null)
{
exceptionMessage += remoteServiceErrorMessage;
}
_logger.LogInformation(exceptionMessage);
_logger.LogInformation(exceptionMessage);
}
}
}
catch (Exception ex)
{
Console.WriteLine("Error occured while cli analytics from {0} : {1}", url, ex.Message);
}
}
}
}
Loading…
Cancel
Save