Skip to content

Commit

Permalink
Import simple NodeSet2 file is incomplete #510
Browse files Browse the repository at this point in the history
- Improved error reporting message for `P3-0503030201 Description: Wrong Reference type targeting`
- UT 👍
  • Loading branch information
mpostol committed Feb 21, 2021
1 parent 52fe0a2 commit dc53d36
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void eoursel510Test()
if (!nodesDictionary.ContainsKey(item.BrowseName.Name))
{
orphanedNodes.Add(item);
Debug.WriteLine($"{item.ToString()}");
Debug.WriteLine($"The following node has been removed from the model: {item.ToString()}");
}
}
Debug.WriteLine($"After removing inherited and instance declaration nodes the recovered information model contains {nodes.Count<NodeFactoryBase>()}");
Expand Down
12 changes: 6 additions & 6 deletions SemanticData/UANodeSetValidation/IUANodeBase.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//___________________________________________________________________________________
//
// Copyright (C) 2019, Mariusz Postol LODZ POLAND.
// Copyright (C) 2021, Mariusz Postol LODZ POLAND.
//
// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI
//___________________________________________________________________________________
Expand Down Expand Up @@ -52,9 +52,10 @@ internal interface IUANodeBase: IEquatable<IUANodeBase>
/// <value><c>true</c> if this instance is property variable type; otherwise, <c>false</c>.</value>
bool IsPropertyVariableType { get; }
/// <summary>
/// Exports the browse name of the base type.
/// Exports the browse name of this node recognized as <see cref="ReferenceKindEnum.HasSubtype"/> or <see cref="ReferenceKindEnum.HasTypeDefinition"/> target.
/// </summary>
/// <param name="traceEvent">The trace event.</param>
/// <returns>An instance of <see cref="XmlQualifiedName"/> representing subtype or type of an instance.</returns>
XmlQualifiedName ExportBrowseNameBaseType(Action<NodeId> traceEvent);
/// <summary>
/// Gets the derived instances.
Expand All @@ -65,11 +66,10 @@ internal interface IUANodeBase: IEquatable<IUANodeBase>
/// </summary>
QualifiedName BrowseName { get; set; }
/// <summary>
/// Exports the BrowseName of the BaseType.
/// Exports the BrowseName of the BaseType.
/// </summary>
/// <param name="type">if set to <c>true</c> the source node represents type. <c>false</c> if it is an instance.</param>
/// <value>An instance of <see cref="XmlQualifiedName" /> representing the base type.</value>
XmlQualifiedName ExportBaseTypeBrowseName(bool type);
/// <returns>An instance of <see cref="XmlQualifiedName" /> representing the base type..</returns>
XmlQualifiedName ExportBaseTypeBrowseName();
/// <summary>
/// Gets the modeling rule associated with this node.
/// </summary>
Expand Down
18 changes: 7 additions & 11 deletions SemanticData/UANodeSetValidation/UANodeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ void IUANodeBase.CalculateNodeReferences(INodeFactory nodeFactory, IValidator va
public bool IsProperty { get; private set; } = false;

/// <summary>
/// Exports the BrowseName of the BaseType.
/// Exports the <see cref="UANode.BrowseName"/> of a node recognized
/// as <see cref="ReferenceKindEnum.HasSubtype"/> or <see cref="ReferenceKindEnum.HasTypeDefinition"/> target.
/// </summary>
/// <param name="type">if set to <c>true</c> the source node represents type. <c>false</c> if it is an instance.</param>
/// <returns>XmlQualifiedName.</returns>
/// <value>An instance of <see cref="XmlQualifiedName" /> representing the base type.</value>
public XmlQualifiedName ExportBaseTypeBrowseName(bool type)
/// <returns>An instance of <see cref="XmlQualifiedName" /> representing the base type..</returns>
public XmlQualifiedName ExportBaseTypeBrowseName()
{
bool type = UANode is UAType;
return m_BaseTypeNode == null ? null : m_BaseTypeNode.ExportBrowseNameBaseType(x => TraceErrorUndefinedBaseType(x, type, _TraceEvent));
}

Expand All @@ -248,10 +248,10 @@ public XmlQualifiedName ExportBaseTypeBrowseName(bool type)
public ModelingRules? ModelingRule { get; private set; } = new Nullable<ModelingRules>();

/// <summary>
/// Exports the browse name of the base type.
/// Exports the browse name of this node recognized as <see cref="ReferenceKindEnum.HasSubtype" /> or <see cref="ReferenceKindEnum.HasTypeDefinition" /> target.
/// </summary>
/// <param name="traceEvent">The trace event.</param>
/// <returns>XmlQualifiedName.</returns>
/// <returns>An instance of <see cref="XmlQualifiedName" /> representing subtype or type of an instance.</returns>
public XmlQualifiedName ExportBrowseNameBaseType(Action<NodeId> traceEvent)
{
//TODO It cannot be the reference type
Expand Down Expand Up @@ -353,10 +353,6 @@ public override string ToString()
private bool m_InGetDerivedInstances = false;

//methods
/// <summary>
/// Gets or sets the name of the m browse.
/// </summary>
/// <value>The name of the m browse.</value>
private void TraceErrorUndefinedBaseType(NodeId target, bool type, Action<TraceMessage> traceEvent)
{
if (type)
Expand Down
20 changes: 15 additions & 5 deletions SemanticData/UANodeSetValidation/Validator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,20 @@ private void Update(IPropertyInstanceFactory propertyInstance, UAVariable nodeSe
Update(propertyInstance, nodeSet);
propertyInstance.ReferenceType = parentReference == null ? null : parentReference.GetReferenceTypeName();
if (!nodeContext.IsProperty)
m_buildErrorsHandling.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, $"Creating Property {nodeContext.BrowseName}- wrong reference type {parentReference.ReferenceKind.ToString()}"));
{
XmlQualifiedName baseType = nodeContext.ExportBaseTypeBrowseName();
string baseTypeName = baseType == null ? "a base type" : $"the {baseType.ToString()} type.";
m_buildErrorsHandling.TraceEvent
(
TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property,
$"Target node of the {parentReference.ReferenceKind.ToString()} reference cannot be {nodeContext.BrowseName} of {baseTypeName}.")
);
}
}
catch (Exception _ex)
{
m_buildErrorsHandling.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, string.Format("Cannot resolve the reference for Property because of error {0} at: {1}.", _ex, _ex.StackTrace)));
m_buildErrorsHandling.TraceEvent(
TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, string.Format("Cannot resolve the reference for Property because of error {0} at: {1}.", _ex, _ex.StackTrace)));
}
}

