public async Task <SemanticVersion> GetLatestVersionOrNullAsync(string packageId, bool includePreviews = false, bool includeNightly = false) { using (var client = new CliHttpClient()) { var url = includeNightly ? $"https://www.myget.org/F/abp-nightly/api/v3/flatcontainer/{packageId.ToLowerInvariant()}/index.json" : $"https://api.nuget.org/v3-flatcontainer/{packageId.ToLowerInvariant()}/index.json"; var responseMessage = await client.GetAsync(url, CancellationTokenProvider.Token); if (!responseMessage.IsSuccessStatusCode) { throw new Exception("Remote server returns error! HTTP status code: " + responseMessage.StatusCode); } var result = await responseMessage.Content.ReadAsStringAsync(); var versions = JsonSerializer.Deserialize <NuGetVersionResultDto>(result).Versions.Select(x => SemanticVersion.Parse(x)); if (!includePreviews && !includeNightly) { versions = versions.Where(x => !x.IsPrerelease); } return(versions.Any() ? versions.Max() : null); } }
private async Task <byte[]> DownloadSourceCodeContentAsync(SourceCodeDownloadInputDto input) { var url = $"{CliUrls.WwwAbpIo}api/download/{input.Type}/"; try { using (var client = new CliHttpClient(TimeSpan.FromMinutes(10))) { HttpResponseMessage responseMessage; if (input.TemplateSource.IsNullOrWhiteSpace()) { responseMessage = await client.PostAsync( url, new StringContent(JsonSerializer.Serialize(input), Encoding.UTF8, MimeTypes.Application.Json), CancellationTokenProvider.Token ); } else { responseMessage = await client.GetAsync(input.TemplateSource, CancellationTokenProvider.Token); } await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(responseMessage); return(await responseMessage.Content.ReadAsByteArrayAsync()); } } catch (Exception ex) { Console.WriteLine("Error occured while downloading source-code from {0} : {1}", url, ex.Message); throw; } }
public async Task <MyGetApiResponse> GetPackages() { if (_response != null) { return(_response); } try { using (var client = new CliHttpClient(TimeSpan.FromMinutes(10))) { var responseMessage = await client.GetAsync( $"{CliUrls.WwwAbpIo}api/myget/packages/" ); _response = JsonConvert.DeserializeObject <MyGetApiResponse>(Encoding.Default.GetString(await responseMessage.Content.ReadAsByteArrayAsync())); } } catch (Exception) { Logger.LogError("Unable to get latest preview version."); throw; } return(_response); }
protected virtual async Task <ModuleWithMastersInfo> GetModuleInfoAsync(string moduleName, bool newTemplate, bool newProTemplate = false) { if (newTemplate || newProTemplate) { return(await GetEmptyModuleProjectInfoAsync(moduleName, newProTemplate)); } using (var client = new CliHttpClient()) { var url = $"{CliUrls.WwwAbpIo}api/app/module/byNameWithDetails/?name=" + moduleName; var response = await client.GetAsync(url); if (!response.IsSuccessStatusCode) { if (response.StatusCode == HttpStatusCode.NotFound) { throw new CliUsageException($"ERROR: '{moduleName}' module could not be found!"); } await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response); } var responseContent = await response.Content.ReadAsStringAsync(); return(JsonSerializer.Deserialize <ModuleWithMastersInfo>(responseContent)); } }
private async Task <byte[]> DownloadSourceCodeContentAsync(SourceCodeDownloadInputDto input) { var postData = JsonSerializer.Serialize(input); using (var client = new CliHttpClient(TimeSpan.FromMinutes(10))) { HttpResponseMessage responseMessage; if (input.TemplateSource.IsNullOrWhiteSpace()) { responseMessage = await client.PostAsync( $"{CliUrls.WwwAbpIo}api/download/{input.Type}/", new StringContent(postData, Encoding.UTF8, MimeTypes.Application.Json), CancellationTokenProvider.Token ); } else { responseMessage = await client.GetAsync(input.TemplateSource, CancellationTokenProvider.Token); } await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(responseMessage); return(await responseMessage.Content.ReadAsByteArrayAsync()); } }
private async Task <List <ModuleInfo> > GetModuleListAsync() { using (var client = new CliHttpClient()) { var responseMessage = await client.GetAsync( $"{CliUrls.WwwAbpIo}api/download/modules/", CancellationTokenProvider.Token ).ConfigureAwait(false); await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(responseMessage).ConfigureAwait(false); var result = await responseMessage.Content.ReadAsStringAsync().ConfigureAwait(false); return(JsonSerializer.Deserialize <List <ModuleInfo> >(result)); } }
public async Task <string> GetApiKeyAsync() { try { using (var client = new CliHttpClient(TimeSpan.FromMinutes(1))) { var responseMessage = await client.GetAsync( $"{CliUrls.WwwAbpIo}api/myget/apikey/" ); return(Encoding.Default.GetString(await responseMessage.Content.ReadAsByteArrayAsync())); } } catch (Exception) { return(""); } }
public async Task <DeveloperApiKeyResult> GetApiKeyOrNullAsync() { using (var client = new CliHttpClient()) { var url = $"{CliUrls.WwwAbpIo}api/license/api-key"; var response = await client.GetAsync(url); if (!response.IsSuccessStatusCode) { throw new Exception($"ERROR: Remote server returns '{response.StatusCode}'"); } var responseContent = await response.Content.ReadAsStringAsync(); return(JsonSerializer.Deserialize <DeveloperApiKeyResult>(responseContent)); } }
protected virtual async Task <ModuleInfo> FindModuleInfoAsync(string moduleName) { using (var client = new CliHttpClient()) { var url = $"{CliUrls.WwwAbpIo}api/app/module/byName/?name=" + moduleName; var response = await client.GetAsync(url).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { if (response.StatusCode == HttpStatusCode.NotFound) { throw new CliUsageException($"ERROR: '{moduleName}' module could not be found!"); } await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response).ConfigureAwait(false); } var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); return(JsonSerializer.Deserialize <ModuleInfo>(responseContent)); } }
protected virtual async Task <NugetPackageInfo> FindNugetPackageInfoAsync(string packageName) { using (var client = new CliHttpClient()) { var url = $"{CliUrls.WwwAbpIo}api/app/nugetPackage/byName/?name=" + packageName; var response = await client.GetAsync(url); if (!response.IsSuccessStatusCode) { if (response.StatusCode == HttpStatusCode.NotFound) { throw new CliUsageException($"'{packageName}' nuget package could not be found!"); } await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response); } var responseContent = await response.Content.ReadAsStringAsync(); return(JsonSerializer.Deserialize <NugetPackageInfo>(responseContent)); } }
private async Task <List <string> > GetProPackageListAsync() { using var client = new CliHttpClient(); var responseMessage = await client.GetAsync( $"{CliUrls.WwwAbpIo}api/app/nugetPackage/proPackageNames", CancellationTokenProvider.Token ); if (!responseMessage.IsSuccessStatusCode) { var exceptionMessage = "Remote server returns '" + (int)responseMessage.StatusCode + "-" + responseMessage.ReasonPhrase + "'. "; var remoteServiceErrorMessage = await RemoteServiceExceptionHandler.GetAbpRemoteServiceErrorAsync(responseMessage); if (remoteServiceErrorMessage != null) { exceptionMessage += remoteServiceErrorMessage; } Logger.LogInformation(exceptionMessage); return(null); } return(JsonSerializer.Deserialize <List <string> >(await responseMessage.Content.ReadAsStringAsync())); }
public async Task <DeveloperApiKeyResult> GetApiKeyOrNullAsync(bool invalidateCache = false) { if (invalidateCache) { _apiKeyResult = null; } if (_apiKeyResult != null) { return(_apiKeyResult); } var url = $"{CliUrls.WwwAbpIo}api/license/api-key"; using (var client = new CliHttpClient()) { var response = await HttpPolicyExtensions .HandleTransientHttpError() .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 to {url} 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 {url} with {(int)responseMessage.Result.StatusCode}-{responseMessage.Result.ReasonPhrase}. " + $"Waiting {timeSpan.TotalSeconds} secs for the next try..."); } }) .ExecuteAsync(async() => await client.GetAsync(url).ConfigureAwait(false)).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { throw new Exception($"ERROR: Remote server returns '{response.StatusCode}'"); } await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response).ConfigureAwait(false); var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var apiKeyResult = JsonSerializer.Deserialize <DeveloperApiKeyResult>(responseContent); if (apiKeyResult == null || string.IsNullOrEmpty(apiKeyResult.ApiKey)) { _logger.LogError("Couldn't retrieve your NuGet API key!"); _logger.LogWarning(File.Exists(CliPaths.AccessToken) ? "Make sure you have an active session and license on commercial.abp.io. To re-sign in you can use the CLI command \"abp login <username>\"." : "You are not signed in to commercial.abp.io. Use the CLI command \"abp login <username>\" to sign in."); return(null); } return(apiKeyResult); } }
public async Task <DeveloperApiKeyResult> GetApiKeyOrNullAsync(bool invalidateCache = false) { if (!AuthService.IsLoggedIn()) { return(null); } if (invalidateCache) { _apiKeyResult = null; } if (_apiKeyResult != null) { return(_apiKeyResult); } var url = $"{CliUrls.WwwAbpIo}api/license/api-key"; using (var client = new CliHttpClient()) { var response = await HttpPolicyExtensions .HandleTransientHttpError() .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 to {url} 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 {url} with {(int)responseMessage.Result.StatusCode}-{responseMessage.Result.ReasonPhrase}. " + $"Waiting {timeSpan.TotalSeconds} secs for the next try..."); } }) .ExecuteAsync(async() => await client.GetAsync(url).ConfigureAwait(false)).ConfigureAwait(false); if (!response.IsSuccessStatusCode) { throw new Exception($"ERROR: Remote server returns '{response.StatusCode}'"); } await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response).ConfigureAwait(false); var responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(false); var apiKeyResult = JsonSerializer.Deserialize <DeveloperApiKeyResult>(responseContent); return(apiKeyResult); } }