-
Notifications
You must be signed in to change notification settings - Fork 7
/
UaNodeManager.cs
113 lines (94 loc) · 3.73 KB
/
UaNodeManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using Opc.Ua;
using Opc.Ua.Sample;
using Opc.Ua.Server;
namespace vc2opcua
{
public class UaNodeManager : SampleNodeManager
{
public NodeState baseFolder;
public SystemContext context;
#region Constructors
/// <summary>
/// Initializes the node manager.
/// </summary>
public UaNodeManager(
Opc.Ua.Server.IServerInternal server,
ApplicationConfiguration configuration
)
:
base(server)
{
List<string> namespaceUris = new List<string>
{
Namespaces.vc2opcua,
Namespaces.vc2opcua + "/Instance"
};
NamespaceUris = namespaceUris;
context = SystemContext;
m_typeNamespaceIndex = Server.NamespaceUris.GetIndexOrAppend(namespaceUris[0]);
m_namespaceIndex = Server.NamespaceUris.GetIndexOrAppend(namespaceUris[1]);
}
#endregion
#region Overrides
/// <summary>
/// Loads a node set from a file or resource and adds them to the set of predefined nodes.
/// </summary>
protected override NodeStateCollection LoadPredefinedNodes(ISystemContext context)
{
NodeStateCollection predefinedNodes = new NodeStateCollection();
predefinedNodes.LoadFromBinaryResource(context, "vc2opcua.opcuamodel.vc2opcua.PredefinedNodes.uanodes", this.GetType().GetTypeInfo().Assembly, true);
return predefinedNodes;
}
public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences)
{
lock (Lock)
{
base.CreateAddressSpace(externalReferences);
CreateBaseFolder();
// Raise event address space created
OnAddressSpaceCreated();
}
}
public delegate void AddressSpaceCreatedEventHandler(object source, EventArgs args);
public event AddressSpaceCreatedEventHandler AddressSpaceCreated;
protected virtual void OnAddressSpaceCreated()
{
if (AddressSpaceCreated != null)
{
AddressSpaceCreated(this, EventArgs.Empty);
}
}
private void CreateBaseFolder()
{
// Base folder under which all components will be created
baseFolder = (NodeState)FindPredefinedNode(
ExpandedNodeId.ToNodeId(ObjectIds.VisualComponents_Components, Server.NamespaceUris),
typeof(NodeState));
AddNode(baseFolder);
}
/// <summary>
/// AddPredefindedNode is private, we access it through this method
/// </summary>
public void AddNode(NodeState node) => AddPredefinedNode(SystemContext, node);
public void RemoveNode(NodeState parentNode, NodeState childNode, NodeId referenceType)
{
List<LocalReference> references = new List<LocalReference>();
references.Add(new LocalReference(parentNode.NodeId, referenceType, false, childNode.NodeId));
references.Add(new LocalReference(childNode.NodeId, referenceType, true, parentNode.NodeId));
RemovePredefinedNode(SystemContext, childNode, references);
}
#endregion
#region Private Fields
private ushort m_namespaceIndex;
private ushort m_typeNamespaceIndex;
#endregion
}
}