コード例 #1
0
        public ActionResult CreateSubCondition(policyData vData, int id, int linkId)
        {
            vData.PolicyLink = new PolicyLinkEntity(linkId);

            DecisionNodeEntity ce = new DecisionNodeEntity(id);

            vData.Condition        = new DecisionNodeEntity();
            vData.Condition.Type   = constants.conditionType;
            vData.Condition.Parent = ce;

            DecisionNodeCollection maxColl = new DecisionNodeCollection();
            PredicateExpression    pe      = new PredicateExpression(DecisionNodeFields.ParentId == id);
            object maxObj = maxColl.GetScalar(DecisionNodeFieldIndex.Order, null, AggregateFunction.Max, pe);

            if (maxObj != null && maxObj != DBNull.Value)
            {
                vData.Condition.Order = (int)maxObj + 1;
            }
            else
            {
                vData.Condition.Order = 0;
            }

            vData.Condition.Save();

            ViewData["title"] = "new sub-condition";

            return(View("EditCondition", vData));
        }
コード例 #2
0
        private void loadAttributeValue(int idx, DecisionNodeEntity ame, XmlNode node)
        {
            XmlNode attr = node.Attributes.GetNamedItem("attr");

            if (attr == null)
            {
                throw new Exception(string.Format("attr attribute missing from node: {0}", node.InnerXml));
            }

            string attrVal;
            string attrExtra;

            resolveAttribute(attr.Value, out attrVal, out attrExtra);

            AttributeCollection acoll = new AttributeCollection();

            acoll.GetMulti(AttributeFields.Name == attrVal);
            if (acoll.Count == 0)
            {
                throw new Exception(string.Format("unknown attribute {0} (toby please fix this)", attrVal));
            }

            AttributeValueEntity ave = new AttributeValueEntity();

            ave.Order          = idx;
            ave.Attribute      = acoll[0];
            ave.Value          = attr.Value.Trim();
            ave.AttributeMatch = ame;
        }
コード例 #3
0
        /// <summary>Creates a new, empty DecisionNodeEntity object.</summary>
        /// <returns>A new, empty DecisionNodeEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new DecisionNodeEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewDecisionNode
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
コード例 #4
0
        private void loadSubject(TargetEntity te, XmlNode node)
        {
            DecisionNodeEntity ce = new DecisionNodeEntity();

            TargetConditionEntity tce = new TargetConditionEntity();

            tce.Target       = te;
            tce.DecisionNode = ce;

            loadCondition(ce, node);
        }
コード例 #5
0
        static private void DeleteDecisionNode(DecisionNodeEntity de)
        {
            foreach (DecisionNodeEntity child in de.Children)
            {
                DeleteDecisionNode(child);
            }

            de.AttributeValue.DeleteMulti();
            de.TargetCondition.DeleteMulti();
            de.Rule.DeleteMulti();
            de.Delete();
        }
コード例 #6
0
        public string GetConditionString(DecisionNodeEntity ce)
        {
            Debug.Assert(ce.Type == constants.conditionType);

            StringBuilder sb = new StringBuilder();

            ce.Children.Sort(DecisionNodeFields.Order.FieldIndex, System.ComponentModel.ListSortDirection.Ascending);
            foreach (DecisionNodeEntity ame in ce.Children)
            {
                if (sb.Length > 0)
                {
                    sb.AppendFormat(" {0} ", ce.CombineAnd ? "and" : "or");
                }
                else
                {
                    sb.Append("(");
                }

                if (ame.Type == constants.conditionType)
                {
                    sb.AppendFormat("{0}", GetConditionString(ame));
                }
                else
                {
                    if (ame.Extra.Length > 0)
                    {
                        if (ame.Attribute.AttributeType.Name == "uri")
                        {
                            sb.AppendFormat("{0}.{1} = {2}", ame.Attribute.Name, ame.Extra, GetMatchString(ame));
                        }
                        else
                        {
                            sb.AppendFormat("{0}:{1} = {2}", ame.Attribute.Name, ame.Extra, GetMatchString(ame));
                        }
                    }
                    else
                    {
                        sb.AppendFormat("{0} = {1}", ame.Attribute.Name, GetMatchString(ame));
                    }
                }
            }

            if (sb.Length == 0)
            {
                sb.Append("always");
            }
            else
            {
                sb.Append(")");
            }

            return(sb.ToString());
        }
コード例 #7
0
        /// <summary>Gets the relation objects which represent the relation the fieldName specified is mapped on. </summary>
        /// <param name="fieldName">Name of the field mapped onto the relation of which the relation objects have to be obtained.</param>
        /// <returns>RelationCollection with relation object(s) which represent the relation the field is maped on</returns>
        public static new RelationCollection GetRelationsForField(string fieldName)
        {
            RelationCollection toReturn = new RelationCollection();

            switch (fieldName)
            {
            default:
                toReturn = DecisionNodeEntity.GetRelationsForField(fieldName);
                break;
            }
            return(toReturn);
        }
コード例 #8
0
        public ActionResult DecisionNodeOrder(policyData vData, int id, int id2, int linkId, FormCollection collection)
        {
            DecisionNodeEntity     match = new DecisionNodeEntity(id2);
            DecisionNodeCollection coll  = new DecisionNodeCollection();

            PredicateExpression pe = new PredicateExpression(DecisionNodeFields.Id != match.Id);

            pe.Add(DecisionNodeFields.ParentId == id);
            SortExpression se = null;

            if (collection["up"] != null)
            {
                // Find all categories with display index less than ours.
                pe.Add(DecisionNodeFields.Order <= match.Order);

                // Order by display index, highest first.
                se = new SortExpression(DecisionNodeFields.Order | SortOperator.Descending);
            }
            else
            {
                // Find all categories with display index greater than ours.
                pe.Add(DecisionNodeFields.Order >= match.Order);

                // Order by display index, lowest first.
                se = new SortExpression(DecisionNodeFields.Order | SortOperator.Ascending);
            }

            // Swap with closest one.
            if (coll.GetMulti(pe, 1, se) && coll.Count > 0)
            {
                int temp = coll[0].Order;
                coll[0].Order = match.Order;
                match.Order   = temp;

                match.Save();
                coll.SaveMulti();
            }

            string action = collection["backTo"];

            if (action == "EditRule")
            {
                vData.Condition = new DecisionNodeEntity(id);
                id = vData.Condition.Rule[0].Id;
            }

            return(RedirectToAction(action, new { id = id, linkId = linkId }));
        }
コード例 #9
0
        public string GetMatchString(DecisionNodeEntity ame)
        {
            StringBuilder sb = new StringBuilder();

            ame.AttributeValue.Sort(AttributeValueFields.Order.FieldIndex, System.ComponentModel.ListSortDirection.Ascending);
            foreach (AttributeValueEntity ave in ame.AttributeValue)
            {
                if (ave.Literal)
                {
                    sb.Append(ave.Value);
                }
                else
                {
                    sb.AppendFormat("[{0}]", ave.Attribute.Name);
                }
            }

            return(sb.ToString());
        }
コード例 #10
0
        static public DecisionNodeEntity dupCondition(DecisionNodeEntity original)
        {
            DecisionNodeEntity copy = new DecisionNodeEntity(original.Id);

            duplicator.MarkEntityDirty(copy);
            copy.IsNew = true;

            foreach (AttributeValueEntity ave in original.AttributeValue)
            {
                AttributeValueEntity aveCopy = dupAttributeValue(ave);
                aveCopy.AttributeMatch = copy;
            }

            foreach (DecisionNodeEntity dce in original.Children)
            {
                DecisionNodeEntity dceNew = dupCondition(dce);
                dceNew.Parent = copy;
            }

            return(copy);
        }
コード例 #11
0
        private void loadCondition(DecisionNodeEntity ce, XmlNode node)
        {
            ce.Type = constants.conditionType;
            XmlNode attr = node.Attributes.GetNamedItem("combine");

            if (attr == null || attr.Value == "and")
            {
                ce.CombineAnd = true;
            }
            else
            {
                ce.CombineAnd = false;
            }

            int matchIdx = 0;

            foreach (XmlNode child in node.ChildNodes)
            {
                if (child.NodeType != XmlNodeType.Element)
                {
                    continue;
                }

                switch (child.LocalName)
                {
                case "condition":
                    DecisionNodeEntity ceChild = new DecisionNodeEntity();
                    ceChild.Parent = ce;
                    ceChild.Order  = matchIdx++;
                    loadCondition(ceChild, child);
                    break;

                case "resource-match":
                case "environment-match":
                case "subject-match":
                    loadMatch(matchIdx++, ce, child);
                    break;
                }
            }
        }
コード例 #12
0
        public string GetMatchName(DecisionNodeEntity ame)
        {
            string name = string.Empty;

            if (ame.Extra.Length > 0)
            {
                if (ame.Attribute.AttributeType.Name == "uri")
                {
                    name = string.Format("{0}.{1}", ame.Attribute.Name, ame.Extra);
                }
                else
                {
                    name = string.Format("{0}:{1}", ame.Attribute.Name, ame.Extra);
                }
            }
            else
            {
                name = ame.Attribute.Name;
            }

            return(name);
        }
