Example #1
0
 protected override void SetTaskConditions(IEnumerable <Condition> conditions)
 {
     foreach (Condition condition in conditions)
     {
         if (condition.GetType() == typeof(NameValuesPairConfigurationPredicate) || condition.GetType() == typeof(IsPredicate))
         {
             IsPredicate isPredicate = condition as IsPredicate;
             if (isPredicate != null)
             {
                 MultiValuedProperty <Guid> multiValuedProperty = new MultiValuedProperty <Guid>();
                 if (isPredicate.Property.Name.Equals("ExclusionList"))
                 {
                     if (isPredicate.Value.ParsedValue is Guid)
                     {
                         multiValuedProperty.Add(isPredicate.Value.ParsedValue);
                     }
                     if (isPredicate.Value.ParsedValue is List <Guid> )
                     {
                         foreach (string item in ((List <string>)isPredicate.Value.ParsedValue))
                         {
                             multiValuedProperty.Add(item);
                         }
                     }
                     this.ExclusionList = multiValuedProperty;
                 }
             }
             else
             {
                 NameValuesPairConfigurationPredicate nameValuesPairConfigurationPredicate = condition as NameValuesPairConfigurationPredicate;
                 if (nameValuesPairConfigurationPredicate != null)
                 {
                     bool value2;
                     if (nameValuesPairConfigurationPredicate.Property.Name.Equals(DeviceTenantRule.AccessControl_ResourceScope))
                     {
                         PolicyResourceScope value;
                         if (Enum.TryParse <PolicyResourceScope>(nameValuesPairConfigurationPredicate.Value.RawValues.FirstOrDefault <string>(), out value))
                         {
                             this.ApplyPolicyTo = new PolicyResourceScope?(value);
                         }
                     }
                     else if (nameValuesPairConfigurationPredicate.Property.Name.Equals(DeviceTenantRule.AccessControl_AllowActionOnUnsupportedPlatform) && bool.TryParse(nameValuesPairConfigurationPredicate.Value.RawValues.FirstOrDefault <string>(), out value2))
                     {
                         this.BlockUnsupportedDevices = new bool?(value2);
                     }
                 }
             }
         }
     }
 }
Example #2
0
        public void ParseIsPredicateTest()
        {
            //Create parser
            PredicateParser  predicateParser   = new PredicateParser(Init(".string?"));
            ExpressionParser expressionParser  = new ExpressionParser(Init("test"));
            Expression       parsedExpression  = expressionParser.ParseExpression();
            IsPredicate      parsedIsPredicate = predicateParser.ParseIsPredicate(parsedExpression);

            //Check expression
            Assert.AreEqual(typeof(VarExpression), parsedIsPredicate.GetExpression().GetType());
            Assert.AreEqual("test", parsedIsPredicate.GetExpression().ToString());

            //Check type
            Assert.AreEqual(typeof(StringType), parsedIsPredicate.GetType().GetType());
        }
Example #3
0
        /// <summary>
        /// Parser for IsPredicate
        /// </summary>
        /// <returns>Parsed IsPredicate</returns>
        public IsPredicate ParseIsPredicate(Expression parsedExpression)
        {
            IsPredicate isPredicate = new IsPredicate();

            //Set already parsed expression
            isPredicate.SetExpression(parsedExpression);

            //Skip . token
            NextToken(".", "Expression.Type?", '.');

            //Parse type
            isPredicate.SetType(ParseType());

            //Skip ? token
            NextToken("?", "Expression.Type?", '?');

            return isPredicate;
        }
