コード例 #1
0
        public bool Evaluate(string rawMessage)
        {
            if (rawMessage == null)
            {
                return(false);
            }

            bool AndResult = true, OrResult = true, NotAllResult = true, NotAnyResult = true;

            if (And != null && And.Count > 0)
            {
                AndResult = And.All(x => Regex.IsMatch(rawMessage, x, (RegexOptions)Options));
            }
            if (Or != null && Or.Count > 0)
            {
                OrResult = Or.Any(x => Regex.IsMatch(rawMessage, x, (RegexOptions)Options));
            }
            if (NotAll != null && NotAll.Count > 0)
            {
                NotAllResult = !NotAll.All(x => Regex.IsMatch(rawMessage, x, (RegexOptions)Options));
            }
            if (NotAny != null && NotAny.Count > 0)
            {
                NotAnyResult = !NotAny.Any(x => Regex.IsMatch(rawMessage, x, (RegexOptions)Options));
            }

            return(AndResult && OrResult && NotAllResult && NotAnyResult);
        }
コード例 #2
0
ファイル: Expression.cs プロジェクト: MaxxVolk/YASLS.NET
        public bool Evaluate(MessageDataItem dataItem)
        {
            if (And != null)
            {
                return(And.All(x => x?.Evaluate(dataItem) == true));
            }
            if (Or != null)
            {
                return(Or.Any(x => x?.Evaluate(dataItem) == true));
            }
            if (Not != null)
            {
                return(!Not.Evaluate(dataItem));
            }
            if (Exists != null)
            {
                if (Exists.Attribute != null)
                {
                    if (dataItem.AttributeExists(Exists.Attribute.Name ?? ""))
                    {
                        if (dataItem.GetAttributeAsVariant(Exists.Attribute.Name).Type == Exists.Attribute.Type)
                        {
                            return(true);
                        }
                    }
                }
            }
            if (SimpleExpression != null)
            {
                return(SimpleExpression.Evaluate(dataItem));
            }
            if (InExpression != null)
            {
                return(InExpression.Evaluate(dataItem));
            }
            if (RegExExpression != null)
            {
                return(RegExExpression.Evaluate(dataItem));
            }
            if (ModuleExpressionModule != null)
            {
                return(ModuleExpressionModule.IsMatch(dataItem));
            }

            return(false);
        }