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; } }
private async Task <string> GetLatestSourceCodeVersionAsync(string name, string type) { using (var client = new CliHttpClient()) { var response = await client.PostAsync( $"{CliUrls.WwwAbpIo}api/download/{type}/get-version/", new StringContent( JsonSerializer.Serialize( new GetLatestSourceCodeVersionDto { Name = name } ), Encoding.UTF8, MimeTypes.Application.Json ), CancellationTokenProvider.Token ); await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response); var result = await response.Content.ReadAsStringAsync(); return(JsonSerializer.Deserialize <GetLatestSourceCodeVersionResultDto>(result).Version); } }
private async Task <string> GetTemplateNugetVersionAsync(string name, string type, string version) { var url = $"{CliUrls.WwwAbpIo}api/download/{type}/get-nuget-version/"; try { using (var client = new CliHttpClient(TimeSpan.FromMinutes(10))) { var response = await client.PostAsync( url, new StringContent( JsonSerializer.Serialize( new GetTemplateNugetVersionDto { Name = name, Version = version } ), Encoding.UTF8, MimeTypes.Application.Json ), CancellationTokenProvider.Token ); await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response); var result = await response.Content.ReadAsStringAsync(); return(JsonSerializer.Deserialize <GetVersionResultDto>(result).Version); } } catch (Exception ex) { Console.WriteLine("Error occured while getting the NuGet version from {0} : {1}", url, ex.Message); return(null); } }
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()); } }
public async Task CollectAsync(CliAnalyticsCollectInputDto input) { var postData = _jsonSerializer.Serialize(input); using (var client = new CliHttpClient()) { var responseMessage = await client.PostAsync( $"{CliUrls.WwwAbpIo}api/clianalytics/collect", new StringContent(postData, Encoding.UTF8, MimeTypes.Application.Json), _cancellationTokenProvider.Token ).ConfigureAwait(false); if (!responseMessage.IsSuccessStatusCode) { var exceptionMessage = "Remote server returns '" + (int)responseMessage.StatusCode + "-" + responseMessage.ReasonPhrase + "'. "; var remoteServiceErrorMessage = await _remoteServiceExceptionHandler.GetAbpRemoteServiceErrorAsync(responseMessage).ConfigureAwait(false); if (remoteServiceErrorMessage != null) { exceptionMessage += remoteServiceErrorMessage; } _logger.LogInformation(exceptionMessage); } } }
public async Task CollectAsync(CliAnalyticsCollectInputDto input) { var postData = _jsonSerializer.Serialize(input); using (var client = new CliHttpClient()) { var responseMessage = await client.PostAsync( $"{CliUrls.WwwAbpIo}api/clianalytics/collect", new StringContent(postData, Encoding.UTF8, MimeTypes.Application.Json), _cancellationTokenProvider.Token ); if (!responseMessage.IsSuccessStatusCode) { _logger.LogInformation("Remote server returns error! HTTP status code: " + responseMessage.StatusCode); } } }
private async Task <byte[]> DownloadTemplateFileContentAsync(TemplateDownloadInputDto input) { var postData = JsonSerializer.Serialize(input); using (var client = new CliHttpClient()) { var responseMessage = await client.PostAsync( $"{CliUrls.WwwAbpIo}api/download/template/", new StringContent(postData, Encoding.UTF8, MimeTypes.Application.Json), CancellationTokenProvider.Token ); if (!responseMessage.IsSuccessStatusCode) { throw new Exception("Remote server returns error! HTTP status code: " + responseMessage.StatusCode); } return(await responseMessage.Content.ReadAsByteArrayAsync()); } }
private async Task <string> GetLatestTemplateVersionAsync(string name) { var postData = JsonSerializer.Serialize(new GetLatestTemplateVersionDto { Name = name }); using (var client = new CliHttpClient()) { var responseMessage = await client.PostAsync( $"{CliUrls.WwwAbpIo}api/download/template/get-version/", new StringContent(postData, Encoding.UTF8, MimeTypes.Application.Json), CancellationTokenProvider.Token ); if (!responseMessage.IsSuccessStatusCode) { throw new Exception("Remote server returns error! HTTP status code: " + responseMessage.StatusCode); } var result = await responseMessage.Content.ReadAsStringAsync(); return(JsonSerializer.Deserialize <GetLatestTemplateVersionResultDto>(result).Version); } }