A reference returned in browse operation.
상속: IFormattable
예제 #1
0
        /// <summary>
        /// Converts an OPC Foundation node to an Hylasoft OPC UA Node
        /// </summary>
        /// <param name="node">The node to convert</param>
        /// <param name="parent">the parent node (optional)</param>
        /// <returns></returns>
        internal static UaNode ToHylaNode(this OpcF.ReferenceDescription node, Node parent = null)
        {
            var name   = node.DisplayName.ToString();
            var nodeId = node.NodeId.ToString();

            return(new UaNode(name, nodeId, parent));
        }
예제 #2
0
파일: Node.cs 프로젝트: yuriik83/UA-.NET
        /// <summary>
        /// Creates a node from a reference desciption.
        /// </summary>
        /// <param name="reference">The reference.</param>
        public Node(ReferenceDescription reference)
        {
            Initialize();

            m_nodeId      = (NodeId)reference.NodeId;
            m_nodeClass   = reference.NodeClass;
            m_browseName  = reference.BrowseName;
            m_displayName = reference.DisplayName;
        }
예제 #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="mode"></param>
 public NodeItem(Opc.Ua.ReferenceDescription mode)
 {
     if (mode != null)
     {
         this.mMode = mode;
         if (this.mMode.NodeClass == NodeClass.Object)
         {
             mChildren.Add(new NodeItem(null));
         }
     }
 }
예제 #4
0
        /// <summary>
        /// Determines whether a reference is in a view.
        /// </summary>
        /// <param name="description">The description.</param>
        /// <param name="reference">The reference.</param>
        /// <returns>
        ///     <c>true</c> whether a reference is in a view; otherwise, <c>false</c>.
        /// </returns>
        public bool IsReferenceInView(ViewDescription description, ReferenceDescription reference)
        {
            // everything is in the default view.
            if (ViewDescription.IsDefault(description))
            {
                return(true);
            }

            lock (m_lock)
            {
                ViewNode view = null;

                if (m_views.TryGetValue(description.ViewId, out view))
                {
                    throw new ServiceResultException(StatusCodes.BadViewIdUnknown);
                }

                return(false);
            }
        }
예제 #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventFieldDefinition"/> class.
        /// </summary>
        /// <param name="parentField">The parent field.</param>
        /// <param name="reference">The reference to the instance declaration node.</param>
        public EventFieldDefinition(EventFieldDefinition parentField, ReferenceDescription reference)
        {
            DeclarationNode = reference;

            Operand = new SimpleAttributeOperand();

            // setting the typedefinition id to null ignores the event type when evaluating the operand.
            Operand.TypeDefinitionId = null;

            // event filters only support the NodeId attribute for objects and the Value attribute for Variables.
            Operand.AttributeId = (reference.NodeClass == NodeClass.Variable) ? Attributes.Value : Attributes.NodeId;

            // prefix the browse path with the parent browse path.
            if (parentField != null)
            {
                Operand.BrowsePath = new QualifiedNameCollection(parentField.Operand.BrowsePath);
            }

            // add the child browse name.
            Operand.BrowsePath.Add(reference.BrowseName);

            // may select sub-sets of array values. Not used in this sample.
            Operand.IndexRange = null;

            // construct the display name.
            StringBuilder buffer = new StringBuilder();

            for (int ii = 0; ii < Operand.BrowsePath.Count; ii++)
            {
                if (buffer.Length > 0)
                {
                    buffer.Append('/');
                }

                buffer.Append(Operand.BrowsePath[ii].Name);
            }

            DisplayName = buffer.ToString();
        }
        /// <summary>
        /// Returns the references for the node that meets the criteria specified.
        /// </summary>
        protected virtual ReferenceDescription GetReferenceDescription(
            ServerSystemContext context,
            Dictionary<NodeId,NodeState> cache,
            IReference reference,
            ContinuationPoint continuationPoint)
        {
            ServerSystemContext systemContext = m_systemContext.Copy(context);

            // create the type definition reference.        
            ReferenceDescription description = new ReferenceDescription();

            description.NodeId = reference.TargetId;
            description.SetReferenceType(continuationPoint.ResultMask, reference.ReferenceTypeId, !reference.IsInverse);
            
            // check if reference is in the view.
            if (!IsReferenceInView(context, continuationPoint, reference))
            {
                return null;
            }

            // do not cache target parameters for remote nodes.
            if (reference.TargetId.IsAbsolute)
            {
                // only return remote references if no node class filter is specified.
                if (continuationPoint.NodeClassMask != 0)
                {
                    return null;
                }

                return description;
            }

            NodeState target = null;

            // check for local reference.
            NodeStateReference referenceInfo = reference as NodeStateReference;

            if (referenceInfo != null)
            {
                target = referenceInfo.Target;
            }

            // check for internal reference.
            if (target == null)
            {
                NodeHandle handle = GetManagerHandle(context, (NodeId)reference.TargetId, null) as NodeHandle;
                
                if (handle != null)
                {
                    target = ValidateNode(context, handle, null);
                }
            }

            // the target may be a reference to a node in another node manager. In these cases
            // the target attributes must be fetched by the caller. The Unfiltered flag tells the
            // caller to do that.
            if (target == null)
            {
                description.Unfiltered = true;
                return description;
            }

            // apply node class filter.
            if (continuationPoint.NodeClassMask != 0 && ((continuationPoint.NodeClassMask & (uint)target.NodeClass) == 0))
            {
                return null;
            }

            // check if target is in the view.
            if (!IsNodeInView(context, continuationPoint, target))
            {
                return null;
            }

            // look up the type definition.
            NodeId typeDefinition = null;

            BaseInstanceState instance = target as BaseInstanceState;

            if (instance != null)
            {
                typeDefinition = instance.TypeDefinitionId;
            }

            // set target attributes.
            description.SetTargetAttributes(
                continuationPoint.ResultMask,
                target.NodeClass,
                target.BrowseName,
                target.DisplayName,
                typeDefinition);

            return description;
        }
예제 #7
0
        /// <summary>
        /// Determines whether a reference is in a view.
        /// </summary>
        /// <param name="description">The description.</param>
        /// <param name="reference">The reference.</param>
        /// <returns>
        /// 	<c>true</c> whether a reference is in a view; otherwise, <c>false</c>.
        /// </returns>
        public bool IsReferenceInView(ViewDescription description, ReferenceDescription reference)
        {
            // everything is in the default view.
            if (ViewDescription.IsDefault(description))
            {
                return true;
            }

            lock (m_lock)
            {
                ViewNode view = null;

                if (m_views.TryGetValue(description.ViewId, out view))
                {
                    throw new ServiceResultException(StatusCodes.BadViewIdUnknown);
                }

                return false;
            }
        }
예제 #8
0
        /// <summary>
        /// Handles the click event for the OK button.
        /// </summary>
        private void OkBTN_Click(object sender, EventArgs e)
        {
            try
            {
                #region Task #B1 - Browse References
                if (ReferencesLV.SelectedItems.Count == 0)
                {
                    return;
                }

                m_reference = ReferencesLV.SelectedItems[0].Tag as ReferenceDescription;
                #endregion

                DialogResult = DialogResult.OK;
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
예제 #9
0
        /// <summary>
        /// Changes the session used by the control.
        /// </summary>
        private void ChangeSession(Session session, bool refresh)
        {
            m_session = session;

            if (AttributesControl != null)
            {
                AttributesControl.ChangeSession(session);
            }

            BrowseTV.Nodes.Clear();

            if (m_session != null)
            {
                INode node = m_session.NodeCache.Find(m_rootId);

                if (node != null)
                {
                    TreeNode root = new TreeNode(node.ToString());
                    root.ImageIndex = ClientUtils.GetImageIndex(m_session, node.NodeClass, node.TypeDefinitionId, false);
                    root.SelectedImageIndex = ClientUtils.GetImageIndex(m_session, node.NodeClass, node.TypeDefinitionId, true);

                    ReferenceDescription reference = new ReferenceDescription();
                    reference.NodeId = node.NodeId;
                    reference.NodeClass = node.NodeClass;
                    reference.BrowseName = node.BrowseName;
                    reference.DisplayName = node.DisplayName;
                    reference.TypeDefinition = node.TypeDefinitionId;
                    root.Tag = reference;

                    root.Nodes.Add(new TreeNode());
                    BrowseTV.Nodes.Add(root);
                    root.Expand();
                    BrowseTV.SelectedNode = root;
                }
            }
        }
예제 #10
0
        private void ReadNode(NodeId nodeid, bool ignoreroot, bool ignorechildren, String DriverName)
        {
            INode node = m_session.NodeCache.Find(nodeid);
            if (node != null)
            {
                //TreeNode root = new TreeNode(node.ToString());
                //root.ImageIndex = ClientUtils.GetImageIndex(m_session, node.NodeClass, node.TypeDefinitionId, false);
                //root.SelectedImageIndex = ClientUtils.GetImageIndex(m_session, node.NodeClass, node.TypeDefinitionId, true);

                ReferenceDescription reference = new ReferenceDescription();

                reference.NodeId = node.NodeId;
                reference.NodeClass = node.NodeClass;
                reference.BrowseName = node.BrowseName;
                reference.DisplayName = node.DisplayName;
                reference.TypeDefinition = node.TypeDefinitionId;


                // build list of attributes to read.
                ReadValueIdCollection nodesToRead = new ReadValueIdCollection();

                foreach (uint attributeId in Attributes.GetIdentifiers())
                {
                    ReadValueId nodeToRead = new ReadValueId();
                    nodeToRead.NodeId = (NodeId)reference.NodeId;
                    nodeToRead.AttributeId = attributeId;
                    nodesToRead.Add(nodeToRead);
                }

                // read the attributes.
                DataValueCollection results = null;
                DiagnosticInfoCollection diagnosticInfos = null;

                m_session.Read(
                 null,
                 0,
                 TimestampsToReturn.Neither,
                 nodesToRead,
                 out results,
                 out diagnosticInfos);
                if (ignoreroot == false)
                {
                    //Log(results[0].ToString() + " \t| " + results[3].ToString() + " \t| "+ results[4].ToString() + " \t| " + results[12].ToString());
                    Log("UID:" + S80(results[(int)Attributes.NodeId - 1].ToString()) + " \tBrowseName: " + s40(results[(int)Attributes.BrowseName - 1].ToString()) + " \tDisplayName:  " + s40(results[(int)Attributes.DisplayName - 1].ToString()) + " \tDescription:  " + S80(results[(int)Attributes.Description - 1].ToString()) + " \tValue:  " + results[(int)Attributes.Value - 1].ToString());

                    dr = dt.NewRow();
                    dr["UID"] = results[(int)Attributes.NodeId - 1].ToString();
                    dr["BrowseName"] = results[(int)Attributes.BrowseName - 1].ToString();
                    dr["DisplayName"] = results[(int)Attributes.DisplayName - 1].ToString();
                    dr["Description"] = results[(int)Attributes.Description - 1].ToString();
                    dr["Value"] = results[(int)Attributes.Value - 1].ToString();
                    dr["Name"] = DriverName;
                    dt.Rows.Add(dr);
                    if (results[(int)Attributes.AccessLevel - 1].Value != null)
                    {
                        if (((byte)(results[(int)Attributes.AccessLevel - 1].GetValue(typeof(byte))) & AccessLevels.HistoryRead) == AccessLevels.HistoryRead)
                        {
                            //gv.DataSource = dt;
                            ReadHistory(DateTime.Now.AddDays(-1), DateTime.Now, new NodeId(results[0].ToString()), 25, "");
                        }
                    }
                }

                if (ignorechildren == false)
                {
                    BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection();


                    BrowseDescription nodeToBrowse = new BrowseDescription();

                    nodeToBrowse.NodeId = nodeid;
                    nodeToBrowse.BrowseDirection = BrowseDirection.Forward;
                    nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HierarchicalReferences;
                    nodeToBrowse.IncludeSubtypes = true;
                    nodeToBrowse.NodeClassMask = 0;
                    nodeToBrowse.ResultMask = (uint)BrowseResultMask.All;

                    if (reference != null)
                    {
                        nodeToBrowse.NodeId = (NodeId)reference.NodeId;
                    }

                    nodesToBrowse.Add(nodeToBrowse);

                    ReferenceDescriptionCollection references = ClientUtils.Browse(m_session, null, nodesToBrowse, false);

                    for (int ii = 0; references != null && ii < references.Count; ii++)
                    {
                        reference = references[ii];


                        // build list of attributes to read.
                        nodesToRead = new ReadValueIdCollection();

                        foreach (uint attributeId in Attributes.GetIdentifiers())
                        {
                            ReadValueId nodeToRead = new ReadValueId();
                            nodeToRead.NodeId = (NodeId)reference.NodeId;
                            nodeToRead.AttributeId = attributeId;
                            nodesToRead.Add(nodeToRead);
                        }

                        // read the attributes.
                        results = null;
                        diagnosticInfos = null;

                        m_session.Read(
                         null,
                         0,
                         TimestampsToReturn.Neither,
                         nodesToRead,
                         out results,
                         out diagnosticInfos);
                        //    Log("UID:"+results[0].ToString() + " \tBrowseName: " + results[(int)Attributes.BrowseName].ToString() + " \tDisplayName:  " + results[(int)Attributes.DisplayName].ToString() + " \tDescription:  " + results[(int)Attributes.Description].ToString() + " \t|  " + results[(int)Attributes.Value].ToString());
                        //Log("UID:" + S80(results[(int)Attributes.NodeId - 1].ToString()) + " \tBrowseName: " + results[(int)Attributes.BrowseName - 1].ToString() + " \tDisplayName:  " + results[(int)Attributes.DisplayName - 1].ToString() + " \tDescription:  " + results[(int)Attributes.Description - 1].ToString() + " \tValue:  " + results[(int)Attributes.Value - 1].ToString());
                        Log("UID:" + S80(results[(int)Attributes.NodeId - 1].ToString()) + " \tBrowseName: " + s40(results[(int)Attributes.BrowseName - 1].ToString()) + " \tDisplayName:  " + s40(results[(int)Attributes.DisplayName - 1].ToString()) + " \tDescription:  " + S80(results[(int)Attributes.Description - 1].ToString()) + " \tValue:  " + results[(int)Attributes.Value - 1].ToString());
                        dr = dt.NewRow();
                        dr["UID"] = results[(int)Attributes.NodeId - 1].ToString();
                        dr["BrowseName"] = results[(int)Attributes.BrowseName - 1].ToString();
                        dr["DisplayName"] = results[(int)Attributes.DisplayName - 1].ToString();
                        dr["Description"] = results[(int)Attributes.Description - 1].ToString();
                        dr["Value"] = results[(int)Attributes.Value - 1].ToString();
                        dt.Rows.Add(dr);
                        try
                        {
                            if (results[(int)Attributes.AccessLevel - 1].Value != null)
                            {
                                if (((byte)(results[(int)Attributes.AccessLevel - 1].GetValue(typeof(byte))) & AccessLevels.HistoryRead) == AccessLevels.HistoryRead)
                                {
                                    //gv.DataSource = dt;
                                    ReadHistory(DateTime.Today, DateTime.Now, new NodeId(results[0].ToString()), 25, "");
                                }
                            }
                            else
                            {
                                if (results[(int)Attributes.Value - 1].Value == null)
                                {
                                   // gv.DataSource = dt;
                                    ReadNode(new NodeId(results[(int)Attributes.NodeId - 1].ToString()), true, false, "");
                                }

                            }
                        }
                        catch
                        {
                            Log("V=" + results[17].ToString());
                        }

                    }
                }

            }

        }
예제 #11
0
 public PropertyWithHistory(ReferenceDescription reference, byte accessLevel)
 {
     DisplayText = reference.ToString();
     NodeId = (NodeId)reference.NodeId;
     BrowseName = reference.BrowseName;
     AccessLevel = accessLevel;
 }
예제 #12
0
 /// <summary>
 ///
 /// </summary>
 public override void Dispose()
 {
     Parent = null;
     mMode  = null;
     base.Dispose();
 }
예제 #13
0
파일: Browser.cs 프로젝트: yuriik83/UA-.NET
        /// <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);
        }