private void RulesAppliedHandler(RuleList <ConditionalRenderingsRuleContext> ruleList, ConditionalRenderingsRuleContext ruleContext, RuleAction <ConditionalRenderingsRuleContext> action)
 {
     if (action.GetType().Name.StartsWith("SetRenderingVariantAction"))
     {
         _VariantId = (action as SetRenderingVariantAction <ConditionalRenderingsRuleContext>).VariantID;
     }
 }
Beispiel #2
0
        public IActionExecutor Create(RuleAction action)
        {
            if (action == null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var actionType = action.GetType();

            if (_executors.TryGetValue(actionType, out var executor))
            {
                return(executor);
            }
            throw new ArgumentOutOfRangeException($"Executor for type '{actionType}' doesn't exist.");
        }
Beispiel #3
0
 private void CreateWorkItemForAction(FolderEvaluationResult result, RuleAction action, int actionIndex)
 {
     if (action == null)
     {
         this.context.TraceError("Action is empty");
         return;
     }
     this.context.TraceDebug <Type>("Create work item for action {0}", action.GetType());
     if (action is RuleAction.InMailboxMove)
     {
         this.CreateWorkItemForInMailboxMove(result, (RuleAction.InMailboxMove)action, actionIndex);
         return;
     }
     if (action is RuleAction.ExternalMove)
     {
         this.CreateWorkItemForExternalMove(result, (RuleAction.ExternalMove)action, actionIndex);
         return;
     }
     if (action is RuleAction.InMailboxCopy)
     {
         this.CreateWorkItemForInMailboxCopy(result, (RuleAction.InMailboxCopy)action, actionIndex);
         return;
     }
     if (action is RuleAction.ExternalCopy)
     {
         this.CreateWorkItemForExternalCopy(result, (RuleAction.ExternalCopy)action, actionIndex);
         return;
     }
     if (action is RuleAction.Bounce)
     {
         this.CreateWorkItemForBounce(result, (RuleAction.Bounce)action);
         return;
     }
     if (action is RuleAction.Reply)
     {
         this.CreateWorkItemForReply(result, (RuleAction.Reply)action, actionIndex);
         return;
     }
     if (action is RuleAction.OOFReply)
     {
         this.CreateWorkItemForOofReply(result, (RuleAction.OOFReply)action, actionIndex);
         return;
     }
     if (action is RuleAction.Defer)
     {
         this.CreateWorkItemForDefer(result, (RuleAction.Defer)action, actionIndex);
         return;
     }
     if (action is RuleAction.Forward)
     {
         this.CreateWorkItemForForward(result, (RuleAction.Forward)action, actionIndex);
         return;
     }
     if (action is RuleAction.Delegate)
     {
         this.CreateWorkItemForDelegate(result, (RuleAction.Delegate)action, actionIndex);
         return;
     }
     if (action is RuleAction.Tag)
     {
         this.CreateWorkItemForTag(result, (RuleAction.Tag)action, actionIndex);
         return;
     }
     if (action is RuleAction.Delete)
     {
         this.CreateWorkItemForDelete(result, (RuleAction.Delete)action, actionIndex);
         return;
     }
     if (action is RuleAction.MarkAsRead)
     {
         this.CreateWorkItemForMarkAsRead(result, (RuleAction.MarkAsRead)action, actionIndex);
         return;
     }
     this.context.TraceError <RuleAction.Type>("Unsupported action type {0}", action.ActionType);
     this.context.MarkRuleInError(this.context.CurrentRule, action.ActionType, actionIndex, DeferredError.RuleError.Unknown);
 }
Beispiel #4
0
        private bool EvaluateRule(Rule rule, FolderEvaluationResult result)
        {
            if (rule == null)
            {
                throw new ArgumentNullException("rule");
            }
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
            if (rule.Actions == null)
            {
                throw new ArgumentException("Rule.Actions must not be null.");
            }
            this.context.CurrentRule = rule;
            this.context.NestedLevel = 0;
            this.context.TraceDebug <string>("Evaluate rule {0}", rule.Name);
            int  i = 0;
            bool result2;

            try
            {
                RuleUtil.FaultInjection((FaultInjectionLid)3102092605U);
                if (!RestrictionEvaluator.Evaluate(rule.Condition, this.context))
                {
                    result2 = false;
                }
                else
                {
                    this.context.TraceDebug <string>("Rule {0} evaluated to true", rule.Name);
                    if (this.context.HasRuleFiredBefore(rule))
                    {
                        this.context.TraceDebug <string>("Rule history loop detected on rule {0}", rule.Name);
                        result2 = false;
                    }
                    else
                    {
                        while (i < rule.Actions.Length)
                        {
                            RuleAction ruleAction = rule.Actions[i];
                            if (ruleAction == null)
                            {
                                this.context.TraceDebug <string, int>("For rule \"{0}\", action at index {1} is null.", rule.Name, i);
                            }
                            else
                            {
                                this.CreateWorkItemForAction(result, ruleAction, i++);
                                if (!result.ShouldContinue)
                                {
                                    this.context.TraceDebug <Type>("Stop evaluation process after action {0}", ruleAction.GetType());
                                    break;
                                }
                            }
                        }
                        result2 = true;
                    }
                }
            }
            catch (InvalidRuleException exception)
            {
                this.context.DisableAndMarkRuleInError(rule, rule.Actions[i].ActionType, i, DeferredError.RuleError.Parsing);
                this.context.RecordError(exception, ServerStrings.FolderRuleStageEvaluation);
                result2 = false;
            }
            return(result2);
        }