Esempio n. 1
0
    private async Task<bool> CheckProLicenseAsync()
    {
        if (!AuthService.IsLoggedIn())
        {
            return false;
        }

        try
        {
            var url = $"{CliUrls.WwwAbpIo}api/license/check-user";
            var client = _cliHttpClientFactory.CreateClient();

            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. 2
0
    public async Task <LoginInfo> GetLoginInfoAsync()
    {
        if (!IsLoggedIn())
        {
            return(null);
        }

        var url = $"{CliUrls.WwwAbpIo}api/license/login-info";

        var client = CliHttpClientFactory.CreateClient();

        using (var response = await client.GetHttpResponseMessageWithRetryAsync(url, CancellationTokenProvider.Token, Logger))
        {
            if (!response.IsSuccessStatusCode)
            {
                Logger.LogError("Remote server returns '{response.StatusCode}'");
                return(null);
            }

            await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);

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

            return(JsonSerializer.Deserialize <LoginInfo>(responseContent));
        }
    }
Esempio n. 3
0
        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));
            }
        }
Esempio n. 4
0
    private async Task <bool> IsVersionExists(string version)
    {
        var url = $"{CliUrls.WwwAbpIo}api/download/versions?includePreReleases=true";

        try
        {
            var client = _cliHttpClientFactory.CreateClient();

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

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

                var versions = JsonSerializer.Deserialize <List <GithubRelease> >(result);

                return(versions.Any(v => v.Name == version));
            }
        }
        catch (Exception ex)
        {
            throw new Exception($"Error occured while getting the versions from {url} : {ex.Message}");
        }
    }
Esempio n. 5
0
    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. 6
0
    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";
        var client = _cliHttpClientFactory.CreateClient();

        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 <DeveloperApiKeyResult>(responseContent));
        }
    }
Esempio n. 7
0
 public AuthService(
     IIdentityModelAuthenticationService authenticationService,
     ILogger <AuthService> logger,
     ICancellationTokenProvider cancellationTokenProvider,
     CliHttpClientFactory cliHttpClientFactory,
     RemoteServiceExceptionHandler remoteServiceExceptionHandler,
     IJsonSerializer jsonSerializer
     )
 {
     AuthenticationService = authenticationService;
     Logger = logger;
     CancellationTokenProvider     = cancellationTokenProvider;
     CliHttpClientFactory          = cliHttpClientFactory;
     RemoteServiceExceptionHandler = remoteServiceExceptionHandler;
     JsonSerializer = jsonSerializer;
 }
Esempio n. 8
0
    private async Task <NpmPackageInfo> FindNpmPackageInfoAsync(string packageName)
    {
        var url    = $"{CliUrls.WwwAbpIo}api/app/npmPackage/byName/?name=" + packageName;
        var client = _cliHttpClientFactory.CreateClient();

        using (var response = await client.GetAsync(url, _cliHttpClientFactory.GetCancellationToken()))
        {
            if (!response.IsSuccessStatusCode)
            {
                if (response.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new CliUsageException($"'{packageName}' npm package could not be found!");
                }

                await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);
            }

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

            return(JsonSerializer.Deserialize <NpmPackageInfo>(responseContent));
        }
    }
Esempio n. 9
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;
        }
    }
Esempio n. 10
0
        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));
            }
        }
Esempio n. 11
0
    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);
        }
    }