/// <summary> /// Select a member /// </summary> /// <param name="controllerContext"></param> /// <param name="controllerDescriptor"></param> /// <param name="actionName"></param> /// <returns></returns> protected override ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName) { // Get all members in the controller var members = MvcApplication.Host.ScriptEngine.Operations.GetMemberNames(controllerContext.Controller); string resolvedActionName = ""; // If memebrs match, return if (members.Contains(actionName)) { resolvedActionName = actionName; } else { // Search with ignore-case mode foreach (var member in members) { if (member.ToLower() == actionName.ToLower()) { resolvedActionName = member; } } } // If an action was found if (!string.IsNullOrWhiteSpace(resolvedActionName)) { // Search for all method of this type var httpMethod = controllerContext.HttpContext.Request.HttpMethod; //GET POST DELETE PUT var member = MvcApplication.Host.ScriptEngine.Operations.GetMember(controllerContext.Controller, resolvedActionName); var methodInfo = member as IronPython.Runtime.Method; var pythonFunction = methodInfo.__func__ as PythonFunction; Decorator.ActionDecorator dec = null; if (AspNetMvcAPI.Filter.actionDecorators.TryGetValue(pythonFunction, out dec)) { if (string.IsNullOrWhiteSpace(dec.httpMethod) && httpMethod == "GET") { return(new DynamicActionDescriptor(controllerContext, controllerDescriptor, resolvedActionName, pythonFunction)); } else if (dec.httpMethod == httpMethod) { return(new DynamicActionDescriptor(controllerContext, controllerDescriptor, resolvedActionName, pythonFunction)); } } else if (httpMethod == "GET") { return(new DynamicActionDescriptor(controllerContext, controllerDescriptor, resolvedActionName, pythonFunction)); } } return(null); }
/// <summary> /// Generic way to register a function /// </summary> /// <param name="function">Function object</param> /// <param name="method">Method to register</param> /// <returns>Function object</returns> public static object register_http_method(object function, string method) { if (function is PythonFunction) { Decorator.ActionDecorator value = null; if (__actionDecorators.TryGetValue((PythonFunction)function, out value)) { value.httpMethod = method; } else { value = new Decorator.ActionDecorator((PythonFunction)function); value.httpMethod = method; __actionDecorators.Add((PythonFunction)function, value); } } else { throw new Exception("Http-Decorator must be applied on a function: " + (function ?? "").ToString()); } return(function); }
/// <summary> /// Generic way to register a function /// </summary> /// <param name="function">Function object</param> /// <param name="method">Method to register</param> /// <returns>Function object</returns> public static object register_http_method(object function, string method) { if (function is PythonFunction) { Decorator.ActionDecorator value = null; if (__actionDecorators.TryGetValue((PythonFunction)function, out value)) { value.httpMethod = method; } else { value = new Decorator.ActionDecorator((PythonFunction)function); value.httpMethod = method; __actionDecorators.Add((PythonFunction)function, value); } } else { throw new Exception("Http-Decorator must be applied on a function: " + (function ?? "").ToString()); } return function; }