Exemplo n.º 1
0
        /// <summary>
        /// Adds a container for the reference type to the tree control.
        /// </summary>
        private TreeNode FindReferenceTypeContainer(TreeNode parent, ReferenceDescription reference)
        {
            if (parent == null)
            {
                return(null);
            }

            if (reference.ReferenceTypeId.IsNullNodeId)
            {
                Utils.Trace("NULL reference type id, for reference: {0}", reference.DisplayName);
                return(null);
            }

            ReferenceTypeNode typeNode = m_browser.Session.NodeCache.Find(reference.ReferenceTypeId) as ReferenceTypeNode;

            foreach (TreeNode child in parent.Nodes)
            {
                NodeId referenceTypeId = child.Tag as NodeId;

                if (typeNode.NodeId == referenceTypeId)
                {
                    if (typeNode.InverseName == null)
                    {
                        return(child);
                    }

                    if (reference.IsForward)
                    {
                        if (child.Text == typeNode.DisplayName.Text)
                        {
                            return(child);
                        }
                    }
                    else
                    {
                        if (child.Text == typeNode.InverseName.Text)
                        {
                            return(child);
                        }
                    }
                }
            }

            if (typeNode != null)
            {
                string text = typeNode.DisplayName.Text;
                string icon = "ReferenceType";

                if (!reference.IsForward && typeNode.InverseName != null)
                {
                    text = typeNode.InverseName.Text;
                }

                return(AddNode(parent, typeNode.NodeId, text, icon));
            }

            Utils.Trace("Reference type id not found for: {0}", reference.ReferenceTypeId);

            return(null);
        }
Exemplo n.º 2
0
 public ItemData(ReferenceTypeNode referenceType, bool isInverse, Node target, Node typeDefinition)
 {
     ReferenceType  = referenceType;
     IsInverse      = isInverse;
     Target         = target;
     TypeDefinition = typeDefinition;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Exports a copy of the node to a node table.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="node">The node.</param>
        protected override void Export(ISystemContext context, Node node)
        {
            base.Export(context, node);

            ReferenceTypeNode referenceTypeNode = node as ReferenceTypeNode;

            if (referenceTypeNode != null)
            {
                referenceTypeNode.InverseName = this.InverseName;
                referenceTypeNode.Symmetric   = this.Symmetric;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Adds a container for the reference type to the tree control.
        /// </summary>
        private TreeItemViewModel FindReferenceTypeContainer(TreeItemViewModel parent, ReferenceDescription reference)
        {
            if (parent == null)
            {
                return(null);
            }

            ReferenceTypeNode typeNode = m_browser.Session.NodeCache.Find(reference.ReferenceTypeId) as ReferenceTypeNode;

            foreach (TreeItemViewModel child in parent.Children)
            {
                NodeId referenceTypeId = child.Item as NodeId;

                if (typeNode.NodeId == referenceTypeId)
                {
                    if (typeNode.InverseName == null)
                    {
                        return(child);
                    }

                    if (reference.IsForward)
                    {
                        if (child.Text == typeNode.DisplayName.Text)
                        {
                            return(child);
                        }
                    }
                    else
                    {
                        if (child.Text == typeNode.InverseName.Text)
                        {
                            return(child);
                        }
                    }
                }
            }

            string text = typeNode.DisplayName.Text;
            string icon = "ReferenceType";

            if (!reference.IsForward && typeNode.InverseName != null)
            {
                text = typeNode.InverseName.Text;
            }

            return(AddNode(parent, typeNode.NodeId, text, icon));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Adds the reference types to drop down box.
        /// </summary>
        private void AddReferenceTypes(ExpandedNodeId referenceTypeId, ReferenceTypeChoice supertype)
        {
            if (referenceTypeId == null)
            {
                throw new ApplicationException("referenceTypeId");
            }

            try
            {
                // find reference.
                ReferenceTypeNode node = m_session.NodeCache.Find(referenceTypeId) as ReferenceTypeNode;

                if (node == null)
                {
                    return;
                }

                // add reference to combobox.
                ReferenceTypeChoice choice = new ReferenceTypeChoice();

                choice.ReferenceType = node;
                choice.SuperType     = supertype;

                ReferenceTypesCB.Items.Add(choice);

                // recursively add subtypes.
                IList <INode> subtypes = m_session.NodeCache.FindReferences(node.NodeId, ReferenceTypeIds.HasSubtype, false, true);

                foreach (INode subtype in subtypes)
                {
                    AddReferenceTypes(subtype.NodeId, choice);
                }
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Ignoring unknown reference type.");
                return;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Displays the target of a browse operation in the control.
        /// </summary>
        private void Browse(NodeId startId)
        {
            if (m_browser == null || NodeId.IsNull(startId))
            {
                Clear();
                return;
            }

            List <ItemData> variables = new List <ItemData>();

            // browse the references from the node and build list of variables.
            BeginUpdate();

            foreach (ReferenceDescription reference in m_browser.Browse(startId))
            {
                Node target = m_session.NodeCache.Find(reference.NodeId) as Node;

                if (target == null)
                {
                    continue;
                }

                ReferenceTypeNode referenceType = m_session.NodeCache.Find(reference.ReferenceTypeId) as ReferenceTypeNode;

                Node typeDefinition = null;

                if ((target.NodeClass & (NodeClass.Variable | NodeClass.Object)) != 0)
                {
                    typeDefinition = m_session.NodeCache.Find(reference.TypeDefinition) as Node;
                }
                else
                {
                    typeDefinition = m_session.NodeCache.Find(m_session.NodeCache.TypeTree.FindSuperType(target.NodeId)) as Node;
                }

                ItemData item = new ItemData(referenceType, !reference.IsForward, target, typeDefinition);
                AddItem(item, GuiUtils2.GetTargetIcon(m_browser.Session, reference), -1);

                if ((target.NodeClass & (NodeClass.Variable | NodeClass.VariableType)) != 0)
                {
                    variables.Add(item);
                }
            }

            EndUpdate();

            // read the current value for any variables.
            if (variables.Count > 0)
            {
                ReadValueIdCollection nodesToRead = new ReadValueIdCollection();

                foreach (ItemData item in variables)
                {
                    ReadValueId valueId = new ReadValueId();

                    valueId.NodeId       = item.Target.NodeId;
                    valueId.AttributeId  = Attributes.Value;
                    valueId.IndexRange   = null;
                    valueId.DataEncoding = null;

                    nodesToRead.Add(valueId);
                }

                DataValueCollection      values;
                DiagnosticInfoCollection diagnosticInfos;

                m_session.Read(
                    null,
                    0,
                    TimestampsToReturn.Neither,
                    nodesToRead,
                    out values,
                    out diagnosticInfos);

                ClientBase.ValidateResponse(values, nodesToRead);
                ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToRead);

                for (int ii = 0; ii < variables.Count; ii++)
                {
                    variables[ii].Value = values[ii];

                    foreach (ListViewItem item in ItemsLV.Items)
                    {
                        if (Object.ReferenceEquals(item.Tag, variables[ii]))
                        {
                            UpdateItem(item, variables[ii]);
                            break;
                        }
                    }
                }
            }

            AdjustColumns();
        }
Exemplo n.º 7
0
        public Node ReadNode(NodeId nodeId)
        {
            // build list of attributes.
            SortedDictionary<uint,DataValue> attributes = new SortedDictionary<uint,DataValue>();
            
            attributes.Add(Attributes.NodeId, null);
            attributes.Add(Attributes.NodeClass, null);
            attributes.Add(Attributes.BrowseName, null);
            attributes.Add(Attributes.DisplayName, null);
            attributes.Add(Attributes.Description, null);
            attributes.Add(Attributes.WriteMask, null);
            attributes.Add(Attributes.UserWriteMask, null);
            attributes.Add(Attributes.DataType, null);
            attributes.Add(Attributes.ValueRank, null);
            attributes.Add(Attributes.ArrayDimensions, null);
            attributes.Add(Attributes.AccessLevel, null);
            attributes.Add(Attributes.UserAccessLevel, null);
            attributes.Add(Attributes.Historizing, null);
            attributes.Add(Attributes.MinimumSamplingInterval, null);
            attributes.Add(Attributes.EventNotifier, null);
            attributes.Add(Attributes.Executable, null);
            attributes.Add(Attributes.UserExecutable, null);
            attributes.Add(Attributes.IsAbstract, null);
            attributes.Add(Attributes.InverseName, null);
            attributes.Add(Attributes.Symmetric, null);
            attributes.Add(Attributes.ContainsNoLoops, null);

            // build list of values to read.
            ReadValueIdCollection itemsToRead = new ReadValueIdCollection();

            foreach (uint attributeId in attributes.Keys)
            {
                ReadValueId itemToRead = new ReadValueId();

                itemToRead.NodeId      = nodeId;
                itemToRead.AttributeId = attributeId;
                
                itemsToRead.Add(itemToRead);
            }

            // read from server.
            DataValueCollection values = null;
            DiagnosticInfoCollection diagnosticInfos = null;

            ResponseHeader responseHeader = Read(
                null,
                0,
                TimestampsToReturn.Neither,
                itemsToRead,
                out values, 
                out diagnosticInfos);
            
            ClientBase.ValidateResponse(values, itemsToRead);
            ClientBase.ValidateDiagnosticInfos(diagnosticInfos, itemsToRead);

            // process results.
            int? nodeClass = null;

            for (int ii = 0; ii < itemsToRead.Count; ii++)
            {
                uint attributeId = itemsToRead[ii].AttributeId;
                
                // the node probably does not exist if the node class is not found.
                if (attributeId == Attributes.NodeClass)
                {
                    if (!DataValue.IsGood(values[ii]))
                    {
                        throw ServiceResultException.Create(values[ii].StatusCode, ii, diagnosticInfos, responseHeader.StringTable);
                    }       
     
                    // check for valid node class.
                    nodeClass  = values[ii].Value as int?;

                    if (nodeClass == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Node does not have a valid value for NodeClass: {0}.", values[ii].Value);
                    }
                }
                else
                {
                    if (!DataValue.IsGood(values[ii]))
                    {
                        // check for unsupported attributes.
                        if (values[ii].StatusCode == StatusCodes.BadAttributeIdInvalid)
                        {
                            continue;
                        }

                        // all supported attributes must be readable.
                        if (attributeId != Attributes.Value)
                        {
                            throw ServiceResultException.Create(values[ii].StatusCode, ii, diagnosticInfos, responseHeader.StringTable);
                        }
                    }      
                }

                attributes[attributeId] = values[ii];
            }

            Node node = null;
            DataValue value = null;

            switch ((NodeClass)nodeClass.Value)
            {
                default:
                {
                    throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Node does not have a valid value for NodeClass: {0}.", nodeClass.Value);
                }

                case NodeClass.Object:
                {
                    ObjectNode objectNode = new ObjectNode();

                    value = attributes[Attributes.EventNotifier];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Object does not support the EventNotifier attribute.");
                    }

                    objectNode.EventNotifier = (byte)attributes[Attributes.EventNotifier].GetValue(typeof(byte));
                    node = objectNode;
                    break;
                }

                case NodeClass.ObjectType:
                {
                    ObjectTypeNode objectTypeNode = new ObjectTypeNode();

                    value = attributes[Attributes.IsAbstract];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "ObjectType does not support the IsAbstract attribute.");
                    }

                    objectTypeNode.IsAbstract = (bool)attributes[Attributes.IsAbstract].GetValue(typeof(bool));
                    node = objectTypeNode;
                    break;
                }

                case NodeClass.Variable:
                {
                    VariableNode variableNode = new VariableNode();
                    
                    // DataType Attribute
                    value = attributes[Attributes.DataType];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Variable does not support the DataType attribute.");
                    }

                    variableNode.DataType = (NodeId)attributes[Attributes.DataType].GetValue(typeof(NodeId));     

                    // ValueRank Attribute
                    value = attributes[Attributes.ValueRank];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Variable does not support the ValueRank attribute.");
                    }

                    variableNode.ValueRank = (int)attributes[Attributes.ValueRank].GetValue(typeof(int));                                      
                    
                    // ArrayDimensions Attribute
                    value = attributes[Attributes.ArrayDimensions];

                    if (value != null)
                    {
                        if (value.Value == null)
                        {
                            variableNode.ArrayDimensions = new uint[0];
                        }
                        else
                        {
                            variableNode.ArrayDimensions = (uint[])value.GetValue(typeof(uint[]));
                        }
                    }
                    
                    // AccessLevel Attribute
                    value = attributes[Attributes.AccessLevel];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Variable does not support the AccessLevel attribute.");
                    }

                    variableNode.AccessLevel = (byte)attributes[Attributes.AccessLevel].GetValue(typeof(byte));     
                    
                    // UserAccessLevel Attribute
                    value = attributes[Attributes.UserAccessLevel];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Variable does not support the UserAccessLevel attribute.");
                    }

                    variableNode.UserAccessLevel = (byte)attributes[Attributes.UserAccessLevel].GetValue(typeof(byte));     
                    
                    // Historizing Attribute
                    value = attributes[Attributes.Historizing];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Variable does not support the Historizing attribute.");
                    }

                    variableNode.Historizing = (bool)attributes[Attributes.Historizing].GetValue(typeof(bool));    
                    
                    // MinimumSamplingInterval Attribute
                    value = attributes[Attributes.MinimumSamplingInterval];

                    if (value != null)
                    {
                        variableNode.MinimumSamplingInterval = Convert.ToDouble(attributes[Attributes.MinimumSamplingInterval].Value);
                    }

                    node = variableNode;
                    break;
                }
                    
                case NodeClass.VariableType:
                {
                    VariableTypeNode variableTypeNode = new VariableTypeNode();

                    // IsAbstract Attribute
                    value = attributes[Attributes.IsAbstract];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "VariableType does not support the IsAbstract attribute.");
                    }

                    variableTypeNode.IsAbstract = (bool)attributes[Attributes.IsAbstract].GetValue(typeof(bool));
                    
                    // DataType Attribute
                    value = attributes[Attributes.DataType];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "VariableType does not support the DataType attribute.");
                    }

                    variableTypeNode.DataType = (NodeId)attributes[Attributes.DataType].GetValue(typeof(NodeId));     

                    // ValueRank Attribute
                    value = attributes[Attributes.ValueRank];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "VariableType does not support the ValueRank attribute.");
                    }

                    variableTypeNode.ValueRank = (int)attributes[Attributes.ValueRank].GetValue(typeof(int));                                      
                    
                    // ArrayDimensions Attribute
                    value = attributes[Attributes.ArrayDimensions];

                    if (value != null && value.Value != null)
                    {
                        variableTypeNode.ArrayDimensions = (uint[])attributes[Attributes.ArrayDimensions].GetValue(typeof(uint[]));
                    }
                    
                    node = variableTypeNode;
                    break;
                }
                    
                case NodeClass.Method:
                {
                    MethodNode methodNode = new MethodNode();

                    // Executable Attribute
                    value = attributes[Attributes.Executable];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Method does not support the Executable attribute.");
                    }

                    methodNode.Executable = (bool)attributes[Attributes.Executable].GetValue(typeof(bool));
                    
                    // UserExecutable Attribute
                    value = attributes[Attributes.UserExecutable];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Method does not support the UserExecutable attribute.");
                    }

                    methodNode.UserExecutable = (bool)attributes[Attributes.UserExecutable].GetValue(typeof(bool));

                    node = methodNode;
                    break;
                }
                    
                case NodeClass.DataType:
                {
                    DataTypeNode dataTypeNode = new DataTypeNode();

                    // IsAbstract Attribute
                    value = attributes[Attributes.IsAbstract];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "DataType does not support the IsAbstract attribute.");
                    }

                    dataTypeNode.IsAbstract = (bool)attributes[Attributes.IsAbstract].GetValue(typeof(bool));

                    node = dataTypeNode;
                    break;
                }
                    
                case NodeClass.ReferenceType:
                {
                    ReferenceTypeNode referenceTypeNode = new ReferenceTypeNode();

                    // IsAbstract Attribute
                    value = attributes[Attributes.IsAbstract];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "ReferenceType does not support the IsAbstract attribute.");
                    }

                    referenceTypeNode.IsAbstract = (bool)attributes[Attributes.IsAbstract].GetValue(typeof(bool));

                    // Symmetric Attribute
                    value = attributes[Attributes.Symmetric];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "ReferenceType does not support the Symmetric attribute.");
                    }

                    referenceTypeNode.Symmetric = (bool)attributes[Attributes.IsAbstract].GetValue(typeof(bool));

                    // InverseName Attribute
                    value = attributes[Attributes.InverseName];

                    if (value != null && value.Value != null)
                    {
                        referenceTypeNode.InverseName = (LocalizedText)attributes[Attributes.InverseName].GetValue(typeof(LocalizedText));
                    }
                    
                    node = referenceTypeNode;
                    break;
                }
                    
                case NodeClass.View:
                {
                    ViewNode viewNode = new ViewNode();

                    // EventNotifier Attribute
                    value = attributes[Attributes.EventNotifier];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "View does not support the EventNotifier attribute.");
                    }

                    viewNode.EventNotifier = (byte)attributes[Attributes.EventNotifier].GetValue(typeof(byte));
                    
                    // ContainsNoLoops Attribute
                    value = attributes[Attributes.ContainsNoLoops];

                    if (value == null)
                    {
                        throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "View does not support the ContainsNoLoops attribute.");
                    }

                    viewNode.ContainsNoLoops = (bool)attributes[Attributes.ContainsNoLoops].GetValue(typeof(bool));

                    node = viewNode;
                    break;
                }                    
            }
                
            // NodeId Attribute
            value = attributes[Attributes.NodeId];

            if (value == null)
            {
                throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Node does not support the NodeId attribute.");
            }

            node.NodeId = (NodeId)attributes[Attributes.NodeId].GetValue(typeof(NodeId));
            node.NodeClass = (NodeClass)nodeClass.Value;

            // BrowseName Attribute
            value = attributes[Attributes.BrowseName];

            if (value == null)
            {
                throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Node does not support the BrowseName attribute.");
            }

            node.BrowseName = (QualifiedName)attributes[Attributes.BrowseName].GetValue(typeof(QualifiedName));

            // DisplayName Attribute
            value = attributes[Attributes.DisplayName];

            if (value == null)
            {
                throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Node does not support the DisplayName attribute.");
            }

            node.DisplayName = (LocalizedText)attributes[Attributes.DisplayName].GetValue(typeof(LocalizedText));
    
            // Description Attribute
            value = attributes[Attributes.Description];

            if (value != null && value.Value != null)
            {
                node.Description = (LocalizedText)attributes[Attributes.Description].GetValue(typeof(LocalizedText));
            }

            // WriteMask Attribute
            value = attributes[Attributes.WriteMask];

            if (value != null)
            {
                node.WriteMask = (uint)attributes[Attributes.WriteMask].GetValue(typeof(uint));
            }

            // UserWriteMask Attribute
            value = attributes[Attributes.UserWriteMask];

            if (value != null)
            {
                node.WriteMask = (uint)attributes[Attributes.UserWriteMask].GetValue(typeof(uint));
            }
                
            return node;
        }
        /// <summary>
        /// Creates an ReferenceType node with the specified node id.
        /// </summary>
        public NodeId CreateReferenceType(
            NodeId         parentId,
            NodeId         nodeId,
            QualifiedName  browseName,
            LocalizedText  displayName,
            LocalizedText  description,
            uint           writeMask,
            uint           userWriteMask,
            LocalizedText  inverseName,
            bool           isAbstract,
            bool           symmetric)
        {
            try
            {
                m_lock.Enter();
    
                // check for null node id.
                if (NodeId.IsNull(nodeId))
                {
                    nodeId = CreateUniqueNodeId();
                }

                // check if node id exists.
                if (m_nodes.Exists(nodeId))
                {
                    throw ServiceResultException.Create(StatusCodes.BadNodeIdExists, "NodeId '{0}' already exists.", nodeId);
                }

                // find parent.
                IReferenceType parent = GetManagerHandle(parentId) as IReferenceType;

                if (parent == null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadParentNodeIdInvalid, "Parent node '{0}' does not exist or is not an ReferenceType.", parentId);
                }
                
                // validate reference.
                ValidateReference(parent, ReferenceTypeIds.HasSubtype, false, NodeClass.ReferenceType);

                // validate browse name.
                if (QualifiedName.IsNull(browseName))
                {
                    throw ServiceResultException.Create(StatusCodes.BadBrowseNameInvalid, "BrowseName must not be empty.");
                }

                // check that the browse name is unique.
                if (m_server.TypeTree.FindReferenceType(browseName) != null)
                {
                    throw ServiceResultException.Create(StatusCodes.BadBrowseNameInvalid, "A ReferenceType with the same BrowseName ({0}) already exists.", browseName);
                }

                // create node.
                ReferenceTypeNode node = new ReferenceTypeNode();

                node.NodeId          = nodeId;
                node.NodeClass       = NodeClass.ReferenceType;
                node.BrowseName      = browseName;
                node.DisplayName     = displayName;
                node.Description     = description;
                node.WriteMask       = writeMask;
                node.UserWriteMask   = userWriteMask;
                node.InverseName     = inverseName;
                node.IsAbstract      = isAbstract;
                node.Symmetric       = symmetric;

                if (node.DisplayName == null)
                {
                    node.DisplayName = new LocalizedText(browseName.Name);
                }

                // add reference from parent.
                AddReference(parent, ReferenceTypeIds.HasSubtype, false, node, true);
                
                // add node.
                AddNode(node);
                                
                // return the new node id.
                return node.NodeId;
            }
            finally
            {
                m_lock.Exit();
            } 
        }
