예제 #1
0
        private void Debug <TController, TResponse>(
            Expression <Func <TController, TResponse> > expression, Action <HttpRequestHeaders> headerBuilder = null, HttpRequestMessage message = null) where TController : ControllerBase
        {
            var controllerAction = ControllerActionFactory.GetAction(expression);

            var sb = new StringBuilder();

            sb.AppendLine();
            sb.AppendLine($"Controller:{controllerAction.Controller}");
            sb.AppendLine($"Action:{controllerAction.ActionName}");
            sb.AppendLine($"Route Segments:{string.Join(Environment.NewLine, controllerAction.RouteSegments)}");
            sb.AppendLine();
            sb.AppendLine(message.RequestUri.ToString());
            Logger.Write(sb.ToString());
        }
예제 #2
0
        /// <summary>
        /// Invokes an IControllerAction
        /// </summary>
        /// <typeparam name="TController">The type of the controller.</typeparam>
        /// <typeparam name="TResponse">The type of the response.</typeparam>
        /// <param name="client">The http client.</param>
        /// <param name="expression">The expression.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">controllerAction</exception>
        public static async Task <TResponse> InvokeAsync <TController, TResponse>(this HttpClient client,
                                                                                  Expression <Func <TController, object> > expression) where TController : Controller
        {
            if (expression == null)
            {
                throw new System.ArgumentNullException(nameof(expression));
            }
            var controllerAction = ControllerActionFactory.GetAction(expression);
            var route            = ControllerActionRouteFactory.CreateRoute(controllerAction);
            var response         = await client.SendAsync(route.BuildRequestMessage(controllerAction));

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

            response.EnsureSuccessStatusCode();
            return(JsonConvert.DeserializeObject <TResponse>(dataAsString));
        }