public string GetLocalItemId(NodeId nodeId)
{
try
{
// check for null.
if (NodeId.IsNull(nodeId))
{
return null;
}
// check for the objects folder (use knowledge of the target to avoid calling the less efficient Equals() method).
if (nodeId.IdType == IdType.Numeric && nodeId.NamespaceIndex == 0)
{
if ((uint)nodeId.Identifier == Objects.ObjectsFolder)
{
return String.Empty;
}
}
// get the lcoal index.
ushort namespaceIndex = GetLocalNamespaceIndex(nodeId.NamespaceIndex);
// check if a mapping is required.
if (namespaceIndex != nodeId.NamespaceIndex)
{
// could happen if the server updates it namespace table.
if (namespaceIndex == UInt16.MaxValue)
{
return null;
}
nodeId = new NodeId(nodeId.Identifier, namespaceIndex);
}
// convert the node id to a string.
string itemId = nodeId.ToString();
// must remove ';' from item id since the CTT does not like them.
#if !NO_CTT_HACK
StringBuilder buffer = new StringBuilder(itemId.Length+2);
for (int ii = 0; ii < itemId.Length; ii++)
{
char ch = itemId[ii];
if (ch == '=')
{
buffer.Append('*');
continue;
}
if (ch == '*')
{
buffer.Append('*');
continue;
}
buffer.Append(ch);
}
itemId = buffer.ToString();
#endif
return itemId;
}
catch (Exception)
{
// oops. probably a programming error.
return null;
}
}
#endregion