public override RequestAnalysisResult GetRequestAnalysis(RequestAnalysisContext analysisContext) { if (analysisContext.HttpRouteData != null) { return(base.GetRequestAnalysis(analysisContext)); } return(null); }
public RequestAnalysisResult GetRequestAnalysis(RequestAnalysisContext analysisContext) { foreach (var provider in Providers) { RequestAnalysisResult analysisResult = provider.GetRequestAnalysis(analysisContext); if (analysisResult != null) { return(analysisResult); } } return(null); }
public RequestAnalysisResult GetRequestAnalysis(RequestAnalysisContext analysisContext) { if (analysisContext.RouteData != null) { if (analysisContext.RouteData?.RouteHandler.GetType() == typeof(HttpControllerRouteHandler)) { return(_httpProvider.GetRequestAnalysis(analysisContext)); } return(_mvcProvider.GetRequestAnalysis(analysisContext)); } return(null); }
protected void ExcuteCore(RequestAnalysisContext analysisContext, IRequestAnalysisProvider provider) { try { RequestAnalysisResult analysisResult = provider.GetRequestAnalysis(analysisContext); if (!string.IsNullOrEmpty(analysisResult?.Mode)) { OutputResult(analysisResult); } } catch (Exception ex) { Debug.WriteLine($"Url: {HttpContext.Current.Request.Url}"); Debug.WriteLine(ex.Message); } }
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 override RequestAnalysisResult GetRequestAnalysis(RequestAnalysisContext analysisContext) { RouteData routeData = analysisContext.RouteData; RequestAnalysisResult analysisResult = new RequestAnalysisResult(); string controllerName = routeData.Values.TryGetValue("controller", out object controller) ? controller.ToString() : null; analysisResult.ActionName = routeData.Values.TryGetValue("action", out object action) ? action.ToString() : null; if (!string.IsNullOrEmpty(controllerName) && !string.IsNullOrEmpty(analysisResult.ActionName)) { IControllerFactory controllerFactory = ControllerBuilder.Current.GetControllerFactory(); RequestContext requestContext = new RequestContext(new HttpContextWrapper(HttpContext.Current), routeData); IController controllerInstance = controllerFactory.CreateController(requestContext, controllerName); ControllerDescriptor controllerDescriptor = new ReflectedControllerDescriptor(controllerInstance.GetType()); ControllerContext controllerContext = new ControllerContext(requestContext, controllerInstance as ControllerBase); ActionDescriptor actionDescriptor = controllerDescriptor.FindAction(controllerContext, analysisResult.ActionName); analysisResult.Url = HttpContext.Current.Request.Url.ToString(); analysisResult.Mode = Mode; analysisResult.Values = routeData.Values; analysisResult.DataTokens = routeData.DataTokens; analysisResult.ControllerName = controllerDescriptor.ControllerType.FullName; analysisResult.Parameters = actionDescriptor.GetParameters().Select(parameter => parameter.ParameterName).ToArray(); analysisResult.SupportedHttpMethods = actionDescriptor.GetCustomAttributes(typeof(ActionMethodSelectorAttribute), true) .Select(methodAttribute => methodAttribute.GetType().Name.Replace("Attribute", "").Replace("Http", "")).ToArray(); analysisResult.SupportedHttpMethods = analysisResult.SupportedHttpMethods.Count() == 0 ? new string[1] { "All" } : analysisResult.SupportedHttpMethods; string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, LookupPrefix); analysisResult.FilePath = LookupFilePath(path, analysisResult.ControllerName); } return(analysisResult); }
public abstract RequestAnalysisResult GetRequestAnalysis(RequestAnalysisContext analysisContext);