Skip to content

Commit

Permalink
IModelTableEntry must be updated during import. #523
Browse files Browse the repository at this point in the history
- IModelTableEntry is read-only
  • Loading branch information
mpostol committed Feb 13, 2021
1 parent 23bdf0d commit f7f1d13
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ private List<IUANodeContext> ValidateAndExportModelUnitTest(FileInfo testDataFil
List<TraceMessage> _trace = new List<TraceMessage>();
IAddressSpaceContext _as = new AddressSpaceContext(z => TraceDiagnostic(z, _trace));
_trace.Clear();
_as.ImportUANodeSet(testDataFileInfo);
Uri model = _as.ImportUANodeSet(testDataFileInfo);
Assert.AreEqual<int>(0, _trace.Count);
((AddressSpaceContext)_as).UTAddressSpaceCheckConsistency(x => { Assert.Fail(); });
((AddressSpaceContext)_as).UTReferencesCheckConsistency((x, y, z, v) => Assert.Fail());
IEnumerable<IUANodeContext> _nodes = null;
((AddressSpaceContext)_as).UTValidateAndExportModel(1, x => _nodes = x);
Assert.AreEqual<int>(numberOfNodes, _nodes.Count<IUANodeContext>());
_as.ValidateAndExportModel();
_as.ValidateAndExportModel(model.ToString());
Assert.AreEqual<int>(0, _trace.Count);
return _nodes.ToList<IUANodeContext>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//___________________________________________________________________________________

using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
Expand All @@ -25,9 +26,9 @@ public void ADITest()
Assert.IsTrue(_testDataFileInfo.Exists);
List<TraceMessage> _trace = new List<TraceMessage>();
IAddressSpaceContext _as = new AddressSpaceContext(z => _trace.Add(z));
_as.ImportUANodeSet(_testDataFileInfo);
Uri model = _as.ImportUANodeSet(_testDataFileInfo);
Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic).Count<TraceMessage>());
_as.ValidateAndExportModel(@"http://opcfoundation.org/UA/ADI/");
_as.ValidateAndExportModel(model.ToString());
IEnumerable<TraceMessage> vitalMessageserrors = _trace.Where<TraceMessage>(x => x.BuildError.Focus != Focus.Diagnostic);
IEnumerable<TraceMessage> focusNodeClass = _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.NodeClass);
Assert.IsFalse(focusNodeClass.Where<TraceMessage>(x => !x.BuildError.Identifier.Trim().Contains("P3-0502020001")).Any<TraceMessage>());
Expand Down Expand Up @@ -55,11 +56,11 @@ public void eoursel510Test()
Assert.IsTrue(_testDataFileInfo.Exists);
List<TraceMessage> _trace = new List<TraceMessage>();
IAddressSpaceContext _as = new AddressSpaceContext(z => _trace.Add(z));
_as.ImportUANodeSet(_testDataFileInfo);
Uri model = _as.ImportUANodeSet(_testDataFileInfo);
//Extensions is omitted during the import
Assert.AreEqual<int>(10, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.Diagnostic).Count<TraceMessage>());
Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.XML).Count<TraceMessage>());
_as.ValidateAndExportModel();
_as.ValidateAndExportModel(model.ToString());
Assert.AreEqual<int>(16, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.Diagnostic).Count<TraceMessage>());
Assert.AreEqual<int>(1, _trace.Where<TraceMessage>(x => x.BuildError.Focus == Focus.XML).Count<TraceMessage>());

Expand Down
11 changes: 6 additions & 5 deletions SemanticData/UANodeSetValidation/AddressSpaceContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,28 +68,28 @@ public IModelFactory InformationModelFactory
/// </summary>
/// <param name="model">The model to be imported.</param>
/// <exception cref="System.ArgumentNullException">model;the model cannot be null</exception>
void IAddressSpaceContext.ImportUANodeSet(UANodeSet model)
Uri IAddressSpaceContext.ImportUANodeSet(UANodeSet model)
{
m_TraceEvent(TraceMessage.DiagnosticTraceMessage("Entering AddressSpaceContextService.ImportUANodeSet - importing from object model."));
if (model == null)
throw new ArgumentNullException("model", "the model cannot be null");
ImportNodeSet(model, m_TraceEvent);
return ImportNodeSet(model, m_TraceEvent);
}

/// <summary>
/// Imports a part of the OPC UA Address Space contained in the file <see cref="FileInfo" />.
/// </summary>
/// <param name="model">The model to be imported.</param>
/// <exception cref="System.IO.FileNotFoundException">The imported file does not exist</exception>
void IAddressSpaceContext.ImportUANodeSet(FileInfo model)
Uri IAddressSpaceContext.ImportUANodeSet(FileInfo model)
{
m_TraceEvent(TraceMessage.DiagnosticTraceMessage("Entering AddressSpaceContextService.ImportUANodeSet - importing form file"));
if (model == null)
throw new ArgumentNullException("model", "the model cannot be null");
if (!model.Exists)
throw new FileNotFoundException("The imported file does not exist", model.FullName);
UANodeSet _nodeSet = UANodeSet.ReadModelFile(model);
ImportNodeSet(_nodeSet, m_TraceEvent);
return ImportNodeSet(_nodeSet, m_TraceEvent);
}

/// <summary>
Expand Down Expand Up @@ -300,14 +300,15 @@ public Parameter ExportArgument(DataSerialization.Argument argument)
private readonly Action<TraceMessage> m_TraceEvent = BuildErrorsHandling.Log.TraceEvent;

//methods
private void ImportNodeSet(UANodeSet model, Action<TraceMessage> traceEvent)
private Uri ImportNodeSet(UANodeSet model, Action<TraceMessage> traceEvent)
{
IUAModelContext _modelContext = model.ParseUAModelContext(this, traceEvent);
traceEvent(TraceMessage.DiagnosticTraceMessage($"Entering AddressSpaceContext.ImportNodeSet - starting import {_modelContext}."));
traceEvent(TraceMessage.DiagnosticTraceMessage("AddressSpaceContext.ImportNodeSet - the context for the imported model is created and starting import nodes."));
foreach (UANode _nd in model.Items)
ImportUANode(_nd, m_TraceEvent);
m_TraceEvent(TraceMessage.DiagnosticTraceMessage($"Finishing AddressSpaceContext.ImportNodeSet - imported {model.Items.Length} nodes."));
return _modelContext.ModelUri;
}

private void ImportUANode(UANode node, Action<TraceMessage> traceEvent)
Expand Down
18 changes: 9 additions & 9 deletions SemanticData/UANodeSetValidation/IAddressSpaceContext.cs
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
//___________________________________________________________________________________
//
// 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
//___________________________________________________________________________________

using System;
using System.IO;
using UAOOI.SemanticData.InformationModelFactory;
using UAOOI.SemanticData.UANodeSetValidation.XML;

namespace UAOOI.SemanticData.UANodeSetValidation
{

/// <summary>
/// Interface IAddressSpaceContext - represents a service used to buildup OPc UA Address Space
/// </summary>
public interface IAddressSpaceContext
{

/// <summary>
/// Imports a part of the OPC UA Address Space contained in the <see cref="UANodeSet" /> object model.
/// </summary>
/// <param name="model">The model to be imported.</param>
void ImportUANodeSet(UANodeSet model);
Uri ImportUANodeSet(UANodeSet model);

/// <summary>
/// Imports a part of the OPC UA Address Space contained in the file <paramref name="model"/> of type <see cref="FileInfo" /> compliant with the `UANodeSet` schema.
/// </summary>
/// <param name="model">The model to be imported.</param>
void ImportUANodeSet(FileInfo model);
Uri ImportUANodeSet(FileInfo model);

/// <summary>
/// Sets the information model factory, which can be used to export a part of the OPC UA Address Space. If not set or set null an internal stub implementation will be used.
/// </summary>
/// <remarks>It is defined to handle dependency injection.</remarks>
/// <value>The information model factory.</value>
IModelFactory InformationModelFactory { set; }

/// <summary>
/// Validates and exports the selected model for the default namespace at index 1 if defined or standard OPC UA.
/// </summary>
void ValidateAndExportModel();

/// <summary>
/// Validates and exports the selected model.
/// </summary>
/// <param name="targetNamespace">The target namespace of the validated model.</param>
void ValidateAndExportModel(string targetNamespace);

}


}
}
12 changes: 6 additions & 6 deletions SemanticData/UANodeSetValidation/IModelTableEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,37 +20,37 @@ public interface IModelTableEntry
/// Gets or sets the access restrictions. The default <c>AccessRestrictions</c> that apply to all <c>Nodes</c> in the model.
/// </summary>
/// <value>The access restrictions.</value>
byte AccessRestrictions { get; set; }
byte AccessRestrictions { get; }

