The base class for all reference type nodes.
Inheritance: BaseTypeState
Example #1
0
        /// <summary>
        /// Initializes the instance from another instance.
        /// </summary>
        protected override void Initialize(ISystemContext context, NodeState source)
        {
            ReferenceTypeState type = source as ReferenceTypeState;

            if (type != null)
            {
                m_inverseName = type.m_inverseName;
                m_symmetric   = type.m_symmetric;
            }

            base.Initialize(context, source);
        }
        /// <summary>
        /// Creates a new instance.
        /// </summary>
        /// <param name="context">The current context.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="nodeClass">The node class.</param>
        /// <param name="browseName">The browse name.</param>
        /// <param name="referenceTypeId">The reference type between the parent and the node.</param>
        /// <param name="typeDefinitionId">The type definition.</param>
        /// <returns>Returns null if the type is not known.</returns>
        public virtual NodeState CreateInstance(
            ISystemContext context,
            NodeState parent,
            NodeClass nodeClass,
            QualifiedName browseName,
            NodeId referenceTypeId,
            NodeId typeDefinitionId)
        {
            NodeState child = null;

            if (m_types != null && !NodeId.IsNull(typeDefinitionId))
            {
                Type type = null;

                if (m_types.TryGetValue(typeDefinitionId, out type))
                {
                    return(Activator.CreateInstance(type, parent) as NodeState);
                }
            }

            switch (nodeClass)
            {
            case NodeClass.Variable:
            {
                if (context.TypeTable != null && context.TypeTable.IsTypeOf(referenceTypeId, ReferenceTypeIds.HasProperty))
                {
                    child = new PropertyState(parent);
                    break;
                }

                child = new BaseDataVariableState(parent);
                break;
            }

            case NodeClass.Object:
            {
                child = new BaseObjectState(parent);
                break;
            }

            case NodeClass.Method:
            {
                child = new MethodState(parent);
                break;
            }

            case NodeClass.ReferenceType:
            {
                child = new ReferenceTypeState();
                break;
            }

            case NodeClass.ObjectType:
            {
                child = new BaseObjectTypeState();
                break;
            }

            case NodeClass.VariableType:
            {
                child = new BaseDataVariableTypeState();
                break;
            }

            case NodeClass.DataType:
            {
                child = new DataTypeState();
                break;
            }

            case NodeClass.View:
            {
                child = new ViewState();
                break;
            }

            default:
            {
                child = null;
                break;
            }
            }

            return(child);
        }
        /// <summary>
        /// Verifies that the specified node exists.
        /// </summary>
        protected override NodeState ValidateNode(
            ServerSystemContext context,
            NodeHandle handle,
            IDictionary<NodeId, NodeState> cache)
        {
            // not valid if no root.
            if (handle == null)
            {
                return null;
            }

            // check if previously validated.
            if (handle.Validated)
            {
                return handle.Node;
            }

            // lookup in operation cache.
            NodeState target = FindNodeInCache(context, handle, cache);

            if (target != null)
            {
                handle.Node = target;
                handle.Validated = true;
                return handle.Node;
            }

            try
            {
                Opc.Ua.Client.Session client = GetClientSession(context);

                // get remote node.
                NodeId targetId = m_mapper.ToRemoteId(handle.NodeId);
                ILocalNode node = client.ReadNode(targetId) as ILocalNode;

                if (node == null)
                {
                    return null;
                }

                // map remote node to local object.
                switch (node.NodeClass)
                {
                    case NodeClass.ObjectType:
                    {
                        BaseObjectTypeState value = new BaseObjectTypeState();
                        value.IsAbstract = ((IObjectType)node).IsAbstract;
                        target = value;
                        break;
                    }

                    case NodeClass.VariableType:
                    {
                        BaseVariableTypeState value = new BaseDataVariableTypeState();
                        value.IsAbstract = ((IVariableType)node).IsAbstract;
                        value.Value = m_mapper.ToLocalValue(((IVariableType)node).Value);
                        value.DataType = m_mapper.ToLocalId(((IVariableType)node).DataType);
                        value.ValueRank = ((IVariableType)node).ValueRank;
                        value.ArrayDimensions = new ReadOnlyList<uint>(((IVariableType)node).ArrayDimensions);
                        target = value;
                        break;
                    }

                    case NodeClass.DataType:
                    {
                        DataTypeState value = new DataTypeState();
                        value.IsAbstract = ((IDataType)node).IsAbstract;
                        target = value;
                        break;
                    }

                    case NodeClass.ReferenceType:
                    {
                        ReferenceTypeState value = new ReferenceTypeState();
                        value.IsAbstract = ((IReferenceType)node).IsAbstract;
                        value.InverseName = ((IReferenceType)node).InverseName;
                        value.Symmetric = ((IReferenceType)node).Symmetric;
                        target = value;
                        break;
                    }

                    case NodeClass.Object:
                    {
                        BaseObjectState value = new BaseObjectState(null);
                        value.EventNotifier = ((IObject)node).EventNotifier;
                        target = value;
                        break;
                    }

                    case NodeClass.Variable:
                    {
                        BaseDataVariableState value = new BaseDataVariableState(null);
                        value.Value = m_mapper.ToLocalValue(((IVariable)node).Value);
                        value.DataType = m_mapper.ToLocalId(((IVariable)node).DataType);
                        value.ValueRank = ((IVariable)node).ValueRank;
                        value.ArrayDimensions = new ReadOnlyList<uint>(((IVariable)node).ArrayDimensions);
                        value.AccessLevel = ((IVariable)node).AccessLevel;
                        value.UserAccessLevel = ((IVariable)node).UserAccessLevel;
                        value.Historizing = ((IVariable)node).Historizing;
                        value.MinimumSamplingInterval = ((IVariable)node).MinimumSamplingInterval;
                        target = value;
                        break;
                    }

                    case NodeClass.Method:
                    {
                        MethodState value = new MethodState(null);
                        value.Executable = ((IMethod)node).Executable;
                        value.UserExecutable = ((IMethod)node).UserExecutable;
                        target = value;
                        break;
                    }

                    case NodeClass.View:
                    {
                        ViewState value = new ViewState();
                        value.ContainsNoLoops = ((IView)node).ContainsNoLoops;
                        target = value;
                        break;
                    }
                }

                target.NodeId = handle.NodeId;
                target.BrowseName = m_mapper.ToLocalName(node.BrowseName);
                target.DisplayName = node.DisplayName;
                target.Description = node.Description;
                target.WriteMask = node.WriteMask;
                target.UserWriteMask = node.UserWriteMask;
                target.Handle = node;
                target.OnCreateBrowser = OnCreateBrowser;
            }

            // ignore errors.
            catch
            {
                return null;
            }

            // put root into operation cache.
            if (cache != null)
            {
                cache[handle.NodeId] = target;
            }

            handle.Node = target;
            handle.Validated = true;
            return handle.Node;
        }
