コード例 #1
0
        public override object RunAction(DynamicAction objAction, DynamicControllerInfo controller, RestService objService, WebMethod verb,
                                         IDictionary <string, object> arguments)
        {
            var dynController = new DynamicController
            {
                Service        = objService,
                ControllerInfo = controller,
                SelectedAction = objAction
            };

            var objContext = objAction.InitContext(arguments);

            objContext.InitParams(objService.GlobalParameters);
            objContext.InitParams(controller.GlobalParameters);
            objContext.SetVar("Controller", dynController);
            foreach (DynamicParameter parameter in objAction.Parameters)
            {
                object val = null;
                if (parameter.IsOptional && parameter.DefaultValue.Enabled && !arguments.TryGetValue(parameter.Name, out val))
                {
                    objContext.SetVar(parameter.Name, parameter.ResolvedDefaultValue);
                }
            }
            var response = dynController.ProcessInternal(objContext, verb);

            return(response?.EvaluateToReturn(objContext));
        }
コード例 #2
0
        public override Task <object> ExecuteAsync(HttpControllerContext controllerContext,
                                                   IDictionary <string, object> arguments, CancellationToken cancellationToken)
        {
            var objContext = _DynamicMethod.InitContext(arguments);

            objContext.InitParams(_Service.GlobalParameters);
            objContext.InitParams(_Controller.GlobalParameters);
            objContext.SetVar("Controller", controllerContext.Controller);
            objContext.SetVar("Request", controllerContext.Request);
            objContext.SetVar("RouteData", controllerContext.RouteData);
            var newDico = new Dictionary <string, object>(1)
            {
                { DynamicController.ActionContextParameterName, objContext }
            };
            var dynController = controllerContext.Controller as DynamicController;

            if (dynController != null)
            {
                dynController.SelectedAction = _DynamicMethod;
            }
            else
            {
                throw new ApplicationException("DynamicActionDescriptor is tied to Dynamic Controllers");
            }

            return(base.ExecuteAsync(controllerContext, newDico, cancellationToken));
        }