예제 #1
0
        private async Task <T> PostRidDictionary <T>(string requestUri, HttpClient http, Config.PollingConfig.Polling config, Dictionary <string, string> requestParams) where T : IRidRequestResponse
        {
            // Get RID
            var response = await http.PostAsync(requestUri, new FormUrlEncodedContent(requestParams));

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

            var result = ReadAs <T>(content);

            if ("RID" == result.Result)
            {
                requestParams.Add("rid", result.RID);
            }

            var retries = config.MaxRetry;

            for (; ;)
            {
                if ("OK".Equals(result.Result))
                {
                    return(result);
                }
                else if ("RID".Equals(result.Result))
                {
                    if (--retries <= 0)
                    {
                        break;
                    }
                    await Task.Delay(config.Interval);

                    response = await http.PostAsync(requestUri, new FormUrlEncodedContent(requestParams));

                    content = await response.Content.ReadAsStringAsync();

                    result = ReadAs <T>(content);
                }
                else if ("FAIL".Equals(result.Result))
                {
                    var errorResult = ReadAs <ParserErrorResponse>(content);
                    var message     = errorResult.Info ?? errorResult.Error;

                    throw new ErrorResponseException(message, "POST", requestUri);
                }
                else
                {
                    throw new UnexpectedContentException("Unexpected Status", "POST", requestUri, content);
                }
            }
            ;

            throw new NoMoreRetriesException(requestUri, config.MaxRetry);
        }
예제 #2
0
 public Task <T> PostRidDictionary <T>(string requestUri, Session session, Config.PollingConfig.Polling config, Dictionary <string, string> requestParams) where T : IRidRequestResponse
 => PostRidDictionary <T>(requestUri, new HttpClient(RestoreSession(session)), config, requestParams);