示例#1
0
        /// <summary>
        /// Execute request
        /// </summary>
        /// <param name="process">Application process</param>
        /// <param name="controllerName">Controller name</param>
        /// <param name="actionName">Action name</param>
        /// <param name="data">JSON data</param>
        /// <returns></returns>
        public string InvokeRequest(ApplicationProcess process, string controllerName, string actionName, string data)
        {
            if (!Controllers.ContainsKey(controllerName))
            {
                throw new ArgumentOutOfRangeException($"Requested request handler not found: {controllerName}");
            }

            RequestController ctrl = Controllers[controllerName];

            if (!ctrl.HasAction(actionName))
            {
                throw new ArgumentOutOfRangeException($"Requested action '{actionName}' not available in {controllerName}");
            }

            ActionHandler handler = ctrl.GetActionHandler(actionName);

            return(handler(process, data));
        }
示例#2
0
        /// <summary>
        /// Register a new controller
        /// </summary>
        /// <param name="controllerInstance"></param>
        /// <returns></returns>
        public RequestDispatcher AddController(RequestController controllerInstance)
        {
            Controllers.Add(controllerInstance.GetControllerName(), controllerInstance);

            return(this);
        }