示例#1
0
    private async Task LogoutAsync(string accessToken)
    {
        try
        {
            var client  = CliHttpClientFactory.CreateClient();
            var content = new StringContent(
                JsonSerializer.Serialize(new { token = accessToken }),
                Encoding.UTF8, "application/json"
                );

            using (var response = await client.PostAsync(CliConsts.LogoutUrl, content, CancellationTokenProvider.Token))
            {
                if (!response.IsSuccessStatusCode)
                {
                    Logger.LogWarning(
                        $"Cannot logout from remote service! Response: {response.StatusCode}-{response.ReasonPhrase}"
                        );
                }
            }
        }
        catch (Exception e)
        {
            Logger.LogWarning($"Error occured while logging out from remote service. {e.Message}");
        }
    }
示例#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));
        }
    }
    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;
        }
    }
示例#4
0
        public async Task <MyGetApiResponse> GetPackagesAsync()
        {
            if (_response != null)
            {
                return(_response);
            }

            try
            {
                var client = _cliHttpClientFactory.CreateClient();

                using (var responseMessage = await client.GetAsync(
                           $"{CliUrls.WwwAbpIo}api/myget/packages/",
                           _cliHttpClientFactory.GetCancellationToken(TimeSpan.FromMinutes(10))))
                {
                    _response = JsonConvert.DeserializeObject <MyGetApiResponse>(
                        Encoding.Default.GetString(await responseMessage.Content.ReadAsByteArrayAsync())
                        );
                }
            }
            catch (Exception ex)
            {
                Logger.LogError("Unable to get latest preview version. Error: " + ex.Message);
                throw;
            }

            return(_response);
        }
示例#5
0
    protected virtual async Task <ModuleWithMastersInfo> GetModuleInfoAsync(string moduleName, bool newTemplate,
                                                                            bool newProTemplate = false)
    {
        if (newTemplate || newProTemplate)
        {
            return(GetEmptyModuleProjectInfo(moduleName, newProTemplate));
        }

        var url    = $"{CliUrls.WwwAbpIo}api/app/module/byNameWithDetails/?name=" + moduleName;
        var client = _cliHttpClientFactory.CreateClient();

        using (var response = await client.GetAsync(url, _cliHttpClientFactory.GetCancellationToken()))
        {
            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));
        }
    }
示例#6
0
        public async Task CollectAsync(CliAnalyticsCollectInputDto input)
        {
            var postData = _jsonSerializer.Serialize(input);
            var url      = $"{CliUrls.WwwAbpIo}api/clianalytics/collect";

            try
            {
                var client = _cliHttpClientFactory.CreateClient();

                var responseMessage = await client.PostAsync(
                    url,
                    new StringContent(postData, Encoding.UTF8, MimeTypes.Application.Json),
                    _cancellationTokenProvider.Token
                    );

                if (!responseMessage.IsSuccessStatusCode)
                {
                    var exceptionMessage          = "Remote server returns '" + (int)responseMessage.StatusCode + "-" + responseMessage.ReasonPhrase + "'. ";
                    var remoteServiceErrorMessage = await _remoteServiceExceptionHandler.GetAbpRemoteServiceErrorAsync(responseMessage);

                    if (remoteServiceErrorMessage != null)
                    {
                        exceptionMessage += remoteServiceErrorMessage;
                    }

                    _logger.LogInformation(exceptionMessage);
                }
            }
            catch (Exception)
            {
                // ignored
            }
        }
示例#7
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));
        }
    }
示例#8
0
        private async Task <List <ModuleInfo> > GetModuleListInternalAsync()
        {
            var client = _cliHttpClientFactory.CreateClient();

            using (var responseMessage = await client.GetAsync(
                       $"{CliUrls.WwwAbpIo}api/download/modules/",
                       CancellationTokenProvider.Token
                       ))
            {
                await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(responseMessage);

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

                return(JsonSerializer.Deserialize <List <ModuleInfo> >(result));
            }
        }
示例#9
0
 public async Task <string> GetApiKeyAsync()
 {
     try
     {
         var client = _cliHttpClientFactory.CreateClient();
         using (var response = await client.GetHttpResponseMessageWithRetryAsync(
                    url: $"{CliUrls.WwwAbpIo}api/myget/apikey/",
                    cancellationToken: CancellationTokenProvider.Token,
                    logger: Logger
                    ))
         {
             return(Encoding.Default.GetString(await response.Content.ReadAsByteArrayAsync()));
         }
     }
     catch (Exception)
     {
         return(string.Empty);
     }
 }
示例#10
0
        protected virtual async Task <NugetPackageInfo> FindNugetPackageInfoAsync(string packageName)
        {
            var url    = $"{CliUrls.WwwAbpIo}api/app/nugetPackage/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}' nuget package could not be found!");
                    }

                    await RemoteServiceExceptionHandler.EnsureSuccessfulHttpResponseAsync(response);
                }

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

                return(JsonSerializer.Deserialize <NugetPackageInfo>(responseContent));
            }
        }
示例#11
0
    protected virtual async Task <ApplicationApiDescriptionModel> GetApplicationApiDescriptionModelAsync(GenerateProxyArgs args)
    {
        Check.NotNull(args.Url, nameof(args.Url));

        var client = CliHttpClientFactory.CreateClient();

        var apiDefinitionResult = await client.GetStringAsync(CliUrls.GetApiDefinitionUrl(args.Url));

        var apiDefinition = JsonSerializer.Deserialize <ApplicationApiDescriptionModel>(apiDefinitionResult);

        var moduleDefinition = apiDefinition.Modules.FirstOrDefault(x => string.Equals(x.Key, args.Module, StringComparison.CurrentCultureIgnoreCase)).Value;

        if (moduleDefinition == null)
        {
            throw new CliUsageException($"Module name: {args.Module} is invalid");
        }

        var apiDescriptionModel = ApplicationApiDescriptionModel.Create();

        apiDescriptionModel.AddModule(moduleDefinition);

        return(apiDescriptionModel);
    }