internal ObjectRequestParameter GetObjectParameterType(string requestParameter, string actionName,
                                                               string controllerName)
        {
            try
            {
                ControllerRegister register = controllerManager.GetControllerRegister(controllerName);

                Type       type   = register.Type;
                MethodInfo method = type.GetMethods().FirstOrDefault(m => m.Name.Equals(actionName));
                if (method == null)
                {
                    return(null);
                }

                if (!requestParameter.Contains("."))
                {
                    return(null);
                }

                string parameter = requestParameter.Substring(0, requestParameter.IndexOf("."));

                ParameterInfo parameterInfo = method.GetParameters().FirstOrDefault(p => p.Name.Equals(parameter));
                return(new ObjectRequestParameter(parameterInfo.Name, parameterInfo.ParameterType.FullName));
            }
            catch (Exception ex)
            {
                logger.WriteLog($"*** CHECK PARAMETER '{requestParameter}' FOR ACTION '{controllerName}.{actionName}' ERROR: *** \n{ex.Message}",
                                controllerName, actionName, ServerLogType.ERROR);
                return(null);
            }
        }
        private List <string> ListActions(string controllerName)
        {
            List <string> result = new List <string>();

            try
            {
                ControllerRegister register = controllerManager.GetControllerRegister(controllerName);

                Type type = register.Type;
                foreach (var method in type.GetMethods())
                {
                    if (method.GetCustomAttribute <NotListed>() != null)
                    {
                        continue;
                    }

                    if (method.ReturnType == typeof(ActionResult) ||
                        method.GetCustomAttribute <ServerAction>() != null)
                    {
                        result.Add(method.Name);
                    }
                }

                return(result);
            }
            catch (Exception ex)
            {
                return(new List <string>());
            }
        }
        public void SendCommandDirectyToLCDController(ControllerRegister Register, byte[] Data)
        {
            List <byte> _bytes = new List <byte>();

            _bytes.Add(Convert.ToByte(Register));
            _bytes.AddRange(Data);
            this.SendCommand(Commands.SEND_COMMAND_DIRECTLY_TO_LCD_CONTROLLER, _bytes.ToArray());
        }
        private void WriteControllerClient(ControllerRegister controller)
        {
            Console.WriteLine($"Writing '{controller.Name}'...");
            string customUsing = "";

            foreach (string customNamespace in customNamespacesUsing)
            {
                customUsing += $"using {customNamespace};\n";
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine($@"using System;
using System.Collections.Generic;
using System.Text;
using SocketAppServerClient;

{customUsing}

namespace {targetNamespace} 
{{
    public class {controller.Name}
    {{");

            Type cType = controller.Type;

            foreach (var method in cType.GetMethods())
            {
                if (!IsValidMethod(method, controller.Name))
                {
                    continue;
                }

                string parameters = GetMethodParameters(method);

                string methodDeclaration = $@"        public {GetTypeDescription(method.ReturnType)} {method.Name}({parameters})
        {{
{GetMethodBody(controller.Name, method)}
        }}
";

                sb.AppendLine(methodDeclaration);
                Console.WriteLine($"    Action '{method.Name}' included.");
            }

            sb.AppendLine("    }");
            sb.AppendLine("}");

            File.WriteAllText($@"{targetDirectory}\{controller.Name}.cs", sb.ToString());
        }
        internal bool ExistsAction(string actionName, string controllerName)
        {
            try
            {
                ControllerRegister register = controllerManager.GetControllerRegister(controllerName);

                Type       type   = register.Type;
                MethodInfo method = type.GetMethod(actionName);

                return(true);
            }
            catch (Exception ex)
            {
                logger.WriteLog($"*** CHECK ACTION '{controllerName}.{actionName}' ERROR: *** \n {ex.Message}",
                                controllerName, actionName, ServerLogType.ERROR);
                return(false);
            }
        }
        public List <string> GetActionParameters(string controller,
                                                 string action)
        {
            ControllerRegister register = controllerManager.GetControllerRegister(controller);

            if (register == null)
            {
                return(new List <string>());
            }
            MethodInfo method = register.Type.GetMethod(action);

            if (method == null)
            {
                return(new List <string>());
            }
            return(method
                   .GetParameters()
                   .Select(p => p.Name)
                   .ToList());
        }
        private ControllerInfo GetControllerInfo(string controllerName)
        {
            try
            {
                ControllerRegister register = controllerManager.GetControllerRegister(controllerName);

                Type type = register.Type;

                ControllerInfo info = new ControllerInfo();
                info.ControllerName    = controllerName;
                info.ControllerActions = ListActions(controllerName);
                info.ControllerClass   = type.FullName;

                return(info);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }