示例#1
0
            public bool ValidateConstantConstraints(Dictionary <string, string> constraints)
            {
                if (!constantConstraintsChecked)
                {
                    constantConstraintsValid = true;
                    if (rule.constantConstraints != null)
                    {
                        for (int i = 0; i < rule.constantConstraints.Count; i++)
                        {
                            Rule.ConstantConstraint constantConstraint = rule.constantConstraints[i];
                            string text    = (constraints != null) ? constraints.TryGetValue(constantConstraint.key, "") : "";
                            float  result  = 0f;
                            float  result2 = 0f;
                            bool   flag    = !text.NullOrEmpty() && !constantConstraint.value.NullOrEmpty() && float.TryParse(text, out result) && float.TryParse(constantConstraint.value, out result2);
                            bool   flag2;
                            switch (constantConstraint.type)
                            {
                            case Rule.ConstantConstraint.Type.Equal:
                                flag2 = text.EqualsIgnoreCase(constantConstraint.value);
                                break;

                            case Rule.ConstantConstraint.Type.NotEqual:
                                flag2 = !text.EqualsIgnoreCase(constantConstraint.value);
                                break;

                            case Rule.ConstantConstraint.Type.Less:
                                flag2 = (flag && result < result2);
                                break;

                            case Rule.ConstantConstraint.Type.Greater:
                                flag2 = (flag && result > result2);
                                break;

                            case Rule.ConstantConstraint.Type.LessOrEqual:
                                flag2 = (flag && result <= result2);
                                break;

                            case Rule.ConstantConstraint.Type.GreaterOrEqual:
                                flag2 = (flag && result >= result2);
                                break;

                            default:
                                Log.Error("Unknown ConstantConstraint type: " + constantConstraint.type);
                                flag2 = false;
                                break;
                            }

                            if (!flag2)
                            {
                                constantConstraintsValid = false;
                                break;
                            }
                        }
                    }

                    constantConstraintsChecked = true;
                }

                return(constantConstraintsValid);
            }
示例#2
0
        private static bool ValidateRulesConstraints(List <Rule.ConstantConstraint> constraints, List <KeyValuePair <string, string> > rules, ref bool ConstraintsChecked, ref bool ConstraintsValid)
        {
            if (!ConstraintsChecked)
            {
                ConstraintsValid = true;
                if (constraints != null)
                {
                    for (int i = 0; i < constraints.Count; i++)
                    {
                        Rule.ConstantConstraint constraint = constraints[i];
                        bool match = false;
                        foreach (var entry in rules.Where(x => x.Key == constraint.key))
                        {
                            string text        = entry.Value ?? "";
                            float  value       = 0f;
                            float  expected    = 0f;
                            bool   ruleIsvalid = !text.NullOrEmpty() && !constraint.value.NullOrEmpty() && float.TryParse(text, out value) && float.TryParse(constraint.value, out expected);
                            switch (constraint.type)
                            {
                            case Rule.ConstantConstraint.Type.Equal:
                                match = text.EqualsIgnoreCase(constraint.value);
                                break;

                            case Rule.ConstantConstraint.Type.NotEqual:
                                match = !text.EqualsIgnoreCase(constraint.value);
                                break;

                            case Rule.ConstantConstraint.Type.Less:
                                match = (ruleIsvalid && value < expected);
                                break;

                            case Rule.ConstantConstraint.Type.Greater:
                                match = (ruleIsvalid && value > expected);
                                break;

                            case Rule.ConstantConstraint.Type.LessOrEqual:
                                match = (ruleIsvalid && value <= expected);
                                break;

                            case Rule.ConstantConstraint.Type.GreaterOrEqual:
                                match = (ruleIsvalid && value >= expected);
                                break;

                            default:
                                Log.Error("Unknown ConstantConstraint type: " + constraint.type, false);
                                match = false;
                                break;
                            }
                            if (match)
                            {
                                break;
                            }
                        }
                        if (!match)
                        {
                            ConstraintsValid = false;
                            break;
                        }
                    }
                }
                ConstraintsChecked = true;
            }
            return(ConstraintsValid);
        }