Example #1
0
        private static void AnalyzeRules(RuleChainingBehavior behavior, List <RuleState> ruleStates, RuleValidation validation, Tracer tracer)
        {
            int count = ruleStates.Count;

            if (behavior != RuleChainingBehavior.None)
            {
                RuleSymbolInfo[] ruleSymbols = new RuleSymbolInfo[count];
                int index = 0;
                while (index < count)
                {
                    ruleSymbols[index] = AnalyzeRule(behavior, ruleStates[index].Rule, validation, tracer);
                    index++;
                }
                for (index = 0; index < count; index++)
                {
                    RuleState state = ruleStates[index];
                    if (ruleSymbols[index].thenSideEffects != null)
                    {
                        state.ThenActionsActiveRules = AnalyzeSideEffects(ruleSymbols[index].thenSideEffects, ruleSymbols);
                        if ((state.ThenActionsActiveRules != null) && (tracer != null))
                        {
                            tracer.TraceThenTriggers(state.Rule.Name, state.ThenActionsActiveRules, ruleStates);
                        }
                    }
                    if (ruleSymbols[index].elseSideEffects != null)
                    {
                        state.ElseActionsActiveRules = AnalyzeSideEffects(ruleSymbols[index].elseSideEffects, ruleSymbols);
                        if ((state.ElseActionsActiveRules != null) && (tracer != null))
                        {
                            tracer.TraceElseTriggers(state.Rule.Name, state.ElseActionsActiveRules, ruleStates);
                        }
                    }
                }
            }
        }
Example #2
0
        private static RuleSymbolInfo AnalyzeRule(RuleChainingBehavior behavior, Rule rule, RuleValidation validator, Tracer tracer)
        {
            RuleSymbolInfo info = new RuleSymbolInfo();

            if (rule.Condition != null)
            {
                info.conditionDependencies = rule.Condition.GetDependencies(validator);
                if ((info.conditionDependencies != null) && (tracer != null))
                {
                    tracer.TraceConditionSymbols(rule.Name, info.conditionDependencies);
                }
            }
            if (rule.thenActions != null)
            {
                info.thenSideEffects = GetActionSideEffects(behavior, rule.thenActions, validator);
                if ((info.thenSideEffects != null) && (tracer != null))
                {
                    tracer.TraceThenSymbols(rule.Name, info.thenSideEffects);
                }
            }
            if (rule.elseActions != null)
            {
                info.elseSideEffects = GetActionSideEffects(behavior, rule.elseActions, validator);
                if ((info.elseSideEffects != null) && (tracer != null))
                {
                    tracer.TraceElseSymbols(rule.Name, info.elseSideEffects);
                }
            }
            return(info);
        }
Example #3
0
        private static void AnalyzeRules(RuleChainingBehavior behavior, List <RuleState> ruleStates, RuleValidation validation, Tracer tracer)
        {
            int i;
            int numRules = ruleStates.Count;

            // if no chaining is required, then nothing to do
            if (behavior == RuleChainingBehavior.None)
            {
                return;
            }

            // Analyze all the rules and collect all the dependencies & side-effects
            RuleSymbolInfo[] ruleSymbols = new RuleSymbolInfo[numRules];
            for (i = 0; i < numRules; ++i)
            {
                ruleSymbols[i] = AnalyzeRule(behavior, ruleStates[i].Rule, validation, tracer);
            }

            for (i = 0; i < numRules; ++i)
            {
                RuleState currentRuleState = ruleStates[i];

                if (ruleSymbols[i].thenSideEffects != null)
                {
                    currentRuleState.ThenActionsActiveRules = AnalyzeSideEffects(ruleSymbols[i].thenSideEffects, ruleSymbols);

                    if ((currentRuleState.ThenActionsActiveRules != null) && (tracer != null))
                    {
                        tracer.TraceThenTriggers(currentRuleState.Rule.Name, currentRuleState.ThenActionsActiveRules, ruleStates);
                    }
                }

                if (ruleSymbols[i].elseSideEffects != null)
                {
                    currentRuleState.ElseActionsActiveRules = AnalyzeSideEffects(ruleSymbols[i].elseSideEffects, ruleSymbols);

                    if ((currentRuleState.ElseActionsActiveRules != null) && (tracer != null))
                    {
                        tracer.TraceElseTriggers(currentRuleState.Rule.Name, currentRuleState.ElseActionsActiveRules, ruleStates);
                    }
                }
            }
        }
Example #4
0
        private static RuleSymbolInfo AnalyzeRule(RuleChainingBehavior behavior, Rule rule, RuleValidation validator, Tracer tracer)
        {
            RuleSymbolInfo rsi = new RuleSymbolInfo();

            if (rule.Condition != null)
            {
                rsi.conditionDependencies = rule.Condition.GetDependencies(validator);

                if ((rsi.conditionDependencies != null) && (tracer != null))
                    tracer.TraceConditionSymbols(rule.Name, rsi.conditionDependencies);
            }

            if (rule.thenActions != null)
            {
                rsi.thenSideEffects = GetActionSideEffects(behavior, rule.thenActions, validator);

                if ((rsi.thenSideEffects != null) && (tracer != null))
                    tracer.TraceThenSymbols(rule.Name, rsi.thenSideEffects);
            }

            if (rule.elseActions != null)
            {
                rsi.elseSideEffects = GetActionSideEffects(behavior, rule.elseActions, validator);

                if ((rsi.elseSideEffects != null) && (tracer != null))
                    tracer.TraceElseSymbols(rule.Name, rsi.elseSideEffects);
            }

            return rsi;
        }
Example #5
0
        private static ICollection<int> AnalyzeSideEffects(ICollection<string> sideEffects, RuleSymbolInfo[] ruleSymbols)
        {
            Dictionary<int, object> affectedRules = new Dictionary<int, object>();

            for (int i = 0; i < ruleSymbols.Length; ++i)
            {
                ICollection<string> dependencies = ruleSymbols[i].conditionDependencies;
                if (dependencies == null)
                {
                    continue;
                }

                foreach (string sideEffect in sideEffects)
                {
                    bool match = false;

                    if (sideEffect.EndsWith("*", StringComparison.Ordinal))
                    {
                        foreach (string dependency in dependencies)
                        {
                            if (dependency.EndsWith("*", StringComparison.Ordinal))
                            {
                                // Strip the trailing "/*" from the dependency
                                string stripDependency = dependency.Substring(0, dependency.Length - 2);
                                // Strip the trailing "*" from the side-effect
                                string stripSideEffect = sideEffect.Substring(0, sideEffect.Length - 1);

                                string shortString;
                                string longString;

                                if (stripDependency.Length < stripSideEffect.Length)
                                {
                                    shortString = stripDependency;
                                    longString = stripSideEffect;
                                }
                                else
                                {
                                    shortString = stripSideEffect;
                                    longString = stripDependency;
                                }

                                // There's a match if the shorter string is a prefix of the longer string.
                                if (longString.StartsWith(shortString, StringComparison.Ordinal))
                                {
                                    match = true;
                                    break;
                                }
                            }
                            else
                            {
                                string stripSideEffect = sideEffect.Substring(0, sideEffect.Length - 1);
                                string stripDependency = dependency;
                                if (stripDependency.EndsWith("/", StringComparison.Ordinal))
                                    stripDependency = stripDependency.Substring(0, stripDependency.Length - 1);
                                if (stripDependency.StartsWith(stripSideEffect, StringComparison.Ordinal))
                                {
                                    match = true;
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        // The side-effect did not end with a wildcard
                        foreach (string dependency in dependencies)
                        {
                            if (dependency.EndsWith("*", StringComparison.Ordinal))
                            {
                                // Strip the trailing "/*"
                                string stripDependency = dependency.Substring(0, dependency.Length - 2);

                                string shortString;
                                string longString;

                                if (stripDependency.Length < sideEffect.Length)
                                {
                                    shortString = stripDependency;
                                    longString = sideEffect;
                                }
                                else
                                {
                                    shortString = sideEffect;
                                    longString = stripDependency;
                                }

                                // There's a match if the shorter string is a prefix of the longer string.
                                if (longString.StartsWith(shortString, StringComparison.Ordinal))
                                {
                                    match = true;
                                    break;
                                }
                            }
                            else
                            {
                                // The side-effect must be a prefix of the dependency (or an exact match).
                                if (dependency.StartsWith(sideEffect, StringComparison.Ordinal))
                                {
                                    match = true;
                                    break;
                                }
                            }
                        }
                    }

                    if (match)
                    {
                        affectedRules[i] = null;
                        break;
                    }
                }
            }

            return affectedRules.Keys;
        }
Example #6
0
        private static void AnalyzeRules(RuleChainingBehavior behavior, List<RuleState> ruleStates, RuleValidation validation, Tracer tracer)
        {
            int i;
            int numRules = ruleStates.Count;

            // if no chaining is required, then nothing to do
            if (behavior == RuleChainingBehavior.None)
                return;

            // Analyze all the rules and collect all the dependencies & side-effects
            RuleSymbolInfo[] ruleSymbols = new RuleSymbolInfo[numRules];
            for (i = 0; i < numRules; ++i)
                ruleSymbols[i] = AnalyzeRule(behavior, ruleStates[i].Rule, validation, tracer);

            for (i = 0; i < numRules; ++i)
            {
                RuleState currentRuleState = ruleStates[i];

                if (ruleSymbols[i].thenSideEffects != null)
                {
                    currentRuleState.ThenActionsActiveRules = AnalyzeSideEffects(ruleSymbols[i].thenSideEffects, ruleSymbols);

                    if ((currentRuleState.ThenActionsActiveRules != null) && (tracer != null))
                        tracer.TraceThenTriggers(currentRuleState.Rule.Name, currentRuleState.ThenActionsActiveRules, ruleStates);
                }

                if (ruleSymbols[i].elseSideEffects != null)
                {
                    currentRuleState.ElseActionsActiveRules = AnalyzeSideEffects(ruleSymbols[i].elseSideEffects, ruleSymbols);

                    if ((currentRuleState.ElseActionsActiveRules != null) && (tracer != null))
                        tracer.TraceElseTriggers(currentRuleState.Rule.Name, currentRuleState.ElseActionsActiveRules, ruleStates);
                }
            }
        }
 private static ICollection<int> AnalyzeSideEffects(ICollection<string> sideEffects, RuleSymbolInfo[] ruleSymbols)
 {
     Dictionary<int, object> dictionary = new Dictionary<int, object>();
     for (int i = 0; i < ruleSymbols.Length; i++)
     {
         ICollection<string> conditionDependencies = ruleSymbols[i].conditionDependencies;
         if (conditionDependencies != null)
         {
             foreach (string str in sideEffects)
             {
                 bool flag = false;
                 if (str.EndsWith("*", StringComparison.Ordinal))
                 {
                     foreach (string str2 in conditionDependencies)
                     {
                         if (str2.EndsWith("*", StringComparison.Ordinal))
                         {
                             string str5;
                             string str6;
                             string str3 = str2.Substring(0, str2.Length - 2);
                             string str4 = str.Substring(0, str.Length - 1);
                             if (str3.Length < str4.Length)
                             {
                                 str5 = str3;
                                 str6 = str4;
                             }
                             else
                             {
                                 str5 = str4;
                                 str6 = str3;
                             }
                             if (!str6.StartsWith(str5, StringComparison.Ordinal))
                             {
                                 continue;
                             }
                             flag = true;
                             break;
                         }
                         string str7 = str.Substring(0, str.Length - 1);
                         string str8 = str2;
                         if (str8.EndsWith("/", StringComparison.Ordinal))
                         {
                             str8 = str8.Substring(0, str8.Length - 1);
                         }
                         if (str8.StartsWith(str7, StringComparison.Ordinal))
                         {
                             flag = true;
                             break;
                         }
                     }
                 }
                 else
                 {
                     foreach (string str9 in conditionDependencies)
                     {
                         if (str9.EndsWith("*", StringComparison.Ordinal))
                         {
                             string str11;
                             string str12;
                             string str10 = str9.Substring(0, str9.Length - 2);
                             if (str10.Length < str.Length)
                             {
                                 str11 = str10;
                                 str12 = str;
                             }
                             else
                             {
                                 str11 = str;
                                 str12 = str10;
                             }
                             if (!str12.StartsWith(str11, StringComparison.Ordinal))
                             {
                                 continue;
                             }
                             flag = true;
                             break;
                         }
                         if (str9.StartsWith(str, StringComparison.Ordinal))
                         {
                             flag = true;
                             break;
                         }
                     }
                 }
                 if (flag)
                 {
                     dictionary[i] = null;
                     break;
                 }
             }
         }
     }
     return dictionary.Keys;
 }
 private static void AnalyzeRules(RuleChainingBehavior behavior, List<RuleState> ruleStates, RuleValidation validation, Tracer tracer)
 {
     int count = ruleStates.Count;
     if (behavior != RuleChainingBehavior.None)
     {
         RuleSymbolInfo[] ruleSymbols = new RuleSymbolInfo[count];
         int index = 0;
         while (index < count)
         {
             ruleSymbols[index] = AnalyzeRule(behavior, ruleStates[index].Rule, validation, tracer);
             index++;
         }
         for (index = 0; index < count; index++)
         {
             RuleState state = ruleStates[index];
             if (ruleSymbols[index].thenSideEffects != null)
             {
                 state.ThenActionsActiveRules = AnalyzeSideEffects(ruleSymbols[index].thenSideEffects, ruleSymbols);
                 if ((state.ThenActionsActiveRules != null) && (tracer != null))
                 {
                     tracer.TraceThenTriggers(state.Rule.Name, state.ThenActionsActiveRules, ruleStates);
                 }
             }
             if (ruleSymbols[index].elseSideEffects != null)
             {
                 state.ElseActionsActiveRules = AnalyzeSideEffects(ruleSymbols[index].elseSideEffects, ruleSymbols);
                 if ((state.ElseActionsActiveRules != null) && (tracer != null))
                 {
                     tracer.TraceElseTriggers(state.Rule.Name, state.ElseActionsActiveRules, ruleStates);
                 }
             }
         }
     }
 }