Ejemplo n.º 1
0
        internal static void ExecuteRuleSet(IList<RuleState> orderedRules, RuleExecution ruleExecution, Tracer tracer, string trackingKey)
        {
            // keep track of rule execution
            long[] executionCount = new long[orderedRules.Count];
            bool[] satisfied = new bool[orderedRules.Count];
            // clear the halted flag
            ruleExecution.Halted = false;

            ActivityExecutionContext activityExecutionContext = ruleExecution.ActivityExecutionContext;

            // loop until we hit the end of the list
            int current = 0;
            while (current < orderedRules.Count)
            {
                RuleState currentRuleState = orderedRules[current];

                // does this rule need to be evaluated?
                if (!satisfied[current])
                {
                    // yes, so evaluate it and determine the list of actions needed
                    if (tracer != null)
                        tracer.StartRule(currentRuleState.Rule.Name);
                    satisfied[current] = true;
                    bool result = currentRuleState.Rule.Condition.Evaluate(ruleExecution);
                    if (tracer != null)
                        tracer.RuleResult(currentRuleState.Rule.Name, result);
                    if (activityExecutionContext != null && currentRuleState.Rule.Name != null)
                        activityExecutionContext.TrackData(trackingKey, new RuleActionTrackingEvent(currentRuleState.Rule.Name, result));

                    ICollection<RuleAction> actions = (result) ?
                        currentRuleState.Rule.thenActions :
                        currentRuleState.Rule.elseActions;
                    ICollection<int> activeRules = result ?
                        currentRuleState.ThenActionsActiveRules :
                        currentRuleState.ElseActionsActiveRules;

                    // are there any actions to be performed?
                    if ((actions != null) && (actions.Count > 0))
                    {
                        ++executionCount[current];
                        string ruleName = currentRuleState.Rule.Name;
                        if (tracer != null)
                            tracer.StartActions(ruleName, result);

                        // evaluate the actions
                        foreach (RuleAction action in actions)
                        {
                            action.Execute(ruleExecution);

                            // was Halt executed?
                            if (ruleExecution.Halted)
                                break;
                        }

                        // was Halt executed?
                        if (ruleExecution.Halted)
                            break;

                        // any fields updated?
                        if (activeRules != null)
                        {
                            foreach (int updatedRuleIndex in activeRules)
                            {
                                RuleState rs = orderedRules[updatedRuleIndex];
                                if (satisfied[updatedRuleIndex])
                                {
                                    // evaluate at least once, or repeatedly if appropriate
                                    if ((executionCount[updatedRuleIndex] == 0) || (rs.Rule.ReevaluationBehavior == RuleReevaluationBehavior.Always))
                                    {
                                        if (tracer != null)
                                            tracer.TraceUpdate(ruleName, rs.Rule.Name);
                                        satisfied[updatedRuleIndex] = false;
                                        if (updatedRuleIndex < current)
                                            current = updatedRuleIndex;
                                    }
                                }
                            }
                        }
                        continue;

                    }
                }
                ++current;
            }
            // no more rules to execute, so we are done
        }
Ejemplo n.º 2
0
        internal static void ExecuteRuleSet(IList <RuleState> orderedRules, RuleExecution ruleExecution, Tracer tracer, string trackingKey)
        {
            long[] numArray  = new long[orderedRules.Count];
            bool[] flagArray = new bool[orderedRules.Count];
            ruleExecution.Halted = false;
            ActivityExecutionContext activityExecutionContext = ruleExecution.ActivityExecutionContext;
            int index = 0;

            while (index < orderedRules.Count)
            {
                RuleState state = orderedRules[index];
                if (!flagArray[index])
                {
                    if (tracer != null)
                    {
                        tracer.StartRule(state.Rule.Name);
                    }
                    flagArray[index] = true;
                    bool result = state.Rule.Condition.Evaluate(ruleExecution);
                    if (tracer != null)
                    {
                        tracer.RuleResult(state.Rule.Name, result);
                    }
                    if ((activityExecutionContext != null) && (state.Rule.Name != null))
                    {
                        activityExecutionContext.TrackData(trackingKey, new RuleActionTrackingEvent(state.Rule.Name, result));
                    }
                    ICollection <RuleAction> is2 = result ? state.Rule.thenActions : state.Rule.elseActions;
                    ICollection <int>        is3 = result ? state.ThenActionsActiveRules : state.ElseActionsActiveRules;
                    if ((is2 != null) && (is2.Count > 0))
                    {
                        numArray[index] += 1L;
                        string name = state.Rule.Name;
                        if (tracer != null)
                        {
                            tracer.StartActions(name, result);
                        }
                        foreach (RuleAction action in is2)
                        {
                            action.Execute(ruleExecution);
                            if (ruleExecution.Halted)
                            {
                                break;
                            }
                        }
                        if (ruleExecution.Halted)
                        {
                            return;
                        }
                        if (is3 != null)
                        {
                            foreach (int num2 in is3)
                            {
                                RuleState state2 = orderedRules[num2];
                                if (flagArray[num2] && ((numArray[num2] == 0L) || (state2.Rule.ReevaluationBehavior == RuleReevaluationBehavior.Always)))
                                {
                                    if (tracer != null)
                                    {
                                        tracer.TraceUpdate(name, state2.Rule.Name);
                                    }
                                    flagArray[num2] = false;
                                    if (num2 < index)
                                    {
                                        index = num2;
                                    }
                                }
                            }
                        }
                        continue;
                    }
                }
                index++;
            }
        }
Ejemplo n.º 3
0
        internal static void ExecuteRuleSet(IList <RuleState> orderedRules, RuleExecution ruleExecution, Tracer tracer, string trackingKey)
        {
            // keep track of rule execution
            long[] executionCount = new long[orderedRules.Count];
            bool[] satisfied      = new bool[orderedRules.Count];
            // clear the halted flag
            ruleExecution.Halted = false;

            //ActivityExecutionContext activityExecutionContext = ruleExecution.ActivityExecutionContext;

            // loop until we hit the end of the list
            int current = 0;

            while (current < orderedRules.Count)
            {
                RuleState currentRuleState = orderedRules[current];

                // does this rule need to be evaluated?
                if (!satisfied[current])
                {
                    // yes, so evaluate it and determine the list of actions needed
                    if (tracer != null)
                    {
                        tracer.StartRule(currentRuleState.Rule.Name);
                    }
                    satisfied[current] = true;
                    bool result = currentRuleState.Rule.Condition.Evaluate(ruleExecution);
                    if (tracer != null)
                    {
                        tracer.RuleResult(currentRuleState.Rule.Name, result);
                    }

                    ICollection <RuleAction> actions = (result) ?
                                                       currentRuleState.Rule.thenActions :
                                                       currentRuleState.Rule.elseActions;
                    ICollection <int> activeRules = result ?
                                                    currentRuleState.ThenActionsActiveRules :
                                                    currentRuleState.ElseActionsActiveRules;

                    // are there any actions to be performed?
                    if ((actions != null) && (actions.Count > 0))
                    {
                        ++executionCount[current];
                        string ruleName = currentRuleState.Rule.Name;
                        if (tracer != null)
                        {
                            tracer.StartActions(ruleName, result);
                        }

                        // evaluate the actions
                        foreach (RuleAction action in actions)
                        {
                            action.Execute(ruleExecution);

                            // was Halt executed?
                            if (ruleExecution.Halted)
                            {
                                break;
                            }
                        }

                        // was Halt executed?
                        if (ruleExecution.Halted)
                        {
                            break;
                        }

                        // any fields updated?
                        if (activeRules != null)
                        {
                            foreach (int updatedRuleIndex in activeRules)
                            {
                                RuleState rs = orderedRules[updatedRuleIndex];
                                if (satisfied[updatedRuleIndex])
                                {
                                    // evaluate at least once, or repeatedly if appropriate
                                    if ((executionCount[updatedRuleIndex] == 0) || (rs.Rule.ReevaluationBehavior == RuleReevaluationBehavior.Always))
                                    {
                                        if (tracer != null)
                                        {
                                            tracer.TraceUpdate(ruleName, rs.Rule.Name);
                                        }
                                        satisfied[updatedRuleIndex] = false;
                                        if (updatedRuleIndex < current)
                                        {
                                            current = updatedRuleIndex;
                                        }
                                    }
                                }
                            }
                        }
                        continue;
                    }
                }
                ++current;
            }
            // no more rules to execute, so we are done
        }
 internal static void ExecuteRuleSet(IList<RuleState> orderedRules, RuleExecution ruleExecution, Tracer tracer, string trackingKey)
 {
     long[] numArray = new long[orderedRules.Count];
     bool[] flagArray = new bool[orderedRules.Count];
     ruleExecution.Halted = false;
     ActivityExecutionContext activityExecutionContext = ruleExecution.ActivityExecutionContext;
     int index = 0;
     while (index < orderedRules.Count)
     {
         RuleState state = orderedRules[index];
         if (!flagArray[index])
         {
             if (tracer != null)
             {
                 tracer.StartRule(state.Rule.Name);
             }
             flagArray[index] = true;
             bool result = state.Rule.Condition.Evaluate(ruleExecution);
             if (tracer != null)
             {
                 tracer.RuleResult(state.Rule.Name, result);
             }
             if ((activityExecutionContext != null) && (state.Rule.Name != null))
             {
                 activityExecutionContext.TrackData(trackingKey, new RuleActionTrackingEvent(state.Rule.Name, result));
             }
             ICollection<RuleAction> is2 = result ? state.Rule.thenActions : state.Rule.elseActions;
             ICollection<int> is3 = result ? state.ThenActionsActiveRules : state.ElseActionsActiveRules;
             if ((is2 != null) && (is2.Count > 0))
             {
                 numArray[index] += 1L;
                 string name = state.Rule.Name;
                 if (tracer != null)
                 {
                     tracer.StartActions(name, result);
                 }
                 foreach (RuleAction action in is2)
                 {
                     action.Execute(ruleExecution);
                     if (ruleExecution.Halted)
                     {
                         break;
                     }
                 }
                 if (ruleExecution.Halted)
                 {
                     return;
                 }
                 if (is3 != null)
                 {
                     foreach (int num2 in is3)
                     {
                         RuleState state2 = orderedRules[num2];
                         if (flagArray[num2] && ((numArray[num2] == 0L) || (state2.Rule.ReevaluationBehavior == RuleReevaluationBehavior.Always)))
                         {
                             if (tracer != null)
                             {
                                 tracer.TraceUpdate(name, state2.Rule.Name);
                             }
                             flagArray[num2] = false;
                             if (num2 < index)
                             {
                                 index = num2;
                             }
                         }
                     }
                 }
                 continue;
             }
         }
         index++;
     }
 }