Skip to content

Commit

Permalink
Add interface for NodeCache (#1364)
Browse files Browse the repository at this point in the history
* feat: add node cache interface
  • Loading branch information
simonjaeger committed Apr 16, 2021
1 parent f2b5c45 commit 0c735eb
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 31 deletions.
91 changes: 61 additions & 30 deletions Libraries/Opc.Ua.Client/NodeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,57 @@ namespace Opc.Ua.Client
/// <summary>
/// A client side cache of the server's type model.
/// </summary>
public class NodeCache : INodeTable, ITypeTable
public interface INodeCache : INodeTable, ITypeTable
{
/// <summary>
/// Loads the UA defined types into the cache.
/// </summary>
/// <param name="context">The context.</param>
void LoadUaDefinedTypes(ISystemContext context);

/// <summary>
/// Removes all nodes from the cache.
/// </summary>
void Clear();

/// <summary>
/// Fetches a node from the server and updates the cache.
/// </summary>
Node FetchNode(ExpandedNodeId nodeId);

/// <summary>
/// Adds the supertypes of the node to the cache.
/// </summary>
void FetchSuperTypes(ExpandedNodeId nodeId);

/// <summary>
/// Returns the references of the specified node that meet the criteria specified.
/// </summary>
IList<INode> FindReferences(ExpandedNodeId nodeId, NodeId referenceTypeId, bool isInverse, bool includeSubtypes);

/// <summary>
/// Returns a display name for a node.
/// </summary>
string GetDisplayText(INode node);

/// <summary>
/// Returns a display name for a node.
/// </summary>
string GetDisplayText(ExpandedNodeId nodeId);

/// <summary>
/// Returns a display name for the target of a reference.
/// </summary>
string GetDisplayText(ReferenceDescription reference);

/// <summary>
/// Builds the relative path from a type to a node.
/// </summary>
NodeId BuildBrowsePath(ILocalNode node, IList<QualifiedName> browsePath);
}

/// <inheritdoc/>
public class NodeCache : INodeCache
{
#region Constructors
/// <summary>
Expand Down Expand Up @@ -576,11 +626,8 @@ public NodeId FindDataTypeId(NodeId encodingId)
}
#endregion

#region Public Methods
/// <summary>
/// Loads the UA defined types into the cache.
/// </summary>
/// <param name="context">The context.</param>
#region INodeCache Methods
/// <inheritdoc/>
public void LoadUaDefinedTypes(ISystemContext context)
{
NodeStateCollection predefinedNodes = new NodeStateCollection();
Expand All @@ -601,17 +648,13 @@ public void LoadUaDefinedTypes(ISystemContext context)
}
}

/// <summary>
/// Removes all nodes from the cache.
/// </summary>
/// <inheritdoc/>
public void Clear()
{
m_nodes.Clear();
}

/// <summary>
/// Fetches a node from the server and updates the cache.
/// </summary>
/// <inheritdoc/>
public Node FetchNode(ExpandedNodeId nodeId)
{
NodeId localId = ExpandedNodeId.ToNodeId(nodeId, m_session.NamespaceUris);
Expand Down Expand Up @@ -659,9 +702,7 @@ public Node FetchNode(ExpandedNodeId nodeId)
return source;
}

/// <summary>
/// Adds the supertypes of the node to the cache.
/// </summary>
/// <inheritdoc/>
public void FetchSuperTypes(ExpandedNodeId nodeId)
{
// find the target node,
Expand Down Expand Up @@ -690,9 +731,7 @@ public void FetchSuperTypes(ExpandedNodeId nodeId)
}
}

/// <summary>
/// Returns the references of the specified node that meet the criteria specified.
/// </summary>
/// <inheritdoc/>
public IList<INode> FindReferences(
ExpandedNodeId nodeId,
NodeId referenceTypeId,
Expand Down Expand Up @@ -727,9 +766,7 @@ public void FetchSuperTypes(ExpandedNodeId nodeId)
return targets;
}

/// <summary>
/// Returns a display name for a node.
/// </summary>
/// <inheritdoc/>
public string GetDisplayText(INode node)
{
// check for null.
Expand Down Expand Up @@ -780,9 +817,7 @@ public string GetDisplayText(INode node)
return node.ToString();
}

/// <summary>
/// Returns a display name for a node.
/// </summary>
/// <inheritdoc/>
public string GetDisplayText(ExpandedNodeId nodeId)
{
if (NodeId.IsNull(nodeId))
Expand All @@ -800,9 +835,7 @@ public string GetDisplayText(ExpandedNodeId nodeId)
return Utils.Format("{0}", nodeId);
}

/// <summary>
/// Returns a display name for the target of a reference.
/// </summary>
/// <inheritdoc/>
public string GetDisplayText(ReferenceDescription reference)
{
if (reference == null || NodeId.IsNull(reference.NodeId))
Expand All @@ -820,9 +853,7 @@ public string GetDisplayText(ReferenceDescription reference)
return reference.ToString();
}

/// <summary>
/// Builds the relative path from a type to a node.
/// </summary>
/// <inheritdoc/>
public NodeId BuildBrowsePath(ILocalNode node, IList<QualifiedName> browsePath)
{
NodeId typeId = null;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Opc.Ua.Client/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ public object Handle
/// <summary>
/// Gets the cache of nodes fetched from the server.
/// </summary>
public NodeCache NodeCache => m_nodeCache;
public INodeCache NodeCache => m_nodeCache;

/// <summary>
/// Gets the context to use for filter operations.
Expand Down

0 comments on commit 0c735eb

Please sign in to comment.