コード例 #1
0
        private static bool SetNodeAttributeValue(Oid nodeId, string value, IServerSession session)
        {
            IModelFactory dacFactory = session.DataAccess.ModelFactory;
            INodeBroker   nodeBroker = session.DataAccess.Brokers.Node;
            ISelector     nodeIdSel  = dacFactory.CreateSelectorById(nodeId);

            Console.WriteLine("Updating attribute values for Node {0}... ", nodeId);
            NodeAttributeValues attrValues;

            using (var result = nodeBroker.ReadSingle(nodeIdSel, null))
            {
                if (result.IsSuccess)
                {
                    attrValues = result.Value.Attributes;
                }
                else
                {
                    Console.WriteLine("failed: " + result.ToString());
                    return(false);
                }
            }
            IChangeSet changes = session.DataAccess.CreateChangeSet();
            INode      node    = session.DataAccess.ModelFactory.CreateNode();

            node.Attributes = attrValues;
            node.Attributes[ATTRIBUTE_NAME] = value;
            nodeBroker.UpdateNodes(changes, node, nodeIdSel);
            using (var result = changes.Save())
            {
                if (result.IsSuccess)
                {
                    Console.WriteLine("success");
                    return(true);
                }
                else
                {
                    Console.WriteLine("failed: " + result.ToString());
                    return(false);
                }
            }
        }