public void Add(ILocalNode node)
{
// ignore null.
if (node == null || NodeId.IsNull(node.NodeId))
{
return;
}
// ignore non-types.
if ((node.NodeClass & (NodeClass.ObjectType | NodeClass.VariableType | NodeClass.ReferenceType | NodeClass.DataType)) == 0)
{
return;
}
NodeId localsuperTypeId = null;
// find the supertype.
ExpandedNodeId superTypeId = node.References.FindTarget(ReferenceTypeIds.HasSubtype, true, false, null, 0);
if (superTypeId != null)
{
localsuperTypeId = ExpandedNodeId.ToNodeId(superTypeId, m_namespaceUris);
if (localsuperTypeId == null)
{
throw ServiceResultException.Create(StatusCodes.BadNodeIdInvalid, "A valid supertype identifier is required.");
}
}
lock (m_lock)
{
// lookup the supertype.
TypeInfo superTypeInfo = null;
if (localsuperTypeId != null)
{
if (!m_nodes.TryGetValue(localsuperTypeId, out superTypeInfo))
{
throw ServiceResultException.Create(StatusCodes.BadNodeIdInvalid, "A valid supertype identifier is required.");
}
}
// create the type info.
TypeInfo typeInfo = null;
if (!m_nodes.TryGetValue(node.NodeId, out typeInfo))
{
typeInfo = new TypeInfo();
m_nodes.Add(node.NodeId, typeInfo);
}
// update the info.
typeInfo.NodeId = node.NodeId;
typeInfo.SuperType = superTypeInfo;
typeInfo.Deleted = false;
// add to supertype.
if (superTypeInfo != null)
{
superTypeInfo.AddSubType(typeInfo);
}
// remove the encodings.
if (typeInfo.Encodings != null)
{
foreach (NodeId encoding in typeInfo.Encodings)
{
m_encodings.Remove(encoding);
}
}
// any new encodings.
IList<IReference> encodings = node.References.Find(ReferenceTypeIds.HasEncoding, false, false, null);
if (encodings.Count > 0)
{
typeInfo.Encodings = new NodeId[encodings.Count];
for (int ii = 0; ii < encodings.Count; ii++)
{
typeInfo.Encodings[ii] = ExpandedNodeId.ToNodeId(encodings[ii].TargetId, m_namespaceUris);
m_encodings[typeInfo.Encodings[ii]] = typeInfo;
}
}
// add reference type.
if ((node.NodeClass & NodeClass.ReferenceType) != 0)
{
if (!QualifiedName.IsNull(typeInfo.BrowseName))
{
m_referenceTypes.Remove(typeInfo.BrowseName);
}
typeInfo.BrowseName = node.BrowseName;
m_referenceTypes[node.BrowseName] = typeInfo;
}
}
}