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 <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 <byte[]> DownloadSourceCodeContentAsync(SourceCodeDownloadInputDto input) { var url = $"{CliUrls.WwwAbpIo}api/download/{input.Type}/"; HttpResponseMessage responseMessage = null; try { var client = _cliHttpClientFactory.CreateClient(timeout: TimeSpan.FromMinutes(5)); if (input.TemplateSource.IsNullOrWhiteSpace()) { responseMessage = await client.PostAsync( url, new StringContent(JsonSerializer.Serialize(input), Encoding.UTF8, MimeTypes.Application.Json), _cliHttpClientFactory.GetCancellationToken(TimeSpan.FromMinutes(10)) ); } else { responseMessage = await client.GetAsync(input.TemplateSource, _cliHttpClientFactory.GetCancellationToken()); } await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(responseMessage); var resultAsBytes = await responseMessage.Content.ReadAsByteArrayAsync(); responseMessage.Dispose(); return(resultAsBytes); } catch (Exception ex) { Console.WriteLine("Error occured while downloading source-code from {0} : {1}{2}{3}", url, responseMessage?.ToString(), Environment.NewLine, ex.Message); throw; } }