Opc.Ua.Server.CoreNodeManager.CreateDataType C# (CSharp) Method

CreateDataType() public method

Creates an DataType node in the address space.
public CreateDataType ( NodeId parentId, NodeId nodeId, QualifiedName browseName, LocalizedText displayName, LocalizedText description, uint writeMask, uint userWriteMask, bool isAbstract, NodeId>.IDictionary encodings ) : NodeId
parentId NodeId
nodeId NodeId
browseName QualifiedName
displayName LocalizedText
description LocalizedText
writeMask uint
userWriteMask uint
isAbstract bool
encodings NodeId>.IDictionary
return NodeId
        public NodeId CreateDataType(
            NodeId                            parentId,
            NodeId                            nodeId,
            QualifiedName                     browseName,
            LocalizedText                     displayName,
            LocalizedText                     description,
            uint                              writeMask,
            uint                              userWriteMask,
            bool                              isAbstract,
            IDictionary<QualifiedName,NodeId> encodings)
        {
             if (parentId == null)   throw new ArgumentNullException("parentId");
            if (browseName == null) throw new ArgumentNullException("browseName");

            try
            {
                m_lock.Enter();

                // check for null node id.
                if (NodeId.IsNull(nodeId))
                {
                    nodeId = CreateUniqueNodeId();
                }

                // check if node id exists.
                if (m_nodes.Exists(nodeId))
                {
                    throw ServiceResultException.Create(StatusCodes.BadNodeIdExists, "NodeId '{0}' already exists.", nodeId);
                }

                // find parent.
                IDataType parent = GetManagerHandle(parentId) as IDataType;

                if (parent == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadParentNodeIdInvalid, "Parent node '{0}' does not exist or is not an DataTypeNode.", parentId);
                }
                
                // validate reference.
                ValidateReference(parent, ReferenceTypeIds.HasSubtype, false, NodeClass.DataType);

                // validate browse name.
                if (QualifiedName.IsNull(browseName))
                {
                    throw ServiceResultException.Create(StatusCodes.BadBrowseNameInvalid, "BrowsName must not be empty.");
                }

                // create node.
                DataTypeNode node = new DataTypeNode();
                
                node.NodeId          = nodeId;
                node.NodeClass       = NodeClass.DataType;
                node.BrowseName      = browseName;
                node.DisplayName     = displayName;
                node.WriteMask     = writeMask;
                node.UserWriteMask = userWriteMask;
                node.Description     = description;
                node.IsAbstract      = isAbstract;

                // add reference from parent.
                AddReference(parent, ReferenceTypeIds.HasSubtype, false, node, true);

                // add node.
                AddNode(node);

                // add the encodings.
                if (encodings != null)
                {
                    List<QualifiedName> encodingNames = new List<QualifiedName>(encodings.Keys);

                    foreach (QualifiedName encodingName in encodingNames)
                    {
                        // assign a unique id to the encoding if none provided.
                        NodeId encodingId = encodings[encodingName];
                        
                        if (NodeId.IsNull(encodingId))
                        {
                            encodingId = CreateUniqueNodeId();
                        }

                        ObjectAttributes attributes = new ObjectAttributes();
                        attributes.SpecifiedAttributes = (uint)NodeAttributesMask.None;

                        // return the actual id.
                        encodings[encodingName] = CreateObject(
                            nodeId,
                            ReferenceTypeIds.HasEncoding,
                            encodingId,
                            encodingName,
                            attributes,
                            ObjectTypes.DataTypeEncodingType);
                    }
                }
                                
                // return the new node id.
                return node.NodeId;
            }
            finally
            {
                m_lock.Exit();
            } 
        }
        #endif