Exemplo n.º 1
0
        public bool CheckCommand(IExecutionContext context, IWorkerCommand workerCommand, Command command)
        {
            ArgUtil.NotNull(context, nameof(context));
            ArgUtil.NotNull(workerCommand, nameof(workerCommand));
            ArgUtil.NotNull(command, nameof(command));

            return(Check(
                       context,
                       (TaskRestrictions restrictions) => restrictions.IsCommandAllowed(workerCommand),
                       () => context.Warning(StringUtil.Loc("CommandNotAllowed", command.Area, command.Event))));
        }
Exemplo n.º 2
0
 public bool isCommandAllowed(IWorkerCommand command)
 {
     foreach (var attr in command.GetType().GetCustomAttributes(typeof(CommandRestrictionAttribute), false))
     {
         var cra = attr as CommandRestrictionAttribute;
         if (cra.AllowedInRestrictedMode)
         {
             return(true);
         }
     }
     return(false);
 }
        public void SimpleTests()
        {
            var            commandExt = new TestWorkerCommandExtensionL0();
            IWorkerCommand command    = commandExt.GetWorkerCommand("foo");

            Assert.Equal("foo", command.Name);
            Assert.IsType <FooCommand>(command);

            IWorkerCommand command2 = commandExt.GetWorkerCommand("bar");

            Assert.Equal("bar", command2.Name);
            IWorkerCommand command3 = commandExt.GetWorkerCommand("cat");

            Assert.Equal("bar", command3.Name);
            Assert.Equal(command2, command3);
        }
Exemplo n.º 4
0
        protected void InstallWorkerCommand(IWorkerCommand commandExecutor)
        {
            if (_commands.ContainsKey(commandExecutor.Name))
            {
                throw new Exception(StringUtil.Loc("CommandDuplicateDetected", commandExecutor.Name, CommandArea.ToLowerInvariant()));
            }
            _commands[commandExecutor.Name] = commandExecutor;
            var aliasList = commandExecutor.Aliases;

            if (aliasList != null)
            {
                foreach (var alias in commandExecutor.Aliases)
                {
                    if (_commands.ContainsKey(alias))
                    {
                        throw new Exception(StringUtil.Loc("CommandDuplicateDetected", alias, CommandArea.ToLowerInvariant()));
                    }
                    _commands[alias] = commandExecutor;
                }
            }
        }
Exemplo n.º 5
0
        public static Boolean IsCommandAllowed(this TaskRestrictions restrictions, IWorkerCommand command)
        {
            ArgUtil.NotNull(command, nameof(command));

            if (restrictions.Commands?.Mode == TaskCommandMode.Restricted)
            {
                foreach (var attr in command.GetType().GetCustomAttributes(typeof(CommandRestrictionAttribute), false))
                {
                    var cra = attr as CommandRestrictionAttribute;
                    if (cra.AllowedInRestrictedMode)
                    {
                        return(true);
                    }
                }

                return(false);
            }
            else
            {
                return(true);
            }
        }
Exemplo n.º 6
0
        protected void InstallWorkerCommand(IWorkerCommand commandExecutor)
        {
            if (_commands.ContainsKey(commandExecutor.Name))
            {
                //TODO: Add some logging (or throw exception)
                return;
            }
            _commands[commandExecutor.Name] = commandExecutor;
            var aliasList = commandExecutor.Aliases;

            if (aliasList != null)
            {
                foreach (var alias in commandExecutor.Aliases)
                {
                    if (!_commands.ContainsKey(alias))
                    {
                        _commands[alias] = commandExecutor;
                    }
                    // TODO: else add some logging (or throw exception)
                }
            }
        }
Exemplo n.º 7
0
 public bool isCommandAllowed(IWorkerCommand command)
 {
     return(true);
 }