public ActionResult AddValue(policyData vData, int id, bool literal, int linkId)
        {
            AttributeValueEntity ave = new AttributeValueEntity();
            ave.AttributeMatchId = id;
            ave.Literal = literal;

            AttributeValueCollection maxColl = new AttributeValueCollection();
            PredicateExpression pe = new PredicateExpression(AttributeValueFields.AttributeMatchId == id);
            object maxObj = maxColl.GetScalar(AttributeValueFieldIndex.Order, null, AggregateFunction.Max,pe);
            if (maxObj != null && maxObj != DBNull.Value)
                ave.Order = (int)maxObj + 1;
            else
                ave.Order = 0;

            if (literal)
                ave.Value = string.Empty;
            else
                ave.Value = null;

            ave.Save();

            return RedirectToAction("EditMatch", new { id = id, linkId = linkId });
        }
        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++;
                }
            }
        }
        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;
        }
        public ActionResult ValueOrder(policyData vData, int id, int id2, int linkId, FormCollection collection)
        {
            AttributeValueEntity attrValue = new AttributeValueEntity(id2);
            AttributeValueCollection coll = new AttributeValueCollection();

            PredicateExpression pe = new PredicateExpression(AttributeValueFields.Id != attrValue.Id);
            pe.Add(AttributeValueFields.AttributeMatchId == id);
            SortExpression se = null;

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

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

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

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

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

            return RedirectToAction("EditMatch", new { id = id, linkId = linkId });
        }
        public ActionResult UpdateAttributeValue(policyData vData, int id, int valueId, int linkId, FormCollection collection)
        {
            AttributeValueEntity attrValue = new AttributeValueEntity(valueId);

            if (attrValue.Literal)
            {
                attrValue.Value = collection["Literal"];
            }
            else
            {
                if (collection["LookupId"] != null && collection["LookupId"] != string.Empty)
                    attrValue.AttributeId = int.Parse(collection["LookupId"]);
                else
                    attrValue.AttributeId = null;
            }

            attrValue.Save();

            TempData["message"] = policyData.detailsSaved;

            return RedirectToAction("EditMatch", new { id = id, linkId = linkId });
        }
        public ActionResult SetAttribute(policyData vData, int id, int id2, int linkId, FormCollection collection)
        {
            vData.DecisionNode = new DecisionNodeEntity(id);
            if (vData.DecisionNode.IsNew)
            {
                vData.DecisionNode.Type = constants.attributeMatchType;

                DecisionNodeCollection maxColl = new DecisionNodeCollection();
                PredicateExpression pe = new PredicateExpression(DecisionNodeFields.ParentId == id2);
                object maxObj = maxColl.GetScalar(DecisionNodeFieldIndex.Order, null, AggregateFunction.Max, pe);
                if (maxObj != null && maxObj != DBNull.Value)
                    vData.DecisionNode.Order = (int)maxObj + 1;
                else
                    vData.DecisionNode.Order = 0;

                AttributeValueEntity ave = new AttributeValueEntity();
                ave.AttributeMatch = vData.DecisionNode;
                ave.Literal = true;
                ave.Value = string.Empty;
            }
            vData.DecisionNode.ParentId = id2;
            vData.DecisionNode.AttributeId = int.Parse(collection["AttributeId"]);

            if (vData.DecisionNode.Attribute.AttributeType.Name == "uri")
                vData.DecisionNode.Extra = collection["uriExtra"];
            else if (vData.DecisionNode.Attribute.AttributeType.Name == "param")
                vData.DecisionNode.Extra = collection["extra"];
            else
                vData.DecisionNode.Extra = string.Empty;

            vData.DecisionNode.Save(true);

            TempData["message"] = policyData.detailsSaved;

            return RedirectToAction("EditMatch", new { id = vData.DecisionNode.Id, linkId = linkId });
        }
        public ActionResult DeleteValue(policyData vData, int id, int valueId, int linkId)
        {
            AttributeValueEntity ave = new AttributeValueEntity(valueId);
            ave.Delete();

            return RedirectToAction("EditMatch", new { id = id, linkId = linkId });
        }
Ejemplo n.º 8
0
        /// <summary>Creates a new, empty AttributeValueEntity object.</summary>
        /// <returns>A new, empty AttributeValueEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new AttributeValueEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewAttributeValue
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }