private List <RequestParameter> NewFillParameters(ref List <RequestParameter> parameters,
                                                          ref string action, ref IController controller)
        {
            MethodInfo method = controller.GetType().GetMethod(action);

            foreach (RequestParameter requestParameter in parameters)
            {
                try
                {
                    ParameterInfo parameterInfo = method
                                                  .GetParameters()
                                                  .FirstOrDefault(p => p.Name.Equals(requestParameter.Name));

                    if (parameterInfo == null)
                    {
                        continue;
                    }

                    if (IsSimpleType(parameterInfo.ParameterType) ||
                        parameterInfo.ParameterType == typeof(List <>) ||
                        parameterInfo.ParameterType.Name.Contains("List"))
                    {
                        RequestParameter tmpParameter = GetRequestParameterFromType(parameterInfo,
                                                                                    requestParameter.Name, requestParameter.Value + "");
                        requestParameter.Value = tmpParameter.Value;
                    }
                    else
                    {
                        ModelRegister model = modelsManager.GetModelRegister(parameterInfo.ParameterType.ToString());
                        if (model == null)
                        {
                            throw new Exception($"Model type '{parameterInfo.ParameterType}', in '{controller.GetType().Name}/{action}' not found or not registered");
                        }

                        using (StringReader sr = new StringReader(requestParameter.Value + ""))
                        {
                            using (JsonReader jr = new JsonTextReader(sr))
                            {
                                JsonSerializer js = new JsonSerializer();
                                js.ApplyCustomSettings();
                                requestParameter.Value = js.Deserialize(jr, parameterInfo.ParameterType);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    logger.WriteLog($"Could not convert parameter '{requestParameter.Name}', required in action '{action}' of controller '{controller.GetType().Name}'. The reason is: {ex.Message}", ServerLogType.ERROR);
                    requestParameter.Value = null;
                }
            }

            return(parameters);
        }
        private List <RequestParameter> LegacyFillParameters(ref List <RequestParameter> parameters,
                                                             ref string action, ref IController controller)
        {
            string msg = "You are using an old version of the native client for the server, or the format of the parameters is out of date. The framework will use the hourly backward compatibility mode, but in future versions support for this parameter format will be discontinued.";

            logger.WriteLog(msg, ServerLogType.ALERT);
            ServerAlertManager.CreateAlert(new ServerAlert(controller.GetType().Name, action, msg));
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine(msg);
            Console.ForegroundColor = ConsoleColor.White;

            object entityParameterObject      = null;
            HashSet <RequestParameter> result = new HashSet <RequestParameter>();
            MethodInfo       method           = controller.GetType().GetMethod(action);
            RequestParameter requestParameter = null;
            string           currentAlias     = null;

            foreach (RequestParameter parameter in parameters)
            {
                string pName  = parameter.Name;
                string pValue = Convert.ToString(parameter.Value);

                foreach (ParameterInfo pInfo in method.GetParameters())
                {
                    if (parameter.IsComplexType() && !IsSimpleType(pInfo.ParameterType))
                    {
                        ObjectRequestParameter objectRequestParameter = GetObjectParameterType(pName, action, controller.GetType().Name);
                        if (currentAlias != objectRequestParameter.Alias)
                        {
                            currentAlias     = objectRequestParameter.Alias;
                            requestParameter = null;
                            ModelRegister model = modelsManager.GetModelRegister(objectRequestParameter.TypeName);
                            if (model == null)
                            {
                                throw new Exception($"Model type '{objectRequestParameter.TypeName}' not found or not registered");
                            }

                            //instantiate object parameter (public ctor)
                            entityParameterObject = Activator.CreateInstance(model.ModelType);
                        }
                        //requestParameter for a complex type object
                        if (requestParameter == null)
                        {
                            requestParameter = new RequestParameter(parameter.GetAliasName(), entityParameterObject);
                        }
                        FillProperty(entityParameterObject, parameter.GetParameterProperyName(), pValue);
                        break;
                    }

                    //requestParameter for simple type object
                    requestParameter = GetRequestParameterFromType(pInfo, pName, pValue);
                    if (requestParameter != null)
                    {
                        break;
                    }
                }

                if (requestParameter != null)
                {
                    result.Add(requestParameter);
                }
            }
            return(result.ToList());
        }
 internal void AddParameter(RequestParameter parameter)
 {
     requestParameters.Add(parameter);
 }