Exemplo n.º 1
0
        public override bool AllowsExecutionOf(object command)
        {
            var requestedCommandName = GetRequestedCommandName(command);

            return((from subjectAlias in subjectCleaner.AliasesFor(AllowedSubject)
                    from actionAlias in actionCleaner.AliasesFor(AllowedAction)
                    where Regex.IsMatch(requestedCommandName, actionAlias, RegexOptions.IgnoreCase) &&
                    Regex.IsMatch(requestedCommandName, subjectAlias, RegexOptions.IgnoreCase)
                    select subjectAlias)
                   .Any());
        }
Exemplo n.º 2
0
        public bool AllowsExecutionOf(object command)
        {
            var requestedCommand = command.GetType().Name;

            //I prefer foreach over LINQ in this case
            foreach (var actionAlias in actionCleaner.AliasesFor(Action))
            {
                foreach (var commandConvention in commandConventions)
                {
                    var allowedCommand =
                        commandConvention
                        .Replace("{action}", actionAlias == "manage" ? ".+" : actionAlias)
                        .Replace("{subject}", Subject == "all" ? ".+" : Subject);

                    if (Regex.IsMatch(requestedCommand, allowedCommand, RegexOptions.IgnoreCase))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }