public List <CommandsActions> GetCommandsActions(string connectionName)
        {
            Database  db        = DatabaseFactory.CreateDatabase(connectionName);
            DbCommand dbCommand = db.GetStoredProcCommand(Resources.CommandsrestrictedResources.SP_GetCommandsRestricted);

            List <CommandsActions> commandsActionsList = new List <CommandsActions>();

            using (IDataReader dr = db.ExecuteReader(dbCommand))
            {
                int _id                 = dr.GetOrdinal(Resources.CommandsrestrictedResources.PARAM_ID);
                int _command            = dr.GetOrdinal(Resources.CommandsrestrictedResources.PARAM_COMMAND);
                int _modulename         = dr.GetOrdinal(Resources.CommandsrestrictedResources.PARAM_MODULENAME);
                int _message            = dr.GetOrdinal(Resources.CommandsrestrictedResources.PARAM_MESSAGE);
                int _commandtype        = dr.GetOrdinal(Resources.CommandsrestrictedResources.PARAM_COMMANDTYPE);
                int _modulesrc          = dr.GetOrdinal(Resources.CommandsrestrictedResources.PARAM_MODULESRC);
                int _allow              = dr.GetOrdinal(Resources.CommandsrestrictedResources.PARAM_ALLOW);
                int _commandsallowed    = dr.GetOrdinal("CommandsAllowed");
                int _commandsrestricted = dr.GetOrdinal("CommandsRestricted");

                while (dr.Read())
                {
                    CommandsActions item = new CommandsActions();
                    item.ID          = dr.GetInt32(_id);
                    item.Command     = dr.GetString(_command);
                    item.ModulesName = (dr[_modulename] == DBNull.Value) ? Types.StringNullValue : dr.GetString(_modulename);
                    item.Message     = (dr[_message] == DBNull.Value) ? Types.StringNullValue : dr.GetString(_message);
                    item.CommandType = dr.GetString(_commandtype);
                    item.ModuleSrc   = (dr[_modulesrc] == DBNull.Value) ? Types.StringNullValue : dr.GetString(_modulesrc);
                    item.Allow       = dr.GetBoolean(_allow);
                    if (dr[_commandsallowed] == DBNull.Value)
                    {
                        item.CommandsAllowed = new List <string>();
                    }
                    else
                    {
                        string[]      result     = dr.GetString(_commandsallowed).Split(new char[] { ',' });
                        List <string> listResult = new List <string>(result.Length);
                        listResult.AddRange(result);
                        item.CommandsAllowed = listResult;
                    }

                    if (dr[_commandsrestricted] == DBNull.Value)
                    {
                        item.CommandsRestricted = new List <string>();
                    }
                    else
                    {
                        string[]      result     = dr.GetString(_commandsrestricted).Split(new char[] { ',' });
                        List <string> listResult = new List <string>(result.Length);
                        listResult.AddRange(result);
                        item.CommandsRestricted = listResult;
                    }
                    commandsActionsList.Add(item);
                }
            }
            return(commandsActionsList);
        }
예제 #2
0
        public MainMenu() : base(screenName, commands, commandsActions)
        {
            if (Session.UserRole != Models.User.Roles.Admin && Session.UserRole != Models.User.Roles.SuperUser1 &&
                Session.UserRole != Models.User.Roles.SuperUser2 && Session.UserRole != Models.User.Roles.SuperUser3)
            {
                int indx = Commands.IndexOf("3");
                Commands.RemoveAt(indx);
                CommandsActions.RemoveAt(indx);
            }
            if (Session.UserRole != Models.User.Roles.Admin && Session.UserRole != Models.User.Roles.SuperUser2 && Session.UserRole != Models.User.Roles.SuperUser3)
            {
                int indx = Commands.IndexOf("4");
                Commands.RemoveAt(indx);
                CommandsActions.RemoveAt(indx);
            }
            if (Session.UserRole != Models.User.Roles.Admin && Session.UserRole != Models.User.Roles.SuperUser3)
            {
                int indx = Commands.IndexOf("5");
                Commands.RemoveAt(indx);
                CommandsActions.RemoveAt(indx);
            }
            if (Session.UserRole != Models.User.Roles.Admin)
            {
                int indx = Commands.IndexOf("6");
                Commands.RemoveAt(indx);
                CommandsActions.RemoveAt(indx);

                indx = Commands.IndexOf("7");
                Commands.RemoveAt(indx);
                CommandsActions.RemoveAt(indx);

                indx = Commands.IndexOf("8");
                Commands.RemoveAt(indx);
                CommandsActions.RemoveAt(indx);
            }

            PrintCommands();

            CheckCommand(Console.ReadLine());
        }