Example #4
0
        /// <summary>
        /// Does any initialization required before the address space can be used.
        /// </summary>
        /// <remarks>
        /// The externalReferences is an out parameter that allows the node manager to link to nodes
        /// in other node managers. For example, the 'Objects' node is managed by the CoreNodeManager and
        /// should have a reference to the root folder node(s) exposed by this node manager.  
        /// </remarks>
        public override void CreateAddressSpace(IDictionary<NodeId, IList<IReference>> externalReferences)
        {
            lock (Lock)
            {
                BaseObjectState trigger = new BaseObjectState(null);

                trigger.NodeId = new NodeId(1, NamespaceIndex);
                trigger.BrowseName = new QualifiedName("Trigger", NamespaceIndex);
                trigger.DisplayName = trigger.BrowseName.Name;
                trigger.TypeDefinitionId = ObjectTypeIds.BaseObjectType; 

                // ensure trigger can be found via the server object. 
                IList<IReference> references = null;

                if (!externalReferences.TryGetValue(ObjectIds.ObjectsFolder, out references))
                {
                    externalReferences[ObjectIds.ObjectsFolder] = references = new List<IReference>();
                }

                trigger.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ObjectsFolder);
                references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, false, trigger.NodeId));

                PropertyState property = new PropertyState(trigger);

                property.NodeId = new NodeId(2, NamespaceIndex);
                property.BrowseName = new QualifiedName("Matrix", NamespaceIndex);
                property.DisplayName = property.BrowseName.Name;
                property.TypeDefinitionId = VariableTypeIds.PropertyType;
                property.ReferenceTypeId = ReferenceTypeIds.HasProperty;
                property.DataType = DataTypeIds.Int32;
                property.ValueRank = ValueRanks.TwoDimensions;
                property.ArrayDimensions = new ReadOnlyList<uint>(new uint[] { 2, 2 });

                trigger.AddChild(property);

                // save in dictionary. 
                AddPredefinedNode(SystemContext, trigger);

                ReferenceTypeState referenceType = new ReferenceTypeState();

                referenceType.NodeId = new NodeId(3, NamespaceIndex);
                referenceType.BrowseName = new QualifiedName("IsTriggerSource", NamespaceIndex);
                referenceType.DisplayName = referenceType.BrowseName.Name;
                referenceType.InverseName = new LocalizedText("IsSourceOfTrigger");
                referenceType.SuperTypeId = ReferenceTypeIds.NonHierarchicalReferences;

                if (!externalReferences.TryGetValue(ObjectIds.Server, out references))
                {
                    externalReferences[ObjectIds.Server] = references = new List<IReference>();
                }

                trigger.AddReference(referenceType.NodeId, false, ObjectIds.Server);
                references.Add(new NodeStateReference(referenceType.NodeId, true, trigger.NodeId));

                // save in dictionary. 
                AddPredefinedNode(SystemContext, referenceType);
            } 
        }
