Opc.Ua.Server.CustomNodeManager2.CreateNode C# (CSharp) Method

CreateNode() public method

Creates a new instance and assigns unique identifiers to all children.
public CreateNode ( ServerSystemContext context, Opc.Ua.NodeId parentId, Opc.Ua.NodeId referenceTypeId, Opc.Ua.QualifiedName browseName, BaseInstanceState instance ) : Opc.Ua.NodeId
context ServerSystemContext The operation context.
parentId Opc.Ua.NodeId An optional parent identifier.
referenceTypeId Opc.Ua.NodeId The reference type from the parent.
browseName Opc.Ua.QualifiedName The browse name.
instance Opc.Ua.BaseInstanceState The instance to create.
return Opc.Ua.NodeId
        public NodeId CreateNode(
            ServerSystemContext context,
            NodeId parentId,
            NodeId referenceTypeId,
            QualifiedName browseName,
            BaseInstanceState instance)
        {
            ServerSystemContext contextToUse = (ServerSystemContext)m_systemContext.Copy(context);

            lock (Lock)
            {
                if (m_predefinedNodes == null)
                {
                    m_predefinedNodes = new NodeIdDictionary<NodeState>();
                }

                instance.ReferenceTypeId = referenceTypeId;

                NodeState parent = null;

                if (parentId != null)
                {
                    if (!m_predefinedNodes.TryGetValue(parentId, out parent))
                    {
                        throw ServiceResultException.Create(
                            StatusCodes.BadNodeIdUnknown,
                            "Cannot find parent with id: {0}",
                            parentId);
                    }

                    parent.AddChild(instance);
                }

                instance.Create(contextToUse, null, browseName, null, true);
                AddPredefinedNode(contextToUse, instance);

                return instance.NodeId;
            }
        }
CustomNodeManager2