Example #4
0
        /// <summary>
        /// Parser for IsPredicate
        /// </summary>
        /// <returns>Parsed IsPredicate</returns>
        public IsPredicate ParseIsPredicate(Expression parsedExpression)
        {
            IsPredicate isPredicate = new IsPredicate();

            //Set already parsed expression
            isPredicate.SetExpression(parsedExpression);

            //Skip . token
            NextToken(".", "Expression.Type?", '.');

            //Parse type
            isPredicate.SetType(ParseType());

            //Skip ? token
            NextToken("?", "Expression.Type?", '?');

            return(isPredicate);
        }
        private void InstallLocalPredicates()
        {
            // Input/Output
            _predicates["write/1"]   = new WritePredicate();
            _predicates["writeln/1"] = new WriteLnPredicate();
            _predicates["nl/0"]      = new NlPredicate();
            _predicates["get0/1"]    = new Get0Predicate();
            _predicates["skip/1"]    = new SkipPredicate();
            _predicates["put/1"]     = new PutPredicate();

            // Comparison, numeric
            _predicates["=\\=/2"] = new NotEqualsPredicate();
            _predicates["=:=/2"]  = new EqualsPredicate();
            _predicates[">=/2"]   = new GreaterThanEqualPredicate();
            _predicates[">/2"]    = new GreaterThanPredicate();
            _predicates["=</2"]   = new LessThanEqualPredicate();
            _predicates["</2"]    = new LessThanPredicate();

            // Control
            _predicates["call/1"] = new CallPredicate();

            // Equality
            _predicates["=/2"]   = new UnifyPredicate();
            _predicates["\\=/2"] = new NotUnifiablePredicate();

            // Meta
            _predicates["is/2"]      = new IsPredicate();
            _predicates["atom/1"]    = new AtomPredicate();
            _predicates["bound/1"]   = new BoundPredicate();
            _predicates["char/1"]    = new CharPredicate();
            _predicates["free/1"]    = new FreePredicate();
            _predicates["integer/1"] = new IntegerPredicate();
            _predicates["nonvar/1"]  = new NonVarPredicate();
            _predicates["var/1"]     = new VarPredicate();

            // Object-Oriented Programming
            _predicates["object/2"]       = new object_2();
            _predicates["invoke/3"]       = new invoke_2();
            _predicates["get_property/3"] = new get_property_3();

            // .NET Reflection
        }
 void IVisitor.VisitBefore(IsPredicate predicate)
 {
     this.ParentExists(predicate);
 }
 void IVisitor.Visit(IsPredicate predicate, int offset)
 {
     this.ParentExists(predicate);
 }
 void IVisitor.VisitAfter(IsPredicate predicate)
 {
     this.ParentExists(predicate);
 }
Example #9
0
        /// <summary>
        /// Method which evaluates an predicate and returns true or false
        /// </summary>
        /// <param name="predicate">Predicate to evaluate</param>
        /// <returns>True if predicate is true, otherwise false</returns>
        private bool EvaluatePredicate(Predicate predicate)
        {
            if (predicate is IsPredicate)
            {   //Evaluate Expression Predicate
                IsPredicate isPredicate = (IsPredicate)predicate;
                Expression  expression  = isPredicate.GetExpression();

                //In case of VarExpression, get expression from symboltable
                if (expression is VarExpression)
                {
                    expression = GetReferenceExpression((VarExpression)expression);
                    if (expression == null)
                    {
                        return(false);
                    }
                }

                //If right type return true, otherwise false
                if (isPredicate.GetType() is StringType)
                {
                    return(expression is TextExpression);
                }
                else if (isPredicate.GetType() is ListType)
                {
                    return(expression is ListExpression);
                }
                else if (isPredicate.GetType() is RecordType)
                {
                    return(expression is RecordExpression);
                }
                else
                {   //No match between types which could be checked, so false
                    return(false);
                }
            }
            else if (predicate is ExpressionPredicate)
            {   //Evaluate Expression Predicate
                ExpressionPredicate expressionPredicate = (ExpressionPredicate)predicate;
                Expression          expression          = expressionPredicate.GetExpression();

                if (expression is FieldExpression)
                {   //Check if specific field exists in record (not null)
                    Expression expr = GetExpression((FieldExpression)expression);
                    return(expr != null);
                }
                else if (expression is VarExpression)
                {   //Check if specific variable is defined
                    VarExpression varExpr = (VarExpression)expression;
                    return(SymbolTable.ContainsVariable(varExpr.GetVariableIdentifier()));
                }
                else
                {   //Other expressions are always true, because they doesn't refer to something
                    return(true);
                }
            }
            else if (predicate is AndPredicate)
            {   //Evaluate And Predicate
                AndPredicate andPredicate = (AndPredicate)predicate;
                return(EvaluatePredicate(andPredicate.GetLeftPredicate()) && EvaluatePredicate(andPredicate.GetLeftPredicate()));
            }
            else if (predicate is OrPredicate)
            {   //Evaluate Or Predicate
                OrPredicate orPredicate = (OrPredicate)predicate;
                return(EvaluatePredicate(orPredicate.GetLeftPredicate()) || EvaluatePredicate(orPredicate.GetRightPredicate()));
            }
            else if (predicate is NotPredicate)
            {   //Evaluate Not Predicate
                NotPredicate notPredicate = (NotPredicate)predicate;
                return(!EvaluatePredicate(notPredicate.GetPredicate()));
            }
            return(false);
        }
Example #10
0
 public virtual void Visit(IsPredicate predicate)
 {
     VisitSubNodes(predicate);
 }
Example #11
0
 public virtual void Visit(IsPredicate predicate)
 {
     VisitSubNodes(predicate);
 }