Skip to content

Commit

Permalink
Fix export of TypeDefinitionId (#1604)
Browse files Browse the repository at this point in the history
- the previous fix to remove TypeDefinitionId caused a regression with Alarms (#1574/#1576)
- This is a backward compatible fix to remove the TypeDefintionId where it is not needed in the nodeset but still fill the MethodDeclarationId.
  • Loading branch information
mregen committed Nov 24, 2021
1 parent 1768649 commit 486e97b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Stack/Opc.Ua.Core/Schema/UANodeSetHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@ public void Export(ISystemContext context, NodeState node, bool outputRedundantN
UAMethod value = new UAMethod();
value.Executable = o.Executable;

if (o.TypeDefinitionId != null && !o.TypeDefinitionId.IsNullNodeId && o.TypeDefinitionId != o.NodeId)
if (o.MethodDeclarationId != null && !o.MethodDeclarationId.IsNullNodeId && o.MethodDeclarationId != o.NodeId)
{
value.MethodDeclarationId = Export(o.TypeDefinitionId, context.NamespaceUris);
value.MethodDeclarationId = Export(o.MethodDeclarationId, context.NamespaceUris);
}

if (o.Parent != null)
Expand Down Expand Up @@ -530,7 +530,7 @@ private NodeState Import(ISystemContext context, UANode node)
MethodState value = new MethodState(null);
value.Executable = o.Executable;
value.UserExecutable = o.Executable;
value.TypeDefinitionId = ImportNodeId(o.MethodDeclarationId, context.NamespaceUris, true);
value.MethodDeclarationId = ImportNodeId(o.MethodDeclarationId, context.NamespaceUris, true);
importedNode = value;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions Stack/Opc.Ua.Core/Stack/State/BaseInstanceState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ protected override void Export(ISystemContext context, Node node)
node.ReferenceTable.Add(referenceTypeId, true, this.Parent.NodeId);
}

if (!NodeId.IsNull(this.TypeDefinitionId) && (NodeClass == NodeClass.Object || NodeClass == NodeClass.Variable))
if (!NodeId.IsNull(m_typeDefinitionId) && m_typeDefinitionId != this.NodeId)
{
node.ReferenceTable.Add(ReferenceTypeIds.HasTypeDefinition, false, this.TypeDefinitionId);
}
Expand All @@ -556,7 +556,7 @@ public override void Save(ISystemContext context, XmlEncoder encoder)
encoder.WriteNodeId("ReferenceTypeId", m_referenceTypeId);
}

if (!NodeId.IsNull(m_typeDefinitionId) && (NodeClass == NodeClass.Object || NodeClass == NodeClass.Variable))
if (!NodeId.IsNull(m_typeDefinitionId) && m_typeDefinitionId != this.NodeId)
{
encoder.WriteNodeId("TypeDefinitionId", m_typeDefinitionId);
}
Expand Down Expand Up @@ -588,7 +588,7 @@ public override AttributesToSave GetAttributesToSave(ISystemContext context)
attributesToSave |= AttributesToSave.ReferenceTypeId;
}

if (!NodeId.IsNull(m_typeDefinitionId) && (NodeClass == NodeClass.Object || NodeClass == NodeClass.Variable))
if (!NodeId.IsNull(m_typeDefinitionId) && m_typeDefinitionId != this.NodeId)
{
attributesToSave |= AttributesToSave.TypeDefinitionId;
}
Expand Down
5 changes: 5 additions & 0 deletions Stack/Opc.Ua.Core/Stack/State/MethodState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ public override AttributesToSave GetAttributesToSave(ISystemContext context)
attributesToSave |= AttributesToSave.UserExecutable;
}

if (!NodeId.IsNull(this.MethodDeclarationId) && MethodDeclarationId != NodeId)
{
attributesToSave |= AttributesToSave.TypeDefinitionId;
}

return attributesToSave;
}

Expand Down

0 comments on commit 486e97b

Please sign in to comment.