Exemplo n.º 9
0
        /// <summary>
        /// Adds a target to the tree control.
        /// </summary>
        private void AddReferences(TreeNode parent, ReferenceDescriptionCollection references)
        {
            foreach (ReferenceDescription reference in references)
            {
                if (reference.ReferenceTypeId.IsNullNodeId)
                {
                    Utils.Trace("Reference {0} has null reference type id", reference.DisplayName);
                    continue;
                }

                ReferenceTypeNode typeNode = m_browser.Session.NodeCache.Find(reference.ReferenceTypeId) as ReferenceTypeNode;
                if (typeNode == null)
                {
                    Utils.Trace("Reference {0} has invalid reference type id.", reference.DisplayName);
                    continue;
                }

                if (m_browser.BrowseDirection == BrowseDirection.Forward && !reference.IsForward ||
                    m_browser.BrowseDirection == BrowseDirection.Inverse && reference.IsForward)
                {
                    Utils.Trace("Reference's IsForward value is: {0}, but the browse direction is: {1}; for reference {2}", reference.IsForward, m_browser.BrowseDirection, reference.DisplayName);
                    continue;
                }

                if (reference.NodeId == null || reference.NodeId.IsNull)
                {
                    Utils.Trace("The node id of the reference {0} is NULL.", reference.DisplayName);
                    continue;
                }

                if (reference.BrowseName == null || reference.BrowseName.Name == null)
                {
                    Utils.Trace("Browse name is empty for reference {0}", reference.DisplayName);
                    continue;
                }

                if (!Enum.IsDefined(typeof(Opc.Ua.NodeClass), reference.NodeClass) || reference.NodeClass == NodeClass.Unspecified)
                {
                    Utils.Trace("Node class is an unknown or unspecified value, for reference {0}", reference.DisplayName);
                    continue;
                }

                if (m_browser.NodeClassMask != 0 && m_browser.NodeClassMask != 255)
                {
                    if (reference.TypeDefinition == null || reference.TypeDefinition.IsNull)
                    {
                        Utils.Trace("Type definition is null for reference {0}", reference.DisplayName);
                        continue;
                    }
                }

                // suppress duplicate references.
                if (!m_showReferences)
                {
                    bool exists = false;

                    foreach (TreeNode existingChild in parent.Nodes)
                    {
                        ReferenceDescription existingReference = existingChild.Tag as ReferenceDescription;

                        if (existingReference != null)
                        {
                            if (existingReference.NodeId == reference.NodeId)
                            {
                                exists = true;
                                break;
                            }
                        }
                    }

                    if (exists)
                    {
                        continue;
                    }
                }

                string text = GetTargetText(reference);
                string icon = GuiUtils2.GetTargetIcon(m_browser.Session, reference);

                TreeNode container = parent;

                if (m_showReferences)
                {
                    container = FindReferenceTypeContainer(parent, reference);
                }

                if (container != null)
                {
                    TreeNode child = AddNode(container, reference, text, icon);
                    child.Nodes.Add(new TreeNode());
                }
            }
        }