コード例 #13
0
        private void loadRule(int idx, PolicyEntity pe, XmlNode node)
        {
            RuleEntity re = new RuleEntity();

            re.Policy = pe;
            re.Order  = idx;

            string  effect = "permit";
            XmlNode attr   = node.Attributes.GetNamedItem("effect");

            if (attr != null)
            {
                effect = attr.Value;
            }

            EffectCollection ecoll = new EffectCollection();

            ecoll.GetMulti(EffectFields.Name == effect);
            if (ecoll.Count != 1)
            {
                throw new Exception(string.Format("unrecognised rule effect {0}", effect));
            }
            re.Effect = ecoll[0];

            DecisionNodeEntity ce = new DecisionNodeEntity();

            re.Condition = ce;
            ce.Type      = constants.conditionType;
            ce.IsDirty   = true;

            XmlNode condition = node.SelectSingleNode("condition");

            if (condition != null)
            {
                loadCondition(ce, condition);
            }
        }
コード例 #14
0
        private void loadMatch(int idx, DecisionNodeEntity ce, XmlNode node)
        {
            DecisionNodeEntity ame = new DecisionNodeEntity();

            ame.Type   = constants.attributeMatchType;
            ame.Parent = ce;
            ame.Order  = idx;

            XmlNode attr = node.Attributes.GetNamedItem("attr");

            if (attr == null)
            {
                throw new Exception(string.Format("attr attribute missing from node: {0}", node.InnerXml));
            }

            AttributeCollection acoll = new AttributeCollection();
            string attrVal;
            string attrExtra;

            resolveAttribute(attr.Value, out attrVal, out attrExtra);

            acoll.GetMulti(AttributeFields.Name == attrVal);
            if (acoll.Count == 0)
            {
                throw new Exception(string.Format("unknown attribute {0} (toby please fix this)", attrVal));
            }

            ame.Attribute = acoll[0];
            ame.Extra     = attrExtra;

            attr = node.Attributes.GetNamedItem("match");
            if (attr != null)
            {
                AttributeValueEntity ave = new AttributeValueEntity();
                ave.Order          = 0;
                ave.Attribute      = m_literalAttribute;
                ave.Value          = attr.Value;
                ave.AttributeMatch = ame;
            }
            else
            {
                int valueIdx = 0;
                foreach (XmlNode kid in node.ChildNodes)
                {
                    switch (kid.NodeType)
                    {
                    case XmlNodeType.Text:
                    {
                        AttributeValueEntity ave = new AttributeValueEntity();
                        ave.Order          = valueIdx;
                        ave.Attribute      = m_literalAttribute;
                        ave.Value          = kid.Value.Trim();
                        ave.AttributeMatch = ame;
                    }
                    break;

                    case XmlNodeType.Element:
                    {
                        switch (kid.LocalName)
                        {
                        case "environment-attr":
                            loadAttributeValue(valueIdx, ame, kid);
                            break;

                        case "resource-attr":
                            loadAttributeValue(valueIdx, ame, kid);
                            break;

                        case "subject-attr":
                            loadAttributeValue(valueIdx, ame, kid);
                            break;

                        default:
                            throw new Exception(string.Format("unknown attribute value type: {0}", kid.LocalName));
                            break;
                        }
                    }
                    break;

                    default:
                        break;
                    }
                    valueIdx++;
                }
            }
        }
コード例 #15
0
        private void generate(StringBuilder sb, DecisionNodeEntity match, bool subject)
        {
            if (match.Type == constants.attributeMatchType)
            {
                newLine(sb);
                if (match.Extra.Length == 0)
                {
                    sb.AppendFormat("<{0}-match attr=\"{1}\">", match.Attribute.Context.Name, match.Attribute.Name);
                }
                else
                {
                    if (match.Attribute.AttributeType.Name == "uri")
                    {
                        sb.AppendFormat("<{0}-match attr=\"{1}.{2}\">", match.Attribute.Context.Name, match.Attribute.Name, match.Extra);
                    }
                    else
                    {
                        sb.AppendFormat("<{0}-match attr=\"{1}:{2}\">", match.Attribute.Context.Name, match.Attribute.Name, match.Extra);
                    }
                }

                match.AttributeValue.Sort(AttributeValueFields.Order.FieldIndex, System.ComponentModel.ListSortDirection.Ascending);
                foreach (AttributeValueEntity ave in match.AttributeValue)
                {
                    m_indent++;
                    generate(sb, ave);
                    m_indent--;
                }

                sb.AppendFormat("</{0}-match>", match.Attribute.Context.Name);
            }
            else
            {
                if (subject)
                {
                    foreach (DecisionNodeEntity de in match.Children)
                    {
                        newLine(sb);
                        sb.Append("<subject>");
                        m_indent++;
                        generate(sb, de, false);
                        m_indent--;
                        newLine(sb);
                        sb.Append("</subject>");
                    }
                }
                else
                {
                    newLine(sb);
                    if (match.CombineAnd)
                    {
                        sb.Append("<condition combine=\"and\">");
                    }
                    else
                    {
                        sb.Append("<condition combine=\"or\">");
                    }

                    foreach (DecisionNodeEntity de in match.Children)
                    {
                        m_indent++;
                        generate(sb, de, false);
                        m_indent--;
                    }

                    newLine(sb);
                    sb.Append("</condition>");
                }
            }
        }