Esempio n. 1
0
        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> GetTemplateNugetVersionAsync(string name, string type, string version)
        {
            if (type != SourceCodeTypes.Template)
            {
                return(null);
            }

            try
            {
                var url    = $"{CliUrls.WwwAbpIo}api/download/{type}/get-nuget-version/";
                var client = _cliHttpClientFactory.CreateClient();

                var stringContent = new StringContent(
                    JsonSerializer.Serialize(new GetTemplateNugetVersionDto {
                    Name = name, Version = version
                }),
                    Encoding.UTF8,
                    MimeTypes.Application.Json
                    );

                using (var response = await client.PostAsync(url, stringContent, _cliHttpClientFactory.GetCancellationToken(TimeSpan.FromMinutes(10))))
                {
                    await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);

                    var result = await response.Content.ReadAsStringAsync();

                    return(JsonSerializer.Deserialize <GetVersionResultDto>(result).Version);
                }
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 3
0
        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 <string> GetLatestSourceCodeVersionAsync(string name, string type, string url = null, bool includePreReleases = false)
        {
            if (url == null)
            {
                url = $"{CliUrls.WwwAbpIo}api/download/{type}/get-version/";
            }

            try
            {
                var client        = _cliHttpClientFactory.CreateClient();
                var stringContent = new StringContent(
                    JsonSerializer.Serialize(new GetLatestSourceCodeVersionDto {
                    Name = name, IncludePreReleases = includePreReleases
                }),
                    Encoding.UTF8,
                    MimeTypes.Application.Json
                    );

                using (var response = await client.PostAsync(url, stringContent, _cliHttpClientFactory.GetCancellationToken(TimeSpan.FromMinutes(10))))
                {
                    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 latest version from {0} : {1}", url, ex.Message);
                return(null);
            }
        }
Esempio n. 5
0
        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);
            }
        }
Esempio n. 6
0
        private async Task <bool> CheckProLicenseAsync()
        {
            if (!AuthService.IsLoggedIn())
            {
                return(false);
            }

            try
            {
                var url = $"{CliUrls.WwwAbpIo}api/license/check-user";

                using (var client = new CliHttpClient())
                {
                    using (var response = await client.GetHttpResponseMessageWithRetryAsync(url, CancellationTokenProvider.Token, Logger))
                    {
                        if (!response.IsSuccessStatusCode)
                        {
                            throw new Exception($"ERROR: Remote server returns '{response.StatusCode}'");
                        }

                        await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);

                        var responseContent = await response.Content.ReadAsStringAsync();

                        return(JsonSerializer.Deserialize <bool>(responseContent));
                    }
                }
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 7
0
        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());
            }
        }
Esempio n. 8
0
        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;
            }
        }