Exemplo n.º 10
0
 public ItemData(ReferenceTypeNode referenceType, bool isInverse, Node target, Node typeDefinition)
 {
     ReferenceType  = referenceType;
     IsInverse      = isInverse;
     Target         = target;
     TypeDefinition = typeDefinition;
 }
Exemplo n.º 11
0
        /// <summary>
        /// Returns the value of an attribute.
        /// </summary>
        public void Read(
            ReadValueId request,
            DataValue result,
            DiagnosticInfo diagnosticInfo)
        {
            lock (m_lock)
            {
                // find the node to read.
                Node source = m_nodes.Find(request.NodeId);

                result.ServerTimestamp = DateTime.UtcNow;

                if (source == null)
                {
                    result.StatusCode = new StatusCode(StatusCodes.BadNodeIdUnknown);
                    return;
                }

                result.Value = Variant.Null;

                // switch on the attribute value.
                switch (request.AttributeId)
                {
                case Attributes.NodeId:
                {
                    result.Value = new Variant(source.NodeId);
                    break;
                }

                case Attributes.NodeClass:
                {
                    result.Value = new Variant(DataTypes.EnumToMask(source.NodeClass));
                    break;
                }

                case Attributes.BrowseName:
                {
                    result.Value = new Variant(source.BrowseName);
                    break;
                }

                case Attributes.DisplayName:
                {
                    result.Value = new Variant(source.DisplayName);
                    break;
                }

                case Attributes.Description:
                {
                    result.Value = new Variant(source.Description);
                    break;
                }

                case Attributes.WriteMask:
                {
                    result.Value = new Variant(source.WriteMask);
                    break;
                }

                case Attributes.UserWriteMask:
                {
                    result.Value = new Variant(source.UserWriteMask);
                    break;
                }

                case Attributes.Value:
                {
                    // check if another component has installed a read callback.
                    ReadValueEventHandler callback = null;

                    if (m_callbacks.TryGetValue(source.NodeId.Identifier, out callback))
                    {
                        result.Value = new Variant(callback());
                        break;
                    }

                    // use the value cached in the node otherwise.
                    VariableNode variable = source as VariableNode;

                    if (variable != null)
                    {
                        result.Value           = variable.Value;
                        result.SourceTimestamp = DateTime.UtcNow;     // The Value attribute requires a SourceTimestamp.
                        break;
                    }

                    VariableTypeNode variableType = source as VariableTypeNode;

                    if (variableType != null)
                    {
                        result.Value           = variableType.Value;
                        result.SourceTimestamp = DateTime.UtcNow;     // The Value attribute requires a SourceTimestamp.
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.DataType:
                {
                    VariableNode variable = source as VariableNode;

                    if (variable != null)
                    {
                        result.Value = new Variant(variable.DataType);
                        break;
                    }

                    VariableTypeNode variableType = source as VariableTypeNode;

                    if (variableType != null)
                    {
                        result.Value = new Variant(variableType.DataType);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.ValueRank:
                {
                    VariableNode variable = source as VariableNode;

                    if (variable != null)
                    {
                        result.Value = new Variant(variable.ValueRank);
                        break;
                    }

                    VariableTypeNode variableType = source as VariableTypeNode;

                    if (variableType != null)
                    {
                        result.Value = new Variant(variableType.ValueRank);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.MinimumSamplingInterval:
                {
                    VariableNode variable = source as VariableNode;

                    if (variable != null)
                    {
                        result.Value = new Variant(variable.MinimumSamplingInterval);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.Historizing:
                {
                    VariableNode variable = source as VariableNode;

                    if (variable != null)
                    {
                        result.Value = new Variant(variable.Historizing);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.AccessLevel:
                {
                    VariableNode variable = source as VariableNode;

                    if (variable != null)
                    {
                        result.Value = new Variant(variable.AccessLevel);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.UserAccessLevel:
                {
                    VariableNode variable = source as VariableNode;

                    if (variable != null)
                    {
                        result.Value = new Variant(variable.UserAccessLevel);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.EventNotifier:
                {
                    ObjectNode objectn = source as ObjectNode;

                    if (objectn != null)
                    {
                        result.Value = new Variant(objectn.EventNotifier);
                        break;
                    }

                    ViewNode view = source as ViewNode;

                    if (view != null)
                    {
                        result.Value = new Variant(view.EventNotifier);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.Executable:
                {
                    MethodNode method = source as MethodNode;

                    if (method != null)
                    {
                        result.Value = new Variant(method.Executable);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.UserExecutable:
                {
                    MethodNode method = source as MethodNode;

                    if (method != null)
                    {
                        result.Value = new Variant(method.UserExecutable);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.ContainsNoLoops:
                {
                    ViewNode view = source as ViewNode;

                    if (view != null)
                    {
                        result.Value = new Variant(view.ContainsNoLoops);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.InverseName:
                {
                    ReferenceTypeNode referenceType = source as ReferenceTypeNode;

                    if (referenceType != null)
                    {
                        result.Value = new Variant(referenceType.InverseName);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.IsAbstract:
                {
                    DataTypeNode dataType = source as DataTypeNode;

                    if (dataType != null)
                    {
                        result.Value = new Variant(dataType.IsAbstract);
                        break;
                    }

                    ReferenceTypeNode referenceType = source as ReferenceTypeNode;

                    if (referenceType != null)
                    {
                        result.Value = new Variant(referenceType.IsAbstract);
                        break;
                    }

                    ObjectTypeNode objectType = source as ObjectTypeNode;

                    if (objectType != null)
                    {
                        result.Value = new Variant(objectType.IsAbstract);
                        break;
                    }

                    VariableTypeNode variableType = source as VariableTypeNode;

                    if (variableType != null)
                    {
                        result.Value = new Variant(variableType.IsAbstract);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                case Attributes.Symmetric:
                {
                    ReferenceTypeNode referenceType = source as ReferenceTypeNode;

                    if (referenceType != null)
                    {
                        result.Value = new Variant(referenceType.Symmetric);
                        break;
                    }

                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }

                default:
                {
                    result.StatusCode = new StatusCode(StatusCodes.BadAttributeIdInvalid);
                    break;
                }
                }
            }
        }