コード例 #1
0
ファイル: HttpDispatchProxy.cs プロジェクト: tahaipek/Proxy
        private async Task <ResponseContext> InternalInvokeAsync(MethodInfo targetMethod, object[] args, Type genericReturnType = null)
        {
            var culture = _proxyContext.CultureFactory?.Invoke();

            var descriptor = new RequestDescriptor(targetMethod,
                                                   _proxyContext.ProxyType,
                                                   _proxyContext.ClientIp,
                                                   _proxyContext.UserAgent,
                                                   _proxyContext.Query,
                                                   culture,
                                                   args);

            RequestContext requestContext = await _proxyManager.CreateRequestAsync(descriptor);

            ResponseContext responseContext = null;

            try
            {
                HttpResponseMessage response = null;
                string metadata = string.Empty;

                if (_proxyManager.HasFilter)
                {
                    await Task.WhenAll(_proxyManager.RequestFilters.Select(t => t.InvokeAsync(requestContext)));
                }

                response = await _proxyManager.HttpClient.SendAsync(requestContext.Request);

                responseContext = await ProxyResultExecutor.ExecuteAsync(response,
                                                                         requestContext,
                                                                         genericReturnType);
            }
            catch (Exception ex)
            {
                var properties = CreateContextProperties(requestContext, targetMethod);
                var result     = properties.GetConfigurationContextDetail(properties);
                throw new ProxyException(result, ex);
            }

            if ((int)responseContext.Response.StatusCode == StatusCodes.Status404NotFound)
            {
                var properties = CreateContextProperties(requestContext, targetMethod);
                var result     = properties.GetConfigurationContextDetail(properties);
                throw new ProxyException(result, new HttpRequestException());
            }

            return(responseContext);
        }