Exemple #1
0
        public NotificationEventHandler(
            [NotNull] INotificationRuleRepository notificationRuleRepository,
            [NotNull] IRuleParser ruleParser,
            [NotNull] IRuleExecutorDirector ruleExecutorDirector,
            [NotNull] ILog log)
        {
            if (notificationRuleRepository == null)
            {
                throw new ArgumentNullException(nameof(notificationRuleRepository));
            }
            if (ruleParser == null)
            {
                throw new ArgumentNullException(nameof(ruleParser));
            }
            if (ruleExecutorDirector == null)
            {
                throw new ArgumentNullException(nameof(ruleExecutorDirector));
            }
            if (log == null)
            {
                throw new ArgumentNullException(nameof(log));
            }

            _notificationRuleRepository = notificationRuleRepository;
            _ruleParser           = ruleParser;
            _ruleExecutorDirector = ruleExecutorDirector;
            _log = log;
        }
Exemple #2
0
        public void SetUp()
        {
            this.ruleRepo     = MockRepository.GenerateStrictMock <IRuleRepo>();
            this.emailService = MockRepository.GenerateStrictMock <IEmailService>();
            this.ruleParser   = MockRepository.GenerateStrictMock <IRuleParser>();

            this.sender = new MailSender(this.ruleRepo, this.emailService, this.ruleParser);
        }
 public NotificationPollJob(
     INotificationRuleRepository notificationRuleRepository,
     IRuleParser ruleParser,
     IRuleExecutorDirector ruleExecutorDirector)
 {
     _notificationRuleRepository = notificationRuleRepository;
     _ruleParser           = ruleParser;
     _ruleExecutorDirector = ruleExecutorDirector;
 }
Exemple #4
0
        /// <summary>
        /// Feeds all tokens to the parser and returns the last result.
        /// </summary>
        private RuleResult FeedAll(IRuleParser parser, IEnumerable <Token> tokens)
        {
            RuleResult lastResult = default;

            foreach (Token t in tokens)
            {
                lastResult = parser.FeedToken(t);
            }

            return(lastResult);
        }
        public void SetUp()
        {
            var ruleParsers = new List <IRuleParser>
            {
                new UglyFlatRuleParser(),
                new CommentedFlatRuleParser(),
                new StragetyRuleParser(),
                new EasyTestStragetyRuleParser()
            };

            this.parser = ruleParsers[1];
        }
Exemple #6
0
        public void TestDynamicRuleCreation()
        {
            IRuleParser parser = RuleParser.GetInstance();

            string successAction;
            string failAction;
            IRule  rule = parser.CreateRule(Files.SourceCode1, out successAction, out failAction);

            Assert.IsNotNull(rule);
            Assert.AreEqual("TEST ID 123", rule.Id);
            Assert.AreEqual("PREDEFINE_ACTION_1", successAction);
            Assert.AreEqual("PREDEFINE_ACTION_2", failAction);
        }
        /// <summary>
        /// The host application must call this or no rewriting will take place
        /// </summary>
        /// <param name="log">Optional logger or null for logging to Trace output</param>
        /// <param name="forwardTracePredicate">A function that determines which urls to
        /// log traces for. If you have a specific URL that is not rewriting as you want then
        /// add that url to this list to log an execution trace through the rewriting rules</param>
        /// <param name="reverseTracePredicate">A list of the rewritten urls
        /// to log traces for. If your site it redirecting to an unexpected
        /// page and you want to know why it was redirected there, add the
        /// rewritten/redirected url to this list</param>
        /// <param name="factory">Pass a factory that can construct your
        /// custom actions and custom conditions using Dependency Injection. You
        /// can pass null if all of your custom extensions have a default public
        /// constructor</param>
        /// <param name="ruleStream">Pass the rewriting rules here. This allows you
        /// to store your rules wherever you want (in a database for example).
        /// You can also pass null to read rles from the RewriteRules.config
        /// file just like the Microsoft one does</param>
        /// <param name="ruleParser">Provide a custom parser to support your
        /// own rule syntax, or pass null for backward compatibility with
        /// the Microsoft IIS Rewriter module but with many more features</param>
        public static void Initialize(
            ILog log = null,
            Func <string, bool> forwardTracePredicate = null,
            Func <string, bool> reverseTracePredicate = null,
            IFactory factory       = null,
            Stream ruleStream      = null,
            IRuleParser ruleParser = null)
        {
            if (_factory == null)
            {
                if (factory == null)
                {
                    factory = new NinjectFactory();
                }
                _factory = factory;
            }

            if (_log == null)
            {
                if (log == null)
                {
                    log = _factory.Create <ILog>();
                }
                _log = log;
            }

            if (ruleStream == null)
            {
                var filePath = HttpContext.Current.Server.MapPath("~/RewriteRules.config");
                ruleStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            }

            try
            {
                SetRules(LoadRules(ruleStream, null, ruleParser));
            }
            finally
            {
                ruleStream.Close();
            }

            DescribeRulesToTrace();

#if !TRACE_ALL
            _forwardTracePredicate = forwardTracePredicate;
            _reverseTracePredicate = reverseTracePredicate;
            _tracingEnabled        = forwardTracePredicate != null || reverseTracePredicate != null;
#endif
        }
        /// <summary>
        /// Parses rules from a stream
        /// </summary>
        /// <param name="stream">The stream to read rules from</param>
        /// <param name="encoding">The text encoding used in this stream, or null for UTF8</param>
        /// <param name="ruleParser">A custom parser, or null to use the default parser</param>
        /// <returns></returns>
        public static IRuleList LoadRules(
            Stream stream,
            Encoding encoding      = null,
            IRuleParser ruleParser = null)
        {
            if (stream == null)
            {
                return(null);
            }

            encoding = encoding ?? Encoding.UTF8;
            var parser = ruleParser ?? _factory.Create <StandardRuleParser>();

            return(parser.Parse(stream, encoding));
        }
        public PolicyCheckEventHandler(
            [NotNull] ITaskRepository taskRepository,
            [NotNull] IPolicyRuleRepository policyRuleRepository,
            [NotNull] IRuleExecutorDirector ruleExecutorDirector,
            [NotNull] IEventProvider eventProvider,
            [NotNull] IRuleParser ruleParser,
            [NotNull] ILog logger,
            [NotNull] ITelemetryScopeProvider telemetryScopeProvider)
        {
            if (taskRepository == null)
            {
                throw new ArgumentNullException(nameof(taskRepository));
            }
            if (policyRuleRepository == null)
            {
                throw new ArgumentNullException(nameof(policyRuleRepository));
            }
            if (ruleExecutorDirector == null)
            {
                throw new ArgumentNullException(nameof(ruleExecutorDirector));
            }
            if (eventProvider == null)
            {
                throw new ArgumentNullException(nameof(eventProvider));
            }
            if (ruleParser == null)
            {
                throw new ArgumentNullException(nameof(ruleParser));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }
            if (telemetryScopeProvider == null)
            {
                throw new ArgumentNullException(nameof(telemetryScopeProvider));
            }

            _taskRepository       = taskRepository;
            _policyRuleRepository = policyRuleRepository;
            _ruleExecutorDirector = ruleExecutorDirector;
            _eventProvider        = eventProvider;
            _ruleParser           = ruleParser;
            _logger = logger;
            _telemetryScopeProvider = telemetryScopeProvider;
        }
        public void CombinedTests()
        {
            // Assemble
            var ruleParsers = new List <IRuleParser>
            {
                new UglyFlatRuleParser(),
                new CommentedFlatRuleParser(),
                new StragetyRuleParser(),
                new EasyTestStragetyRuleParser()
            };

            // Act
            // Assert
            ruleParsers.ForEach(
                rp =>
            {
                this.parser = rp;
                this.ParseRulesReturnsCorrectRules();
            });
        }
