Exemplo n.º 1
0
        private async Task <byte[]> DownloadSourceCodeContentAsync(SourceCodeDownloadInputDto input)
        {
            var url = $"{CliUrls.WwwRocketIo}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;
            }
        }
Exemplo n.º 2
0
        private async Task <string> GetTemplateNugetVersionAsync(string name, string type, string version)
        {
            var url = $"{CliUrls.WwwRocketIo}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 template nuget version from {0} : {1}", url, ex.Message);
                return(null);
            }
        }