Ejemplo n.º 1
0
        private static bool IsValidStringRule(StringDataUnit validStringDataUnit, StringValueRule stringValueRule)
        {
            RuleToApply ruleToApply = RuleToApply.NOTEQUALTO;

            if (!string.IsNullOrEmpty(stringValueRule.ShouldBeGreaterThan) || !string.IsNullOrEmpty(stringValueRule.ShouldBeLessThan))
            {
                ruleToApply = RuleToApply.GREATERORLESSER;
            }
            else if (!string.IsNullOrEmpty(stringValueRule.ShouldBeEqualTo))
            {
                ruleToApply = RuleToApply.EQUALTO;
            }
            else if (!string.IsNullOrEmpty(stringValueRule.ShouldNotBeEqualTo))
            {
                ruleToApply = RuleToApply.NOTEQUALTO;
            }
            else
            {
                throw new Exception($"String Value rule needs to have a proper value");
            }

            switch (ruleToApply)
            {
            case RuleToApply.GREATERORLESSER:
                if (!string.IsNullOrEmpty(stringValueRule.ShouldBeGreaterThan) &&
                    !string.IsNullOrEmpty(stringValueRule.ShouldBeLessThan))
                {
                    if (validStringDataUnit.Value.CompareTo(stringValueRule.ShouldBeGreaterThan) >= 0 &&
                        validStringDataUnit.Value.CompareTo(stringValueRule.ShouldBeLessThan) <= 0)
                    {
                        return(true);
                    }
                    return(false);
                }
                else if (!string.IsNullOrEmpty(stringValueRule.ShouldBeGreaterThan) && validStringDataUnit.Value.CompareTo(stringValueRule.ShouldBeGreaterThan) >= 0)
                {
                    return(true);
                }
                else if (!string.IsNullOrEmpty(stringValueRule.ShouldBeLessThan) && validStringDataUnit.Value.CompareTo(stringValueRule.ShouldBeLessThan) <= 0)
                {
                    return(true);
                }

                return(false);

            case RuleToApply.EQUALTO:
                return(validStringDataUnit.Value == stringValueRule.ShouldBeEqualTo);

            case RuleToApply.NOTEQUALTO:
                return(validStringDataUnit.Value != stringValueRule.ShouldNotBeEqualTo);

            default:
                throw new NotSupportedException("The given type is not valid");
            }
        }
Ejemplo n.º 2
0
        private static bool IsValidDateTimeRule(DateTimeDataUnit validDateTimeDataUnit, DateTimeValueRule dateTimeValueRule)
        {
            RuleToApply ruleToApply = RuleToApply.NOTEQUALTO;

            if (dateTimeValueRule.GreaterThan.HasValue || dateTimeValueRule.LesserThan.HasValue)
            {
                ruleToApply = RuleToApply.GREATERORLESSER;
            }
            else if (dateTimeValueRule.EqualTo.HasValue)
            {
                ruleToApply = RuleToApply.EQUALTO;
            }
            else if (dateTimeValueRule.NotEqualTo.HasValue)
            {
                ruleToApply = RuleToApply.NOTEQUALTO;
            }
            else
            {
                throw new Exception($"DateTime Value rule needs to have a proper value");
            }

            switch (ruleToApply)
            {
            case RuleToApply.GREATERORLESSER:
                if (dateTimeValueRule.GreaterThan.HasValue && dateTimeValueRule.LesserThan.HasValue)
                {
                    if (validDateTimeDataUnit.Value.CompareTo(dateTimeValueRule.GreaterThan.Value) >= 0 &&
                        validDateTimeDataUnit.Value.CompareTo(dateTimeValueRule.LesserThan.Value) <= 0)
                    {
                        return(true);
                    }
                    return(false);
                }
                else if (dateTimeValueRule.GreaterThan.HasValue && validDateTimeDataUnit.Value.CompareTo(dateTimeValueRule.GreaterThan.Value) >= 0)
                {
                    return(true);
                }
                else if (dateTimeValueRule.LesserThan.HasValue && validDateTimeDataUnit.Value.CompareTo(dateTimeValueRule.LesserThan.Value) <= 0)
                {
                    return(true);
                }
                return(false);

            case RuleToApply.EQUALTO:
                return(validDateTimeDataUnit.Value == dateTimeValueRule.EqualTo);

            case RuleToApply.NOTEQUALTO:
                return(validDateTimeDataUnit.Value != dateTimeValueRule.NotEqualTo);

            default:
                throw new NotSupportedException("The given type is not valid");
            }
        }
Ejemplo n.º 3
0
        private static bool IsValidIntegerRule(IntegerDataUnit validIntegerDataUnit, IntegerValueRule integerValueRule)
        {
            RuleToApply ruleToApply = RuleToApply.NOTEQUALTO;

            if (integerValueRule.GreaterThan.HasValue || integerValueRule.LessThan.HasValue)
            {
                ruleToApply = RuleToApply.GREATERORLESSER;
            }
            else if (integerValueRule.EqualTo.HasValue)
            {
                ruleToApply = RuleToApply.EQUALTO;
            }
            else if (integerValueRule.NotEqualTo.HasValue)
            {
                ruleToApply = RuleToApply.NOTEQUALTO;
            }
            else
            {
                throw new Exception($"Integer Value rule needs to have a proper value");
            }

            switch (ruleToApply)
            {
            case RuleToApply.GREATERORLESSER:
                if (integerValueRule.GreaterThan.HasValue && integerValueRule.LessThan.HasValue)
                {
                    if (validIntegerDataUnit.Value >= integerValueRule.GreaterThan.Value && validIntegerDataUnit.Value <= integerValueRule.LessThan.Value)
                    {
                        return(true);
                    }
                    return(false);
                }
                else if (integerValueRule.GreaterThan.HasValue && validIntegerDataUnit.Value >= integerValueRule.GreaterThan.Value)
                {
                    return(true);
                }
                else if (integerValueRule.LessThan.HasValue && validIntegerDataUnit.Value <= integerValueRule.LessThan.Value)
                {
                    return(true);
                }
                return(false);

            case RuleToApply.EQUALTO:
                return(validIntegerDataUnit.Value == integerValueRule.EqualTo);

            case RuleToApply.NOTEQUALTO:
                return(validIntegerDataUnit.Value != integerValueRule.NotEqualTo);

            default:
                throw new NotSupportedException("The given type is not valid");
            }
        }