/// <summary>
/// Gets or sets the model URI. The URI for the model. This URI should be one of the entries in the <see cref="NamespaceTable"/> table.
/// </summary>
/// <value>The model URI.</value>
string ModelUri { get; set; }
string ModelUri { get; }

/// <summary>
/// Gets or sets the publication date. When the model was published. This value is used for comparisons if the model is defined in multiple UANodeSet files.
/// </summary>
/// <value>The publication date.</value>
DateTime? PublicationDate { get; set; }
DateTime? PublicationDate { get; }

/// <summary>
/// Gets or sets the required model. A list of dependencies for the model. If the model requires a minimum version the PublicationDate shall be specified.
/// Tools which attempt to resolve these dependencies may accept any PublicationDate after this date.
/// </summary>
/// <value>The required model.</value>
IModelTableEntry[] RequiredModel { get; set; }
IModelTableEntry[] RequiredModel { get; }

/// <summary>
/// Gets or sets the role permissions. The list of default RolePermissions for all Nodes in the model.
/// </summary>
/// <value>The role permissions.</value>
IRolePermission[] RolePermissions { get; set; }
IRolePermission[] RolePermissions { get; }

/// <summary>
/// Gets or sets the version. The version of the model defined in the UANodeSet. This is a human readable string and not intended for programmatic comparisons.
/// </summary>
/// <value>The version.</value>
string Version { get; set; }
string Version { get; }
}
}
14 changes: 9 additions & 5 deletions SemanticData/UANodeSetValidation/IUAModelContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,34 @@
// To be in touch join the community at GITTER: https://gitter.im/mpostol/OPC-UA-OOI
//___________________________________________________________________________________

using System;
using UAOOI.SemanticData.UANodeSetValidation.DataSerialization;

namespace UAOOI.SemanticData.UANodeSetValidation
{

/// <summary>
/// Interface IUAModelContext - represents an OPC UA Information Model
/// </summary>
internal interface IUAModelContext
public interface IUAModelContext
{
/// <summary>
/// Gets the model URI.
/// </summary>
/// <value>The model URI.</value>
Uri ModelUri { get; }

/// <summary>
/// Imports the qualified name. It recalculates the <see cref="QualifiedName.NamespaceIndex"/> against local namespace index table.
/// Imports the qualified name. It recalculates the <see cref="QualifiedName.NamespaceIndex"/> against local namespace index table.
/// </summary>
/// <param name="qualifiedName">The <see cref="QualifiedName"/> serialized as string to be imported.</param>
/// <returns> An instance of the <see cref="QualifiedName"/> with recalculated <see cref="QualifiedName.NamespaceIndex"/>.</returns>
string ImportQualifiedName(string qualifiedName);

/// <summary>
/// Imports the node identifier if <paramref name="nodeId"/> is not empty.
/// </summary>
/// <param name="nodeId">The node identifier with the syntax defined in Part 6-5.3.1.10.</param>
/// <returns>An instance of the <see cref="NodeId"/> or null is the <paramref name="nodeId"/> is null or empty.</returns>
string ImportNodeId(string nodeId);

}

}
3 changes: 0 additions & 3 deletions SemanticData/UANodeSetValidation/NamespaceTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ internal void UpadateModelOrAppend(IModelTableEntry model)

//var

//private readonly Dictionary<string, ModelTableEntry> m_URIDictionary = new Dictionary<string, ModelTableEntry>();
//private Dictionary<ushort, string> m_IndexDictionary = new Dictionary<ushort, string>();
//private ushort m_Index = 0;
private List<IModelTableEntry> modelsList = new List<IModelTableEntry>();

//classes
Expand Down
3 changes: 2 additions & 1 deletion SemanticData/UANodeSetValidation/XML/UAModelContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,13 @@ internal static UAModelContext ParseUANodeSetModelHeader(IUANodeSetModelHeader m
return context2Return;
}

internal Uri ModelUri { get; private set; }

#endregion API

#region IUAModelContext

public Uri ModelUri { get; private set; }

public string ImportQualifiedName(string source)
{
QualifiedName _qn = QualifiedName.Parse(source);
Expand Down

0 comments on commit f7f1d13

Please sign in to comment.