The base class for all view nodes.
Inheritance: NodeState
        /// <summary>
        /// Makes a copy of the node and all children.
        /// </summary>
        /// <returns>
        /// A new object that is a copy of this instance.
        /// </returns>
        public object MemberwiseClone(NodeState parent)
        {
            ViewState clone = new ViewState();

            if (m_children != null)
            {
                clone.m_children = new List<BaseInstanceState>(m_children.Count);

                for (int ii = 0; ii < m_children.Count; ii++)
                {
                    BaseInstanceState child = (BaseInstanceState)m_children[ii].MemberwiseClone();
                    clone.m_children.Add(child);
                }
            }

            clone.m_changeMasks = NodeStateChangeMasks.None;

            return clone;
        }
Ejemplo n.º 2
0
        /// <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;
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new view.
        /// </summary>
        private ViewState CreateView(NodeState parent, IDictionary<NodeId, IList<IReference>> externalReferences, string path, string name)
        {
            ViewState type = new ViewState();

            type.SymbolicName = name;
            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.ContainsNoLoops = true;

            IList<IReference> references = null;

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

            type.AddReference(ReferenceTypeIds.Organizes, true, ObjectIds.ViewsFolder);
            references.Add(new NodeStateReference(ReferenceTypeIds.Organizes, 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;
        }
Ejemplo n.º 5
0
        /// <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);
        }