Ejemplo n.º 1
0
        internal override bool CheckCondition(Context ctx, Context.LoggerDelegate logger, object o)
        {
            if (Children.Count == 0 && Parent == null)
            {
                return(true);
            }
            switch (Grouping)
            {
            case CndGroupingEnum.And:
            {
                bool actives = false;
                foreach (ConditionComponent cc in Children)
                {
                    if (cc.Enabled == false)
                    {
                        if (System.Diagnostics.Debugger.IsAttached == true)
                        {
                            System.Diagnostics.Debug.WriteLine("AND: Condition '" + cc.ToString() + "' not enabled");
                        }
                        continue;
                    }
                    actives = true;
                    if (cc.CheckCondition(ctx, logger, o) == false)
                    {
                        if (System.Diagnostics.Debugger.IsAttached == true)
                        {
                            System.Diagnostics.Debug.WriteLine("AND: Condition '" + cc.ToString() + "' was false");
                        }
                        return(false);
                    }
                }
                if (actives == false)
                {
                    if (System.Diagnostics.Debugger.IsAttached == true)
                    {
                        System.Diagnostics.Debug.WriteLine("AND: No actives found");
                    }
                    return(false);
                }
            }
            break;

            case CndGroupingEnum.Or:
            {
                foreach (ConditionComponent cc in Children)
                {
                    if (cc.Enabled == false)
                    {
                        if (System.Diagnostics.Debugger.IsAttached == true)
                        {
                            System.Diagnostics.Debug.WriteLine("OR: Condition '" + cc.ToString() + "' not enabled");
                        }
                        continue;
                    }
                    if (cc.CheckCondition(ctx, logger, o) == true)
                    {
                        if (System.Diagnostics.Debugger.IsAttached == true)
                        {
                            System.Diagnostics.Debug.WriteLine("OR: Condition '" + cc.ToString() + "' was true");
                        }
                        return(true);
                    }
                }
            }
            break;

            case CndGroupingEnum.Xor:
            {
                bool truefound = false;
                foreach (ConditionComponent cc in Children)
                {
                    if (cc.Enabled == false)
                    {
                        if (System.Diagnostics.Debugger.IsAttached == true)
                        {
                            System.Diagnostics.Debug.WriteLine("XOR: Condition '" + cc.ToString() + "' not enabled");
                        }
                        continue;
                    }
                    if (cc.CheckCondition(ctx, logger, o) == true)
                    {
                        if (truefound == true)
                        {
                            if (System.Diagnostics.Debugger.IsAttached == true)
                            {
                                System.Diagnostics.Debug.WriteLine("XOR: Condition '" + cc.ToString() + "' was true as well");
                            }
                            return(false);
                        }
                        if (System.Diagnostics.Debugger.IsAttached == true)
                        {
                            System.Diagnostics.Debug.WriteLine("XOR: Condition '" + cc.ToString() + "' was true");
                        }
                        truefound = true;
                    }
                }
                if (System.Diagnostics.Debugger.IsAttached == true)
                {
                    System.Diagnostics.Debug.WriteLine("XOR: Condition on '" + this.ToString() + "' " + ((truefound == true) ? "passed" : "did not pass"));
                }
                return(truefound);
            }

            case CndGroupingEnum.Not:
            {
                foreach (ConditionComponent cc in Children)
                {
                    if (cc.Enabled == false)
                    {
                        if (System.Diagnostics.Debugger.IsAttached == true)
                        {
                            System.Diagnostics.Debug.WriteLine("NOT: Condition '" + cc.ToString() + "' not enabled");
                        }
                        continue;
                    }
                    if (cc.CheckCondition(ctx, logger, o) == true)
                    {
                        if (System.Diagnostics.Debugger.IsAttached == true)
                        {
                            System.Diagnostics.Debug.WriteLine("NOT: Condition '" + cc.ToString() + "' was true");
                        }
                        return(false);
                    }
                }
                if (System.Diagnostics.Debugger.IsAttached == true)
                {
                    System.Diagnostics.Debug.WriteLine("NOT: Condition on '" + this.ToString() + "' passed");
                }
                return(true);
            }
            }
            if (System.Diagnostics.Debugger.IsAttached == true)
            {
                System.Diagnostics.Debug.WriteLine("GENERAL: Condition on '" + this.ToString() + "' " + ((Children.Count > 0 && Grouping == CndGroupingEnum.And) ? "passed" : "did not pass"));
            }
            return(Children.Count > 0 && Grouping == CndGroupingEnum.And);
        }
Ejemplo n.º 2
0
        internal override bool CheckCondition(Context ctx, Context.LoggerDelegate logger, object o)
        {
            try
            {
                if (Enabled == false)
                {
                    return(false);
                }
                string lval = "", rval = "";
                switch (ExpressionTypeL)
                {
                case ExprTypeEnum.Numeric:

                    lval = I18n.ThingToString(ctx.EvaluateNumericExpression(logger, o, ExpressionL));
                    break;

                case ExprTypeEnum.String:
                    lval = ctx.EvaluateStringExpression(logger, o, ExpressionL);
                    break;
                }
                switch (ExpressionTypeR)
                {
                case ExprTypeEnum.Numeric:
                    rval = I18n.ThingToString(ctx.EvaluateNumericExpression(logger, o, ExpressionR));
                    break;

                case ExprTypeEnum.String:
                    rval = ctx.EvaluateStringExpression(logger, o, ExpressionR);
                    break;
                }
                switch (ConditionType)
                {
                case CndTypeEnum.NumericEqual:
                {
                    double ld = double.Parse(lval, CultureInfo.InvariantCulture);
                    double rd = double.Parse(rval, CultureInfo.InvariantCulture);
                    return(Math.Abs(ld - rd) < double.Epsilon ? true : false);
                }

                case CndTypeEnum.NumericNotEqual:
                {
                    double ld = double.Parse(lval, CultureInfo.InvariantCulture);
                    double rd = double.Parse(rval, CultureInfo.InvariantCulture);
                    return(Math.Abs(ld - rd) < double.Epsilon ? false : true);
                }

                case CndTypeEnum.NumericGreater:
                {
                    double ld = double.Parse(lval, CultureInfo.InvariantCulture);
                    double rd = double.Parse(rval, CultureInfo.InvariantCulture);
                    return(ld > rd);
                }

                case CndTypeEnum.NumericGreaterEqual:
                {
                    double ld = double.Parse(lval, CultureInfo.InvariantCulture);
                    double rd = double.Parse(rval, CultureInfo.InvariantCulture);
                    return(ld >= rd);
                }

                case CndTypeEnum.NumericLess:
                {
                    double ld = double.Parse(lval, CultureInfo.InvariantCulture);
                    double rd = double.Parse(rval, CultureInfo.InvariantCulture);
                    return(ld < rd);
                }

                case CndTypeEnum.NumericLessEqual:
                {
                    double ld = double.Parse(lval, CultureInfo.InvariantCulture);
                    double rd = double.Parse(rval, CultureInfo.InvariantCulture);
                    return(ld <= rd);
                }

                case CndTypeEnum.StringEqualCase:
                {
                    return(String.Compare(lval, rval, false) == 0);
                }

                case CndTypeEnum.StringEqualNocase:
                {
                    return(String.Compare(lval, rval, true) == 0);
                }

                case CndTypeEnum.StringNotEqualCase:
                {
                    return(String.Compare(lval, rval, false) != 0);
                }

                case CndTypeEnum.StringNotEqualNocase:
                {
                    return(String.Compare(lval, rval, true) != 0);
                }

                case CndTypeEnum.RegexMatch:
                {
                    return(Regex.IsMatch(lval, rval));
                }

                case CndTypeEnum.RegexNotMatch:
                {
                    return(Regex.IsMatch(lval, rval) == false);
                }

                case CndTypeEnum.ListContains:
                {
                    lock (ctx.plug.sessionvars.List)
                    {
                        if (ctx.plug.sessionvars.List.ContainsKey(lval) == true)
                        {
                            if (ctx.plug.sessionvars.List[lval].IndexOf(rval) > 0)
                            {
                                return(true);
                            }
                        }
                    }
                    return(false);
                }

                case CndTypeEnum.ListDoesNotContain:
                {
                    lock (ctx.plug.sessionvars.List)
                    {
                        if (ctx.plug.sessionvars.List.ContainsKey(lval) == true)
                        {
                            if (ctx.plug.sessionvars.List[lval].IndexOf(rval) > 0)
                            {
                                return(false);
                            }
                        }
                    }
                    return(true);
                }
                }
            }
            catch (Exception)
            {
            }
            return(false);
        }
Ejemplo n.º 3
0
 internal abstract bool CheckCondition(Context ctx, Context.LoggerDelegate logger, object o);