Expand All @@ -155,7 +164,8 @@ private void Update(IVariableInstanceFactory variableInstance, UAVariable nodeSe
}
catch (Exception _ex)
{
m_buildErrorsHandling.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, string.Format("Cannot resolve the reference for Variable because of error {0} at: {1}.", _ex, _ex.StackTrace)));
m_buildErrorsHandling.TraceEvent(
TraceMessage.BuildErrorTraceMessage(BuildError.WrongReference2Property, string.Format("Cannot resolve the reference for Variable because of error {0} at: {1}.", _ex, _ex.StackTrace)));
}
}

Expand Down Expand Up @@ -279,15 +289,15 @@ private AccessRestrictions ConvertToAccessRestrictions(byte accessRestrictions,

private void UpdateType(ITypeFactory nodeDesign, UAType nodeSet, IUANodeBase nodeContext)
{
nodeDesign.BaseType = nodeContext.ExportBaseTypeBrowseName(true);
nodeDesign.BaseType = nodeContext.ExportBaseTypeBrowseName();
nodeDesign.IsAbstract = nodeSet.IsAbstract;
}

private static void UpdateInstance(IInstanceFactory nodeDesign, UAInstance nodeSet, IUANodeBase nodeContext)
{
if (nodeContext.ModelingRule.HasValue)
nodeDesign.ModelingRule = nodeContext.ModelingRule.Value;
nodeDesign.TypeDefinition = nodeContext.ExportBaseTypeBrowseName(false);
nodeDesign.TypeDefinition = nodeContext.ExportBaseTypeBrowseName();
//nodeSet.ParentNodeId - The NodeId of the Node that is the parent of the Node within the information model. This field is used to indicate
//that a tight coupling exists between the Node and its parent (e.g. when the parent is deleted the child is deleted
//as well). This information does not appear in the AddressSpace and is intended for use by design tools.
Expand Down

0 comments on commit dc53d36

Please sign in to comment.