Exemple #11
0
        public RuleResult FeedToken(Token t)
        {
            if (_isFinished)
            {
                throw new Exception("Tried to feed a token to an already-finished ThenChainParser.");
            }

            var currentCallabck = _ruleSequence[_currentRuleIndex].onMatched;

            // HACK: Create the first rule, if it hasn't been already.
            if (_currentRule == null)
            {
                _currentRule = _ruleSequence[_currentRuleIndex].ruleFactory();
            }

            // Feed the token to the current rule
            var result = _currentRule.FeedToken(t);

            // If it failed, cascade that failure upwards
            if (result.status == RuleStatus.Failed)
            {
                return(result);
            }

            // If it succeeded, invoke the callback and move to the next rule
            if (result.status == RuleStatus.Complete)
            {
                currentCallabck(result.node);
                _currentRuleIndex++;

                // If the last rule just succeeded, the whole chain is complete.
                if (_currentRuleIndex >= _ruleSequence.Count)
                {
                    _isFinished = true;
                    return(RuleResult.Complete(_node));
                }
                _currentRule = _ruleSequence[_currentRuleIndex].ruleFactory();
            }

            return(RuleResult.GoodSoFar());
        }
        public WorkflowEventHandler(
            [NotNull] IWorkflowRuleRepository workflowRuleRepository,
            [NotNull] IRuleParser ruleParser,
            [NotNull] IRuleExecutorDirector ruleExecutorDirector)
        {
            if (workflowRuleRepository == null)
            {
                throw new ArgumentNullException(nameof(workflowRuleRepository));
            }
            if (ruleParser == null)
            {
                throw new ArgumentNullException(nameof(ruleParser));
            }
            if (ruleExecutorDirector == null)
            {
                throw new ArgumentNullException(nameof(ruleExecutorDirector));
            }

            _workflowRuleRepository = workflowRuleRepository;
            _ruleParser             = ruleParser;
            _ruleExecutorDirector   = ruleExecutorDirector;
        }
Exemple #13
0
 public RuleBuilder(string rules, IRuleParser parser)
 {
     _rules  = rules;
     _parser = parser;
 }
Exemple #14
0
 /// <summary>
 /// Initializes a new instance of the MailSender class.
 /// </summary>
 /// <param name="ruleRepo">Repository to handle persistence of MailRules.</param>
 /// <param name="emailService">Service to send emails.</param>
 /// <param name="ruleParser">Parser to determine which MailRules should be sent.</param>
 public MailSender(IRuleRepo ruleRepo, IEmailService emailService, IRuleParser ruleParser)
 {
     this.ruleRepo     = ruleRepo;
     this.emailService = emailService;
     this.ruleParser   = ruleParser;
 }
Exemple #15
0
 public void Reset()
 {
     _currentRuleIndex = 0;
     _currentRule      = _ruleSequence[0].ruleFactory();
     _isFinished       = false;
 }