Skip to content

Commit

Permalink
Add a warning that the AS contains nodes orphaned and inaccessible fo…
Browse files Browse the repository at this point in the history
…r browsing starting from the Root node #529

- added testing fixture
- UT 👍
  • Loading branch information
mpostol committed Feb 17, 2021
1 parent 4059663 commit 9aa48c9
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 36 deletions.
27 changes: 16 additions & 11 deletions SemanticData/BuildingErrorsHandling/BuildErrors.partial.cs
Original file line number Diff line number Diff line change
@@ -1,83 +1,88 @@
//___________________________________________________________________________________
//
// 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
//___________________________________________________________________________________

namespace UAOOI.SemanticData.BuildingErrorsHandling
{

/// <summary>
/// Enum Focus
/// </summary>
public enum Focus
{

/// <summary>
/// The reference
/// </summary>
Reference,

/// <summary>
/// The diagnostic
/// </summary>
Diagnostic,

/// <summary>
/// The NodeClass
/// </summary>
NodeClass,

/// <summary>
/// The XML error
/// The XML error
/// </summary>
XML,

/// <summary>
/// The non categorized error, e.g. exception during execution.
/// </summary>
NonCategorized,

/// <summary>
/// The data encoding errors - the syntax is validated against OPC UA XML encoding.
/// </summary>
DataEncoding,

/// <summary>
/// The data type definition error - eny error that relates to custom DataType definion.
/// </summary>
DataType,

/// <summary>
/// The naming
/// </summary>
Naming

}

/// <summary>
/// Class BuildError - provides building descriptions of building errors.
/// Class BuildError - provides building descriptions of building errors.
/// </summary>
public partial class BuildError
{

/// <summary>
/// Gets the focus.
/// </summary>
/// <value>The focus.</value>
public Focus Focus { get; set; }

/// <summary>
/// Gets or sets the unique identifier of the error.
/// </summary>
/// <value>The identifier.</value>
public string Identifier { get; set; }

/// <summary>
/// Gets or sets the descriptor of the error.
/// </summary>
/// <value>The descriptor.</value>
public string Descriptor { get; set; }

/// <summary>
/// Returns a <see cref="System.String" /> that represents this instance.
/// </summary>
/// <returns>A <see cref="System.String" /> that represents this instance.</returns>
public override string ToString()
{
return string.Format("Focus:{0}, ErrorID: {1} Info: {2}", Focus, Identifier, Descriptor);
return string.Format("Focus: {0}, Identifier: {1} Description: {2}", Focus, Identifier, Descriptor);
}

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using UAOOI.SemanticData.BuildingErrorsHandling;

namespace UAOOI.SemanticData.UANodeSetValidation.Helpers
Expand All @@ -33,7 +34,7 @@ internal void Clear()

private void TraceDiagnostic(TraceMessage msg, List<TraceMessage> errors, ref int diagnosticCounter)
{
Console.WriteLine(msg.ToString());
Debug.WriteLine(msg.ToString());
if (msg.BuildError.Focus == Focus.Diagnostic)
diagnosticCounter++;
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,23 @@
<ItemGroup>
<Compile Include="DataSerialization\QualifiedNameUnitTest.cs" />
<Compile Include="Helpers\TracedAddressSpaceContext.cs" />
<Compile Include="InformationModelFactory\Class1.cs" />
<Compile Include="InformationModelFactory\DataTypeDefinitionFactoryBase.cs" />
<Compile Include="InformationModelFactory\DataTypeFactoryBase.cs" />
<Compile Include="InformationModelFactory\DataTypeFieldFactoryBase.cs" />
<Compile Include="InformationModelFactory\InformationModelFactoryBase.cs" />
<Compile Include="InformationModelFactory\InstanceFactoryBase.cs" />
<Compile Include="InformationModelFactory\MethodInstanceFactoryBase.cs" />
<Compile Include="InformationModelFactory\NodeFactoryBase.cs" />
<Compile Include="InformationModelFactory\NodesContainer.cs" />
<Compile Include="InformationModelFactory\ObjectInstanceFactoryBase.cs" />
<Compile Include="InformationModelFactory\ObjectTypeFactoryBase.cs" />
<Compile Include="InformationModelFactory\PropertyInstanceFactoryBase.cs" />
<Compile Include="InformationModelFactory\ReferenceFactoryBase.cs" />
<Compile Include="InformationModelFactory\ReferenceTypeFactoryBase.cs" />
<Compile Include="InformationModelFactory\TypeFactoryBase.cs" />
<Compile Include="InformationModelFactory\VariableInstanceFactoryBase.cs" />
<Compile Include="InformationModelFactory\VariableTypeFactoryBase.cs" />
<Compile Include="InformationModelFactory\ViewInstanceFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\DataTypeDefinitionFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\DataTypeFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\DataTypeFieldFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\InformationModelFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\InstanceFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\MethodInstanceFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\NodeFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\NodesContainer.cs" />
<Compile Include="ModelFactoryTestingFixture\ObjectInstanceFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\ObjectTypeFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\PropertyInstanceFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\ReferenceFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\ReferenceTypeFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\TypeFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\VariableInstanceFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\VariableTypeFactoryBase.cs" />
<Compile Include="ModelFactoryTestingFixture\ViewInstanceFactoryBase.cs" />
<Compile Include="Properties\AssemblyInfo.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using UAOOI.SemanticData.BuildingErrorsHandling;
using UAOOI.SemanticData.UANodeSetValidation.Helpers;
using UAOOI.SemanticData.UANodeSetValidation.InformationModelFactory;

namespace UAOOI.SemanticData.UANodeSetValidation
{
Expand Down Expand Up @@ -57,11 +59,15 @@ public void eoursel510Test()
using (TracedAddressSpaceContext traceContext = new TracedAddressSpaceContext())
{
IAddressSpaceContext addressSpace = traceContext.CreateAddressSpaceContext();
InformationModelFactoryBase testingModelFixture = new InformationModelFactoryBase();
addressSpace.InformationModelFactory = testingModelFixture;
Uri model = addressSpace.ImportUANodeSet(_testDataFileInfo);
Assert.AreEqual<int>(0, traceContext.TraceList.Count);
traceContext.Clear();
addressSpace.ValidateAndExportModel(model);
Assert.AreEqual<int>(0, traceContext.TraceList.Count);
Assert.AreEqual(8, testingModelFixture.NumberOfNodes);
Debug.WriteLine($"After removing inherited and instance declaration nodes the recovered information model contains {testingModelFixture.NumberOfNodes}");
}
}

Expand Down
4 changes: 2 additions & 2 deletions SemanticData/UANodeSetValidation/AddressSpaceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,12 @@ private void ValidateAndExportModel(int nameSpaceIndex)
string _msg = null;
if (m_TraceEvent.Errors == 0)
{
_msg = string.Format("Finishing Validator.ValidateExportModel - the model contains {0} nodes.", _nodes.Count);
_msg = $"Finishing Validator.ValidateExportModel - the model contains {_nodes.Count} nodes and no errors/warnings reported";
m_TraceEvent.TraceEvent(TraceMessage.DiagnosticTraceMessage(_msg));
}
else
{
_msg = $"Finishing Validator.ValidateExportModel - the model contains {_nodes.Count} nodes and {m_TraceEvent.Errors} errors.";
_msg = $"Finishing Validator.ValidateExportModel - the model contains {_nodes.Count} nodes and {m_TraceEvent.Errors} errors reported.";
m_TraceEvent.TraceEvent(TraceMessage.BuildErrorTraceMessage(BuildError.ModelContainsErrors, _msg));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ internal class InformationModelFactoryBase : NodesContainer, IModelFactory
/// <param name="version">The version of the model defined in the UANodeSet. This is a human readable string and not intended for programmatic comparisons.</param>
/// <remarks>The set of objects that the OPC Unified Architecture server makes available to clients is referred to as its Address Space. The namespace is provided to make the BrowseName unique in the Address Space.</remarks>
public void CreateNamespace(string uri, string publicationDate, string version) { }

public int NumberOfNodes => this.m_Nodes.Count;
}

}
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 @@ -50,7 +50,7 @@ internal abstract class NodesContainer : INodeContainer
m_Nodes.Add(_df);
return (NodeFactory)(INodeFactory)_df;
}
protected List<NodeFactoryBase> m_Nodes = new List<NodeFactoryBase>();

protected List<NodeFactoryBase> m_Nodes = new List<NodeFactoryBase>();
}
}
}
6 changes: 5 additions & 1 deletion SemanticData/UANodeSetValidation/UANodeContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public XmlQualifiedName ExportNodeBrowseName()
/// <param name="nodeFactory">The node container.</param>
/// <param name="validator">The validator.</param>
/// <exception cref="ArgumentNullException"><paramref name="nodeFactory"/> must not be null.</exception>
//TODO Add a warning that the AS contains nodes orphaned and inaccessible for browsing starting from the Root node #529
void IUANodeBase.CalculateNodeReferences(INodeFactory nodeFactory, IValidator validator)
{
if (nodeFactory == null)
Expand Down Expand Up @@ -182,7 +183,7 @@ void IUANodeBase.CalculateNodeReferences(INodeFactory nodeFactory, IValidator va
case ReferenceKindEnum.HasSubtype:
break;

case ReferenceKindEnum.HasTypeDefinition: //Recognize problems with P3.7.13 HasTypeDefinition ReferenceType #39
case ReferenceKindEnum.HasTypeDefinition: //TODO Recognize problems with P3.7.13 HasTypeDefinition ReferenceType #39
IsProperty = _rfx.TargetNode.IsPropertyVariableType;
break;
}
Expand All @@ -196,7 +197,10 @@ void IUANodeBase.CalculateNodeReferences(INodeFactory nodeFactory, IValidator va
if (!string.IsNullOrEmpty(_rc.TargetNode.BrowseName.Name))
_instanceDeclaration = _derivedChildren.ContainsKey(_rc.TargetNode.BrowseName.Name) ? _derivedChildren[_rc.TargetNode.BrowseName.Name] : null;
if (_rc.TargetNode.Equals(_instanceDeclaration))
{
//_TraceEvent(TraceMessage.DiagnosticTraceMessage($"Removing instance declaration {_rc.TargetNode.ToString()}"));
continue;
}
_rc.TargetNode.RemoveInheritedValues(_instanceDeclaration);
validator.ValidateExportNode(_rc.TargetNode, nodeFactory, _rc);
}
Expand Down

0 comments on commit 9aa48c9

Please sign in to comment.