public HttpResponse DoAction <T>(AcsRequest <T> request, bool autoRetry, int maxRetryNumber) where T : AcsResponse
 {
     return(DoAction(request, autoRetry, maxRetryNumber, this.clientProfile));
 }
示例#2
0
 public HttpResponse DoAction <T>(AcsRequest <T> request, bool autoRetry, int maxRetryNumber, string regionId,
                                  Credential credential, Signer signer, FormatType?format, List <Endpoint> endpoints) where T : AcsResponse
 {
     return(DoAction(request, autoRetry, maxRetryNumber, regionId, new LegacyCredentials(credential), signer,
                     format, endpoints));
 }
示例#3
0
        public virtual HttpResponse DoAction <T>(AcsRequest <T> request, bool autoRetry, int maxRetryNumber,
                                                 string regionId,
                                                 AlibabaCloudCredentials credentials, Signer signer, FormatType?format, List <Endpoint> endpoints)
            where T : AcsResponse
        {
            var                httpStatusCode    = "";
            var                retryAttemptTimes = 0;
            ClientException    exception;
            RetryPolicyContext retryPolicyContext;

            do
            {
                try
                {
                    var watch = Stopwatch.StartNew();

                    FormatType?requestFormatType = request.AcceptFormat;
                    format = requestFormatType;

                    var domain = request.ProductDomain ??
                                 Endpoint.FindProductDomain(regionId, request.Product, endpoints);

                    if (null == domain)
                    {
                        throw new ClientException("SDK.InvalidRegionId", "Can not find endpoint to access.");
                    }

                    var userAgent = UserAgent.Resolve(request.GetSysUserAgentConfig(), userAgentConfig);
                    DictionaryUtil.Add(request.Headers, "User-Agent", userAgent);
                    DictionaryUtil.Add(request.Headers, "x-acs-version", request.Version);
                    if (!string.IsNullOrWhiteSpace(request.ActionName))
                    {
                        DictionaryUtil.Add(request.Headers, "x-acs-action", request.ActionName);
                    }
                    var httpRequest = request.SignRequest(signer, credentials, format, domain);
                    ResolveTimeout(httpRequest, request.Product, request.Version, request.ActionName);
                    SetHttpsInsecure(IgnoreCertificate);
                    ResolveProxy(httpRequest, request);
                    var response = GetResponse(httpRequest);

                    httpStatusCode = response.Status.ToString();
                    PrintHttpDebugMsg(request, response);
                    watch.Stop();
                    CommonLog.ExecuteTime = watch.ElapsedMilliseconds;
                    return(response);
                }
                catch (ClientException ex)
                {
                    retryPolicyContext = new RetryPolicyContext(ex, httpStatusCode, retryAttemptTimes, request.Product,
                                                                request.Version,
                                                                request.ActionName, RetryCondition.BlankStatus);

                    CommonLog.LogException(ex, ex.ErrorCode, ex.ErrorMessage);
                    exception = ex;
                }

                Thread.Sleep(retryPolicy.GetDelayTimeBeforeNextRetry(retryPolicyContext));
            } while ((retryPolicy.ShouldRetry(retryPolicyContext) & RetryCondition.NoRetry) != RetryCondition.NoRetry);

            if (exception != null)
            {
                CommonLog.LogException(exception, exception.ErrorCode, exception.ErrorMessage);
                throw new ClientException(exception.ErrorCode, exception.ErrorMessage);
            }

            return(null);
        }
示例#4
0
        public T GetAcsResponse <T>(AcsRequest <T> request, IClientProfile profile) where T : AcsResponse
        {
            var httpResponse = DoAction(request, profile);

            return(ParseAcsResponse(request, httpResponse));
        }
示例#5
0
 public HttpResponse DoAction <T>(AcsRequest <T> request, IClientProfile profile) where T : AcsResponse
 {
     return(DoAction(request, AutoRetry, MaxRetryNumber, profile));
 }
示例#6
0
        public T GetAcsResponse <T>(AcsRequest <T> request, bool autoRetry, int maxRetryNumber) where T : AcsResponse
        {
            var httpResponse = DoAction(request, autoRetry, maxRetryNumber);

            return(ParseAcsResponse(request, httpResponse));
        }
示例#7
0
        public T GetAcsResponse <T>(AcsRequest <T> request) where T : AcsResponse
        {
            var httpResponse = DoAction(request);

            return(ParseAcsResponse(request, httpResponse));
        }
