/// <summary> /// Gets the <see cref="HttpControllerContext"/> for the supplied <see cref="Uri"/>. /// </summary> /// <param name="a_uri"> /// The URI. /// </param> /// <returns> /// The <see cref="HttpControllerContext"/> instance for the supplier URI. /// </returns> private HttpControllerContext GetControllerContext(Uri a_uri) { using (var request = new HttpRequestMessage(HttpMethod.Get, a_uri)) { var routeData = Configuration.Routes.GetRouteData(request); if (routeData == null) { return(null); } request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData; request.Properties[HttpPropertyKeys.HttpConfigurationKey] = Configuration; var controllerContext = new HttpControllerContext(Configuration, routeData, request); var controllerName = GetControllerName(routeData); if (!m_controllerSelector.GetControllerMapping().ContainsKey(controllerName)) { return(null); } controllerContext.ControllerDescriptor = m_controllerSelector.SelectController(request); return(controllerContext); } }
internal Type GetControllerType() { var descriptor = _controllerSelector.SelectController(_request); _controllerContext.ControllerDescriptor = descriptor; return(descriptor.ControllerType); }
HttpControllerDescriptor IHttpControllerSelector.SelectController(HttpRequestMessage request) { HttpControllerDescriptor controllerDescriptor = null; _traceWriter.TraceBeginEnd( request, TraceCategories.ControllersCategory, TraceLevel.Info, _innerSelector.GetType().Name, SelectControllerMethodName, beginTrace: (tr) => { tr.Message = Error.Format( SRResources.TraceRouteMessage, FormattingUtilities.RouteToString(request.GetRouteData())); }, execute: () => { controllerDescriptor = _innerSelector.SelectController(request); }, endTrace: (tr) => { tr.Message = controllerDescriptor == null ? SRResources.TraceNoneObjectMessage : controllerDescriptor.ControllerName; }, errorTrace: null); if (controllerDescriptor != null && !(controllerDescriptor is HttpControllerDescriptorTracer)) { return(new HttpControllerDescriptorTracer(controllerDescriptor.Configuration, controllerDescriptor.ControllerName, controllerDescriptor.ControllerType, controllerDescriptor, _traceWriter)); } return(controllerDescriptor); }
public void TestRoute(string url, string verb, Type type, string actionName) { //Arrange url = url.Replace("{apiVersionNumber}", this.ApiVersionNumber); url = Host + url; //Act HttpRequestMessage request = new HttpRequestMessage(new HttpMethod(verb), url); IHttpControllerSelector controller = this.GetControllerSelector(); IHttpActionSelector action = this.GetActionSelector(); IHttpRouteData route = this.Config.Routes.GetRouteData(request); request.Properties[HttpPropertyKeys.HttpRouteDataKey] = route; request.Properties[HttpPropertyKeys.HttpConfigurationKey] = this.Config; HttpControllerDescriptor controllerDescriptor = controller.SelectController(request); HttpControllerContext context = new HttpControllerContext(this.Config, route, request) { ControllerDescriptor = controllerDescriptor }; var actionDescriptor = action.SelectAction(context); //Assert Assert.NotNull(controllerDescriptor); Assert.NotNull(actionDescriptor); Assert.Equal(type, controllerDescriptor.ControllerType); Assert.Equal(actionName, actionDescriptor.ActionName); }
public Type GetControllerType() { var descriptor = controllerSelector.SelectController(request); controllerContext.ControllerDescriptor = descriptor; return(descriptor.ControllerType); }
public HttpControllerDescriptor SelectController(HttpRequestMessage request) { var descriptor = defaultControllerSelector.SelectController(request); var controller = SampleEnvironment.Container.Resolve(descriptor.ControllerType); return(new SampleHttpControllerDescriptor(httpConfiguration, controller.GetType().Name, controller.GetType())); }
public HttpControllerDescriptor SelectController(HttpRequestMessage request) { string controllerName = GetControllerName(request); if (String.IsNullOrEmpty(controllerName)) { return _fallbackControllerSelector.SelectController(request); } HttpControllerDescriptor controllerDescriptor; if (_managedControllers.TryGetValue(controllerName, out controllerDescriptor)) { return controllerDescriptor; } else { return _fallbackControllerSelector.SelectController(request); } }
public HttpControllerDescriptor SelectController(HttpRequestMessage request) { try { return(_concreteSelector.SelectController(request)); } catch (HttpResponseException ex) { _clientCreator.GenerateRaygunWebApiClient().CurrentHttpRequest(request).SendInBackground(ex); throw; } }
public TestControllerBuilder(HttpRequestMessage request, HttpConfiguration httpConfiguration) { var routeData = request.Properties[HttpPropertyKeys.HttpRouteDataKey] as IHttpRouteData; controllerContext = new HttpControllerContext(httpConfiguration, routeData, request); IHttpControllerSelector controllerSelector = httpConfiguration.Services.GetHttpControllerSelector(); controlleDescriptor = controllerSelector.SelectController(request); controllerContext.ControllerDescriptor = controlleDescriptor; actionSelector = new ApiControllerActionSelector(); this.httpConfiguration = httpConfiguration; requestMessage = request; }
private Type GetControllerType() { try { var descriptor = _controllerSelector.SelectController(_request); _controllerContext.ControllerDescriptor = descriptor; return(descriptor.ControllerType); } catch (Exception exception) { Console.WriteLine(exception.ToString()); return(typeof(object)); } }
public HttpControllerDescriptor SelectController(HttpRequestMessage request) { try { return(_concreteSelector.SelectController(request)); } catch (HttpResponseException ex) { _clientCreator.GenerateRaygunWebApiClient(request).SendInBackground(ex, new List <string> { RaygunWebApiClient.UnhandledExceptionTag }); throw; } }
public HttpControllerDescriptor SelectController(HttpRequestMessage request) { if (request == null) { throw Error.ArgumentNull("request"); } IHttpRouteData routeData = request.GetRouteData(); if (routeData == null) { return(_innerSelector.SelectController(request)); } ODataPath odataPath = request.GetODataPath(); if (odataPath == null) { return(_innerSelector.SelectController(request)); } foreach (IODataRoutingConvention routingConvention in _routingConventions) { string controllerName = routingConvention.SelectController(odataPath, request); if (controllerName != null) { routeData.Values.Add(ODataRouteConstants.Controller, controllerName); return(_innerSelector.SelectController(request)); } } throw new HttpResponseException(request.CreateErrorResponse( HttpStatusCode.NotFound, Error.Format(SRResources.NoMatchingResource, request.RequestUri), Error.Format(SRResources.NoRoutingHandlerToSelectController, odataPath.PathTemplate))); }
protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { IHttpRouteData routeData = request.GetRouteData(); IHttpControllerSelector ControllerSelector = mConfiguration.Services.GetHttpControllerSelector(); HttpControllerDescriptor httpControllerDescriptor = ControllerSelector.SelectController(request); IHttpController httpController = httpControllerDescriptor.CreateController(request); request.Method = new HttpMethod(mVerbChange); // Create context HttpControllerContext controllerContext = new HttpControllerContext(mConfiguration, routeData, request); controllerContext.Controller = httpController; controllerContext.ControllerDescriptor = httpControllerDescriptor; return(httpController.ExecuteAsync(controllerContext, cancellationToken)); }
public HttpControllerDescriptor SelectController(HttpRequestMessage request) { if (request.IsInspectRequest()) { var controllers = _innerSelector.GetControllerMapping().Values.Select(desc => new ControllerSelectionInfo { ControllerName = desc.ControllerName, ControllerType = desc.ControllerType.AssemblyQualifiedName }).ToArray(); request.Properties[RequestHelper.ControllerCache] = controllers; } // DefaultHttpControllerSelector.SelectController var controllerDescriptor = _innerSelector.SelectController(request); // if exception is not thrown request.Properties[RequestHelper.SelectedController] = controllerDescriptor.ControllerName; return(controllerDescriptor); }
public override System.Web.Http.Controllers.HttpControllerDescriptor SelectController(System.Net.Http.HttpRequestMessage request) { HttpControllerDescriptor httpControllerDescriptor = null; if (request != null) { string controllerName = this.GetControllerName(request); if (!string.IsNullOrEmpty(controllerName)) { ControllerDescriptors.TryGetValue(controllerName, out httpControllerDescriptor); } } if (httpControllerDescriptor != null) { return(httpControllerDescriptor); } if (_originalControllerSelector != null) { return(_originalControllerSelector.SelectController(request)); } return(base.SelectController(request)); }
public override RequestAnalysisResult GetRequestAnalysis(RequestAnalysisContext analysisContext) { HttpRequestMessage request = analysisContext.RequestMessage; HttpConfiguration httpConfiguration = request.GetConfiguration(); IHttpRouteData httpRouteData = httpConfiguration.Routes.GetRouteData(request); request.SetRouteData(httpRouteData); //IAssembliesResolver assembliesResolver= httpConfiguration.Services.GetAssembliesResolver(); //IHttpControllerTypeResolver controllerTypeResolver = httpConfiguration.Services.GetHttpControllerTypeResolver(); //ICollection<Type> controllerTypes= controllerTypeResolver.GetControllerTypes(assembliesResolver); IHttpControllerSelector controllerSelector = httpConfiguration.Services.GetHttpControllerSelector(); HttpControllerDescriptor controllerDescriptor = controllerSelector.SelectController(request); HttpControllerContext controllerContext = new HttpControllerContext(httpConfiguration, httpRouteData, request); controllerContext.ControllerDescriptor = controllerDescriptor; IHttpActionSelector actionSelector = httpConfiguration.Services.GetActionSelector(); HttpActionDescriptor actionDescriptor = actionSelector.SelectAction(controllerContext); RequestAnalysisResult analysisResult = new RequestAnalysisResult(); analysisResult.Url = request.RequestUri.ToString(); analysisResult.SupportedHttpMethods = actionDescriptor.SupportedHttpMethods.Select(method => method.Method).ToArray(); analysisResult.Parameters = actionDescriptor.GetParameters().Select(parameter => parameter.ParameterName).ToArray(); analysisResult.ActionName = actionDescriptor.ActionName; analysisResult.ControllerName = actionDescriptor.ControllerDescriptor.ControllerName; analysisResult.Values = httpRouteData.Values; analysisResult.DataTokens = httpRouteData.Route.DataTokens; analysisResult.Mode = Mode; string path = new DirectoryInfo(string.Format(@"{0}{1}", AppDomain.CurrentDomain.BaseDirectory, LookupPrefix)).FullName; analysisResult.FilePath = LookupFilePath(path, analysisResult.ControllerName); return(analysisResult); }
public HttpControllerDescriptor SelectController(System.Net.Http.HttpRequestMessage request) { return(httpControllerSelector.SelectController(request)); }
public HttpControllerDescriptor SelectController(HttpRequestMessage request) { var httpControllerDescriptor = inner.SelectController(request); return(httpControllerDescriptor); }