public TranslateNamespaceIndexes ( Opc.Ua.NamespaceTable currentTable, Opc.Ua.NamespaceTable targetTable ) : void | ||
currentTable | Opc.Ua.NamespaceTable | The NamespaceTable which the RelativePathString currently references |
targetTable | Opc.Ua.NamespaceTable | The NamespaceTable which the RelativePathString should reference |
return | void |
public void TranslateNamespaceIndexes(NamespaceTable currentTable, NamespaceTable targetTable)
{
// build mapping table.
int[] mappings = new int[currentTable.Count];
mappings[0] = 0;
// copy mappings.
string[] uris = new string[mappings.Length];
for (int ii = 1; ii < mappings.Length; ii++)
{
uris[ii] = currentTable.GetString((uint)ii);
if (uris[ii] != null)
{
mappings[ii] = targetTable.GetIndex(uris[ii]);
}
}
// update each element.
foreach (Element element in m_elements)
{
QualifiedName qname = element.ReferenceTypeName;
if (qname != null && qname.NamespaceIndex > 0)
{
if (qname.NamespaceIndex < mappings.Length && mappings[qname.NamespaceIndex] > 0)
{
element.ReferenceTypeName = new QualifiedName(qname.Name, (ushort)mappings[qname.NamespaceIndex]);
}
}
qname = element.TargetName;
if (qname != null && qname.NamespaceIndex > 0)
{
if (qname.NamespaceIndex < mappings.Length && mappings[qname.NamespaceIndex] > 0)
{
element.TargetName = new QualifiedName(qname.Name, (ushort)mappings[qname.NamespaceIndex]);
}
}
}
}
#endregion
/// <summary> /// Parses a string representing a relative path and translates the namespace indexes. /// </summary> /// <remarks> /// Parses a string representing a relative path. /// </remarks> /// <exception cref="ServiceResultException">Thrown if any errors occur during parsing</exception> public static RelativePathFormatter Parse(string textToParse, NamespaceTable currentTable, NamespaceTable targetTable) { RelativePathFormatter path = Parse(textToParse); if (path != null) { path.TranslateNamespaceIndexes(currentTable, targetTable); } return(path); }