示例#8
0
        public T GetAcsResponse <T>(AcsRequest <T> request, string regionId, Credential credential) where T : AcsResponse
        {
            HttpResponse httpResponse = this.DoAction(request, regionId, credential);

            return(ParseAcsResponse(request, httpResponse));
        }
        public virtual HttpResponse DoAction <T>(AcsRequest <T> request, bool autoRetry, int maxRetryNumber, string regionId,
                                                 AlibabaCloudCredentials credentials, Signer signer, FormatType?format, List <Endpoint> endpoints) where T : AcsResponse
        {
            FormatType?requestFormatType = request.AcceptFormat;

            if (null != requestFormatType)
            {
                format = requestFormatType;
            }
            ProductDomain domain = null;

            if (request.ProductDomain != null)
            {
                domain = request.ProductDomain;
            }
            else
            {
                domain = Endpoint.FindProductDomain(regionId, request.Product, endpoints);
            }
            if (null == domain)
            {
                throw new ClientException("SDK.InvalidRegionId", "Can not find endpoint to access.");
            }

            request.Headers["User-Agent"] = UserAgent.Resolve(request.GetSysUserAgentConfig(), this.userAgentConfig);

            bool shouldRetry = true;

            for (int retryTimes = 0; shouldRetry; retryTimes++)
            {
                shouldRetry = autoRetry && retryTimes < maxRetryNumber;
                HttpRequest httpRequest = request.SignRequest(signer, credentials, format, domain);

                ResolveTimeout(httpRequest);
                SetHttpsInsecure(IgnoreCertificate);
                ResolveProxy(httpRequest, request);

                HttpResponse response = this.GetResponse(httpRequest);

                PrintHttpDebugMsg(request, response);

                if (response.Content == null)
                {
                    if (shouldRetry)
                    {
                        continue;
                    }
                    else
                    {
                        throw new ClientException("SDK.ConnectionReset", "Connection reset.");
                    }
                }

                if (500 <= response.Status && shouldRetry)
                {
                    continue;
                }

                return(response);
            }

            return(null);
        }
示例#10
0
        public virtual HttpResponse DoAction <T>(AcsRequest <T> request, bool autoRetry, int maxRetryNumber, string regionId,
                                                 AlibabaCloudCredentials credentials, Signer signer, FormatType?format, List <Endpoint> endpoints) where T : AcsResponse
        {
            try
            {
                SerilogHelper.StartTime = DateTime.UtcNow.ToString("o");
                var watch = System.Diagnostics.Stopwatch.StartNew();

                FormatType?requestFormatType = request.AcceptFormat;
                if (null != requestFormatType)
                {
                    format = requestFormatType;
                }
                ProductDomain domain = null;
                if (request.ProductDomain != null)
                {
                    domain = request.ProductDomain;
                }
                else
                {
                    domain = Endpoint.FindProductDomain(regionId, request.Product, endpoints);
                }
                if (null == domain)
                {
                    throw new ClientException("SDK.InvalidRegionId", "Can not find endpoint to access.");
                }

                request.Headers["User-Agent"] = UserAgent.Resolve(request.GetSysUserAgentConfig(), this.userAgentConfig);

                bool shouldRetry = true;
                for (int retryTimes = 0; shouldRetry; retryTimes++)
                {
                    shouldRetry = autoRetry && retryTimes < maxRetryNumber;
                    HttpRequest httpRequest = request.SignRequest(signer, credentials, format, domain);

                    ResolveTimeout(httpRequest);
                    SetHttpsInsecure(IgnoreCertificate);
                    ResolveProxy(httpRequest, request);

                    HttpResponse response = GetResponse(httpRequest);

                    PrintHttpDebugMsg(request, response);

                    if (response.Content == null)
                    {
                        if (shouldRetry)
                        {
                            continue;
                        }

                        throw new ClientException("SDK.ConnectionReset", "Connection reset.");
                    }

                    if (500 <= response.Status && shouldRetry)
                    {
                        continue;
                    }
                    watch.Stop();
                    SerilogHelper.ExecuteTime = watch.ElapsedMilliseconds;
                    return(response);
                }
            }
            catch (ClientException ex)
            {
                SerilogHelper.LogException(ex, ex.ErrorCode, ex.ErrorMessage);
                throw new ClientException(ex.ErrorCode, ex.ErrorMessage);
            }

            return(null);
        }