示例#1
0
 public void TestNegative()
 {
     NxNot and = new NxNot();
     and.Append("id1", "id2", OperatorType.NotEqual);
     and.Append("id3", "id4", OperatorType.LessThan);
     and.Append(new NxIsTrue("id5"));
     and.Append(new NxIsFalse("id6"));
     string expected = "<Not><NotEquals leftId=\"id1\" rightId=\"id2\" /><LessThan leftId=\"id3\" rightId=\"id4\" /><IsTrue valueId=\"id5\" /><IsFalse valueId=\"id6\" /></Not>";
     string actual = and.Create().OuterXml;
     Assert.AreEqual(expected, actual);
 }
示例#2
0
        public void WriteCondition(IPolicySet policySet, IPolicyObject parent, ICondition condition, ConditionLogic cdnlogic)
        {
            NxLogic logic = new NxLogic();
            NxIf iF = new NxIf();
            NxOperator conditionTest = null;
            if (condition.IsNegated)
                conditionTest = new NxNot();
            else
                conditionTest = new NxAnd();

            IDataElement lhs = condition.DataLeft;
            IDataElement rhs = condition.DataRight;

            WriteDataElement(lhs);
            WriteDataElement(rhs);

            string incrementId = Guid.NewGuid().ToString();
            List<NxParameter> parameters = NxUtils.GetAttributes(condition);

            NxSet currentPolicy = m_policysets.PolicySets[0].CurrentPolicy;

            string lhsId = lhs.Identifier.ToString();
            string rhsId = rhs.Identifier.ToString();
            if (condition.Class == "IDataLengthComparer")
            {
                if ((lhs.Type == DataType.Object) || (NxUtils.IsArray(lhs.Type)))
                {
                    lhsId = Guid.NewGuid().ToString();
                    foreach (NxPolicySet policyset in m_policysets.PolicySets)
                    {
                        policyset.CurrentPolicy.Append(new NxObjectLookup(lhsId, lhs.Identifier.ToString(), "Length"));
                    }
                    parameters.Add(new NxParameter("Properties", lhs.Identifier.ToString(), true));
                }

                if ((rhs.Type == DataType.Object) || (NxUtils.IsArray(rhs.Type)))
                {
                    rhsId = Guid.NewGuid().ToString();
                    foreach (NxPolicySet policyset in m_policysets.PolicySets)
                    {
                        policyset.CurrentPolicy.Append(new NxObjectLookup(rhsId, rhs.Identifier.ToString(), "Length"));
                    }
                    parameters.Add(new NxParameter("Properties", rhs.Identifier.ToString(), true));
                }
            }
            conditionTest.Append(lhsId, rhsId, condition.Operator);

            NxDo dO = new NxDo();

            foreach (NxPolicySet policyset in m_policysets.PolicySets)
            {
                policyset.AppendIncrementer(new NxIncrement(incrementId));
                policyset.AppendIncrementer(new NxIncrementStep(incrementId));
            }
           
            dO.Append(new NxIncrementStep(incrementId));
            bool ignored = NxUtils.IsIgnored(condition);
            iF.Append(conditionTest);
            iF.Append(dO);
            logic.Append(iF);
            if (!ignored)
            {
                parameters.Add(new NxParameter("Name", condition));
                dO.Append(new NxEvaluate("ConditionLineFired", new List<NxParameter>(parameters.ToArray())));
                NxElse eLse = new NxElse();
                eLse.Append(new NxEvaluate("ConditionLinePassed", new List<NxParameter>(parameters.ToArray())));
                logic.Append(eLse);
            }
            foreach (NxPolicySet policyset in m_policysets.PolicySets)
            {
                policyset.Policies[policyset.Policies.Count - 1].AppendLogic(logic);
                policyset.Policies[policyset.Policies.Count - 1].AppendIncrementId(incrementId, parent.Identifier, cdnlogic); //IConditionGroup
            }
        }