Пример #1
0
        public async Task <TResult> GetAsync <TResult>(Uri hostname, string relativeUri,
                                                       CancellationToken cancellationToken,
                                                       IEnumerable <KeyValuePair <string, string> > requestParameters = null,
                                                       IEnumerable <KeyValuePair <string, string> > extraHeaders      = null)
            where TResult : class
        {
            SimpleServiceResult <TResult, TResult> result =
                await GetAsync <TResult, TResult>(hostname, relativeUri, cancellationToken, requestParameters, extraHeaders);

            return(result.Result ?? result.ErrorResult);
        }
        private async Task <TResult> RetryOnExpiredTokenAsync <TResult>(CancellationToken cancellationToken, Func <CancellationToken, Task <SimpleServiceResult <TResult, TResult> > > action)
            where TResult : class
        {
            SimpleServiceResult <TResult, TResult> result = await action(cancellationToken);

            if ((result.HttpStatusCode == HttpStatusCode.Unauthorized || result.HttpStatusCode == HttpStatusCode.Forbidden) &&
                result.AuthorizationTokenInvalid != null &&
                result.AuthorizationTokenInvalid.Value == AuthorizationTokenInvalid.Expired)
            {
                if (xToken != null && await xToken.RefreshAsync(cancellationToken))
                {
                    result = await action(cancellationToken);
                }
            }

            return(result.Result ?? result.ErrorResult);
        }