Example #5
0
        /// <summary>
        /// Creates a new reference type.
        /// </summary>
        private ReferenceTypeState CreateReferenceType(NodeState parent, IDictionary<NodeId, IList<IReference>> externalReferences, string path, string name)
        {
            ReferenceTypeState type = new ReferenceTypeState();

            type.SymbolicName = name;
            type.SuperTypeId = ReferenceTypeIds.NonHierarchicalReferences;
            type.NodeId = new NodeId(path, NamespaceIndex);
            type.BrowseName = new QualifiedName(name, NamespaceIndex);
            type.DisplayName = type.BrowseName.Name;
            type.WriteMask = AttributeWriteMask.None;
            type.UserWriteMask = AttributeWriteMask.None;
            type.IsAbstract = false;
            type.Symmetric = true;
            type.InverseName = name;

            IList<IReference> references = null;

            if (!externalReferences.TryGetValue(ReferenceTypeIds.NonHierarchicalReferences, out references))
            {
                externalReferences[ReferenceTypeIds.NonHierarchicalReferences] = references = new List<IReference>();
            }

            references.Add(new NodeStateReference(ReferenceTypeIds.HasSubtype, false, type.NodeId));

            if (parent != null)
            {
                parent.AddReference(ReferenceTypes.Organizes, false, type.NodeId);
                type.AddReference(ReferenceTypes.Organizes, true, parent.NodeId);
            }

            AddPredefinedNode(SystemContext, type);
            return type;
        }
Example #6
0
        /// <summary>
        /// Converts a ReferenceDescription to an IReference.
        /// </summary>
        private IReference ToReference(ReferenceDescription reference)
        {
            if (reference.NodeId.IsAbsolute || reference.TypeDefinition.IsAbsolute)
            {
                return new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, reference.NodeId);
            }

            if (m_source != null && (reference.NodeId == ObjectIds.ObjectsFolder || reference.NodeId == ObjectIds.Server))
            {
                return new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, m_rootId);
            }

            NodeState target = null;

            switch (reference.NodeClass)
            {
                case NodeClass.DataType: { target = new DataTypeState(); break; }
                case NodeClass.Method: { target = new MethodState(null); break; }
                case NodeClass.Object: { target = new BaseObjectState(null); break; }
                case NodeClass.ObjectType: { target = new BaseObjectTypeState(); break; }
                case NodeClass.ReferenceType: { target = new ReferenceTypeState(); break; }
                case NodeClass.Variable: { target = new BaseDataVariableState(null); break; }
                case NodeClass.VariableType: { target = new BaseDataVariableTypeState(); break; }
                case NodeClass.View: { target = new ViewState(); break; }
            }

            target.NodeId = m_mapper.ToLocalId((NodeId)reference.NodeId);
            target.BrowseName = m_mapper.ToLocalName(reference.BrowseName);
            target.DisplayName = reference.DisplayName;

            if (target is BaseInstanceState)
            {
                ((BaseInstanceState)target).TypeDefinitionId = m_mapper.ToLocalId((NodeId)reference.TypeDefinition);
            }

            return new NodeStateReference(reference.ReferenceTypeId, !reference.IsForward, target);
        }