Exemplo n.º 1
0
        private void ResolveActionParameters(ref SocketRequest request)
        {
            foreach (ParameterInfo pi in method.GetParameters())
            {
                if (pi.ParameterType == typeof(SocketRequest))
                {
                    request.AddParameter(new RequestParameter("request", request));
                    continue;
                }

                if (!request.Parameters.Any(rp => rp.Name.Equals(pi.Name)))
                {
                    throw new Exception($"The parameter '{pi.Name}', required on {request.Controller.GetType().Name}/{request.Action}, was not received");
                }
            }
        }
Exemplo n.º 2
0
        private SocketRequest GetRequestSocket()
        {
            if (requestBody == null)
            {
                return(null);
            }
            SocketRequest request = null;

            try
            {
                string path = requestBody.Action;
                controllerName = requestBody.Controller;
                actionName     = requestBody.Action;

                request = new SocketRequest();
                request.SetClientSocket(clientSocket);
                request.Action     = actionName;
                request.Controller = controllerManager.InstantiateController(controllerName, requestBody);

                var parameters = typedObjManager.FillParameters(requestBody.Parameters,
                                                                actionName, request.Controller);

                if (parameters != null)
                {
                    for (int i = 0; i < parameters.Count; i++)
                    {
                        request.AddParameter(parameters[i]);
                    }
                }

                if (!typedObjManager.ExistsAction(actionName, controllerName))
                {
                    throw new Exception($"Action '{actionName}' not exists in controller '{controllerName}'");
                }

                return(request);
            }
            catch (Exception ex)
            {
                logger.WriteLog(ex.Message + "\n" + ex.StackTrace, controllerName, actionName, ServerLogType.ERROR);
                request.HasErrors            = true;
                request.InternalErrorMessage = ex.Message;
                return(request);
            }
        }