예제 #3
0
        private void SendMessageToHostCallBack(string command)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new SendMessageToHost(SendMessageToHostCallBack), command);
            }
            else
            {
                CommandsActions commandAction =
                    ListCommandsActions.Find(delegate(CommandsActions c)
                {
                    return(c.Command.Equals(command));
                });

                if (commandAction != null)
                {
                    if (commandAction.CommandType.Equals(COMMANDTYPE_MSG))
                    {
                        string msg = commandAction.Message;
                        //MessageBox.Show(msg);
                        CommandsAPI2.send_MessageToEmulator(msg);
                    }
                    else if (commandAction.CommandType.Equals(COMMANDTYPE_UC))
                    {
                        pnlMiddle.Controls.Clear();
                        pnlMiddle.Controls.Add(Loader.GetReferenceUserControl(commandAction.ModuleSrc));
                    }
                }
                else
                {
                    if (command.Contains("§"))
                    {
                        CommandsAPI2.send_MessageToEmulator("FORMATO NO DISPONIBLE");
                    }
                }
            }
        }
예제 #4
0
        public int tempSabreMarkupHandler(int messageType, string message, string properties)
        {
            int retcode = 0;

            try
            {
                if (message.Length > 30 && message.Substring(0, 3) == "EM<")
                {
                }
                else
                {
                    if (messageType.Equals(1))
                    {
                        //ValidateMarkups por default es true, cuando se ejecuta del lado
                        //de la aplicación es false
                        if (CommandsAPI.ValidateMarkups)
                        {
                            retcode = 2;
                            //Busca que el comando empiece con el que está registrado en la base de datos
                            CommandsActions commandAction =
                                ListCommandsActions.Find(delegate(CommandsActions c)
                            {
                                return(message.StartsWith(c.Command));
                            });
                            //Si Allow = false se valida el comando tal cual
                            if (commandAction != null)
                            {
                                if (!commandAction.Allow)
                                {
                                    retcode = 2;
                                }
                                else
                                {
                                    //Busca que el comando no contenga comandos restringidos
                                    string commandRestricted =
                                        commandAction.CommandsRestricted.Find(delegate(string c)
                                                                              { return(message.Contains(c)); });

                                    //si el comando contiene un comando restringido busca también que contenga comandos permitidos
                                    if (!string.IsNullOrEmpty(commandRestricted))
                                    {
                                        message = message.Replace(commandRestricted, string.Empty);
                                        string commandsAllowd = commandAction.CommandsAllowed.Find(delegate(string c)
                                                                                                   { return(message.Contains(c)); });

                                        if (!string.IsNullOrEmpty(commandsAllowd))
                                        {
                                            retcode = 0;
                                        }
                                    }
                                    else
                                    {
                                        string commandsAllowd = commandAction.CommandsAllowed.Find(delegate(string c)
                                                                                                   { return(message.Contains(c)); });

                                        if (!string.IsNullOrEmpty(commandsAllowd))
                                        {
                                            retcode = 0;
                                        }
                                    }
                                }
                            }
                            else
                            {
                                retcode = (message.Contains("§")) ? 2 : 0;
                            }

                            if (retcode.Equals(2))
                            {
                                ReceiverParams(message);
                            }
                        }
                    }

                    if (messageType.Equals(2))
                    {
                        retcode = 0;
                    }
                }
                return(retcode);
            }
            catch (Exception)
            {
            }

            return(retcode);
        }