public void InvokeAction(ControllerContext context, String actionName) { Requires.NotNull(context, "context"); Requires.NotNull(actionName, "actionName"); MethodInfo method = GetSuitableMethod(context, actionName); if (method != null) { ParameterInfo[] parameters = method.GetParameters(); Object[] parameterValues = GetParameterValues(parameters, context.RouteData); var actionContext = new ActionContext(context, actionName); IAsyncController asyncController = context.Controller as IAsyncController; if ((asyncController != null)&&(method.ReturnType.Equals(typeof(void)))) { asyncController.ActionCompleted += DefaultActionInvoker_ActionCompleted; _contextCache.Add(asyncController, actionContext); method.Invoke(context.Controller, parameterValues); } else { IActionResult actionResult = method.Invoke(context.Controller, parameterValues) as IActionResult; if (actionResult != null) { actionResult.Execute(actionContext); } } } }
public ViewContext(ControllerContext context, ViewDataDictionary viewData) : base(context.Controller, context.RequestContext, context.RouteData) { Requires.NotNull(context, "context"); Requires.NotNull(viewData, "viewData"); ViewData = viewData; }
public IView GetView(ControllerContext context, String viewName) { IView view = null; foreach (var viewEngine in _viewEngines) { view = viewEngine.GetView(context, viewName); if (view != null) { break; } } return view; }
public static Boolean IsValidForRequest(ControllerContext context, MethodInfo method) { Requires.NotNull(context, "context"); Object[] attr = method.GetCustomAttributes(typeof(AcceptVerbsAttribute), false); if (attr.Length > 0) { if((attr[0] as AcceptVerbsAttribute).Verbs.Contains(context.RequestContext.Verb, StringComparer.OrdinalIgnoreCase)) { return true; } } return false; }
public ActionContext(ControllerContext controllerContext, String actionName) { _controllerContext = controllerContext; _actionName = actionName; }
public void Execute(RequestContext context) { _controllerContext = new ControllerContext(this, context, context.RouteData); Execute(); }
private MethodInfo GetSuitableMethod(ControllerContext context, String actionName) { IEnumerable<MethodInfo> methods = context.Controller.GetType().GetMethods(). Where(m => m.Name.Equals(actionName, StringComparison.OrdinalIgnoreCase)); foreach (var method in methods) { if (AcceptVerbsAttribute.IsValidForRequest(context, method)) { return method; } } return methods.FirstOrDefault(); }