GetImageIndex() public static méthode

Returns an image index for the specified attribute.
public static GetImageIndex ( Session session, NodeClass nodeClass, ExpandedNodeId typeDefinitionId, bool selected ) : int
session Session
nodeClass NodeClass
typeDefinitionId ExpandedNodeId
selected bool
Résultat int
Exemple #1
0
        /// <summary>
        /// Browses for the requested references.
        /// </summary>
        private void Browse()
        {
            m_dataset.Tables[0].Rows.Clear();

            if (m_session == null)
            {
                return;
            }

            ReferenceDescriptionCollection references = ClientUtils.Browse(m_session, View, CreateNodesToBrowse(), false);

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

                DataRow row = m_dataset.Tables[0].NewRow();

                row[0] = reference;
                row[1] = m_session.NodeCache.GetDisplayText(reference.NodeId);
                row[2] = m_session.NodeCache.GetDisplayText(reference.ReferenceTypeId);
                row[3] = reference.IsForward.ToString();
                row[4] = reference.NodeClass.ToString();
                row[5] = m_session.NodeCache.GetDisplayText(reference.TypeDefinition);
                row[6] = ImageList.Images[ClientUtils.GetImageIndex(m_session, reference.NodeClass, reference.TypeDefinition, false)];

                m_dataset.Tables[0].Rows.Add(row);
            }

            for (int ii = 0; ii < ReferencesDV.SelectedRows.Count; ii++)
            {
                ReferencesDV.SelectedRows[ii].Selected = false;
            }
        }
 /// <summary>
 /// Updates the row with the node to read.
 /// </summary>
 public void UpdateRow(DataRow row, InstanceDeclaration declaration)
 {
     row[0] = declaration;
     row[1] = ImageList.Images[ClientUtils.GetImageIndex((declaration.NodeClass == NodeClass.Variable) ? Attributes.Value : Attributes.NodeId, null)];
     row[2] = declaration.DisplayPath;
     row[3] = declaration.DataTypeDisplayText;
     row[4] = declaration.Description;
 }
Exemple #3
0
 /// <summary>
 /// Updates the row with the node to read.
 /// </summary>
 public void UpdateRow(DataRow row, ReadValueId nodeToRead)
 {
     row[0] = nodeToRead;
     row[1] = ImageList.Images[ClientUtils.GetImageIndex(nodeToRead.AttributeId, null)];
     row[2] = (m_session != null) ? m_session.NodeCache.GetDisplayText(nodeToRead.NodeId) : Utils.ToString(nodeToRead.NodeId);
     row[3] = Attributes.GetBrowseName(nodeToRead.AttributeId);
     row[4] = nodeToRead.IndexRange;
     row[5] = (nodeToRead.DataEncoding != null) ? nodeToRead.DataEncoding : QualifiedName.Null;
 }
 /// <summary>
 /// Updates the row with the monitored item.
 /// </summary>
 private void UpdateRow(DataRow row, MonitoredItem monitoredItem)
 {
     row[0] = monitoredItem;
     row[1] = ImageList.Images[ClientUtils.GetImageIndex(monitoredItem.AttributeId, null)];
     row[2] = m_session.NodeCache.GetDisplayText(monitoredItem.StartNodeId) + "/" + Attributes.GetBrowseName(monitoredItem.AttributeId);
     row[3] = monitoredItem.MonitoringMode;
     row[4] = monitoredItem.SamplingInterval;
     row[5] = monitoredItem.DiscardOldest;
 }
        /// <summary>
        /// Updates the row with the node to write.
        /// </summary>
        public void UpdateRow(DataRow row, WriteValue nodeToWrite)
        {
            row[0] = nodeToWrite;
            row[1] = ImageList.Images[ClientUtils.GetImageIndex(nodeToWrite.AttributeId, null)];
            row[2] = (m_session != null) ? m_session.NodeCache.GetDisplayText(nodeToWrite.NodeId) : Utils.ToString(nodeToWrite.NodeId);
            row[3] = Attributes.GetBrowseName(nodeToWrite.AttributeId);
            row[4] = nodeToWrite.IndexRange;

            UpdateRow(row, nodeToWrite.Value);
        }
        /// <summary>
        /// Updates the row with an argument and its value.
        /// </summary>
        private void UpdateRow(DataRow row, Argument argument, Variant value, bool isOutputArgument)
        {
            string dataType = m_session.NodeCache.GetDisplayText(argument.DataType);

            if (argument.ValueRank >= 0)
            {
                dataType += "[]";
            }

            row[0] = argument;
            row[1] = ImageList.Images[ClientUtils.GetImageIndex(isOutputArgument, value.Value)];
            row[2] = argument.Name;
            row[3] = dataType;
            row[4] = value;
            row[5] = String.Empty;
        }
        /// <summary>
        /// Updates the row with the data value.
        /// </summary>
        private void UpdateRow(DataRow row, MonitoredItemNotification notification)
        {
            DataValue value = notification.Value;

            row[11] = value;

            if (value != null)
            {
                row[1]  = ImageList.Images[ClientUtils.GetImageIndex(Attributes.Value, value.Value)];
                row[12] = (value.WrappedValue.TypeInfo != null) ? value.WrappedValue.TypeInfo.ToString() : String.Empty;
                row[13] = value.WrappedValue;
                row[14] = value.StatusCode;
                row[15] = value.SourceTimestamp.ToLocalTime().ToString("hh:mm:ss.fff");
                row[16] = value.ServerTimestamp.ToLocalTime().ToString("hh:mm:ss.fff");
            }
        }
        /// <summary>
        /// Updates the row.
        /// </summary>
        public void UpdateRow(DataRow row, FilterDeclarationField field)
        {
            row[0] = field;
            row[1] = ImageList.Images[ClientUtils.GetImageIndex(m_session, field.InstanceDeclaration.NodeClass, field.InstanceDeclaration.RootTypeId, false)];
            row[2] = field.InstanceDeclaration.BrowsePathDisplayText;
            row[3] = field.Selected;
            row[4] = field.DisplayInList;
            row[5] = field.FilterEnabled;

            if (field.FilterEnabled)
            {
                row[6] = field.FilterOperator;
                row[7] = field.FilterValue;
            }

            row[8] = m_counter++;
        }
Exemple #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;
                }
            }
        }
        /// <summary>
        /// Handles the BeforeExpand event of the BrowseTV control.
        /// </summary>
        private void BrowseTV_BeforeExpand(object sender, TreeViewCancelEventArgs e)
        {
            try
            {
                ReferenceDescription reference = (ReferenceDescription)e.Node.Tag;
                e.Node.Nodes.Clear();

                // build list of references to browse.
                BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection();

                for (int ii = 0; ii < m_referenceTypeIds.Length; ii++)
                {
                    BrowseDescription nodeToBrowse = new BrowseDescription();

                    nodeToBrowse.NodeId          = m_rootId;
                    nodeToBrowse.BrowseDirection = BrowseDirection.Forward;
                    nodeToBrowse.ReferenceTypeId = m_referenceTypeIds[ii];
                    nodeToBrowse.IncludeSubtypes = true;
                    nodeToBrowse.NodeClassMask   = 0;
                    nodeToBrowse.ResultMask      = (uint)BrowseResultMask.All;

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

                    nodesToBrowse.Add(nodeToBrowse);
                }

                // add the childen to the control.
                SortedDictionary <ExpandedNodeId, TreeNode> dictionary = new SortedDictionary <ExpandedNodeId, TreeNode>();

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

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

                    // ignore out of server references.
                    if (reference.NodeId.IsAbsolute)
                    {
                        continue;
                    }

                    if (dictionary.ContainsKey(reference.NodeId))
                    {
                        continue;
                    }

                    TreeNode child = new TreeNode(reference.ToString());

                    child.Nodes.Add(new TreeNode());
                    child.Tag = reference;

                    if (!reference.TypeDefinition.IsAbsolute)
                    {
                        try
                        {
                            if (!m_typeImageMapping.ContainsKey((NodeId)reference.TypeDefinition))
                            {
                                List <NodeId> nodeIds = ClientUtils.TranslateBrowsePaths(m_session, (NodeId)reference.TypeDefinition, m_session.NamespaceUris, Opc.Ua.BrowseNames.Icon);

                                if (nodeIds.Count > 0 && nodeIds[0] != null)
                                {
                                    DataValue value = m_session.ReadValue(nodeIds[0]);
                                    byte[]    bytes = value.Value as byte[];

                                    if (bytes != null)
                                    {
                                        System.IO.MemoryStream istrm = new System.IO.MemoryStream(bytes);
                                        Image icon = Image.FromStream(istrm);
                                        BrowseTV.ImageList.Images.Add(icon);
                                        m_typeImageMapping[(NodeId)reference.TypeDefinition] = BrowseTV.ImageList.Images.Count - 1;
                                    }
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            Utils.Trace(exception, "Error loading image.");
                        }
                    }

                    int index = 0;

                    if (!m_typeImageMapping.TryGetValue((NodeId)reference.TypeDefinition, out index))
                    {
                        child.ImageIndex         = ClientUtils.GetImageIndex(m_session, reference.NodeClass, reference.TypeDefinition, false);
                        child.SelectedImageIndex = ClientUtils.GetImageIndex(m_session, reference.NodeClass, reference.TypeDefinition, true);
                    }
                    else
                    {
                        child.ImageIndex         = index;
                        child.SelectedImageIndex = index;
                    }

                    dictionary[reference.NodeId] = child;
                }

                // add nodes to tree.
                foreach (TreeNode node in dictionary.Values.OrderBy(i => i.Text))
                {
                    e.Node.Nodes.Add(node);
                }
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
        /// <summary>
        /// Adds the results to the control.
        /// </summary>
        private void UpdateResults(ApplicationDescription[] descriptions)
        {
            ServersLV.Items.Clear();

            if (descriptions == null)
            {
                return;
            }

            for (int ii = 0; ii < descriptions.Length; ii++)
            {
                ApplicationDescription description = descriptions[ii];

                if (description == null)
                {
                    continue;
                }

                ListViewItem item = new ListViewItem();
                item.Text       = Utils.Format("{0}", description.ApplicationName);
                item.ImageIndex = ClientUtils.GetImageIndex(ServerCTRL.Session, NodeClass.Object, null, false);
                item.SubItems.Add(new ListViewItem.ListViewSubItem());
                item.SubItems.Add(new ListViewItem.ListViewSubItem());
                item.SubItems.Add(new ListViewItem.ListViewSubItem());
                item.Tag = description;
                ServersLV.Items.Add(item);

                item.SubItems[1].Text = description.ApplicationType.ToString();

                if (description.DiscoveryUrls == null)
                {
                    continue;
                }

                // collect the domains and protocols.
                List <string> domains   = new List <string>();
                List <string> protocols = new List <string>();

                foreach (string discoveryUrl in description.DiscoveryUrls)
                {
                    Uri url = Utils.ParseUri(discoveryUrl);

                    if (url != null)
                    {
                        if (!domains.Contains(url.DnsSafeHost))
                        {
                            domains.Add(url.DnsSafeHost);
                        }

                        if (!protocols.Contains(url.Scheme))
                        {
                            protocols.Add(url.Scheme);
                        }
                    }
                }

                // format the domains.
                StringBuilder buffer = new StringBuilder();

                foreach (string domain in domains)
                {
                    if (buffer.Length > 0)
                    {
                        buffer.Append(", ");
                    }

                    buffer.Append(domain);
                }

                item.SubItems[2].Text = buffer.ToString();

                // format the protocols.
                buffer = new StringBuilder();

                foreach (string protocol in protocols)
                {
                    if (buffer.Length > 0)
                    {
                        buffer.Append(", ");
                    }

                    buffer.Append(protocol);
                }

                item.SubItems[3].Text = buffer.ToString();
            }

            // adjust column widths.
            for (int ii = 0; ii < ServersLV.Columns.Count; ii++)
            {
                ServersLV.Columns[ii].Width = -2;
            }
        }
Exemple #12
0
        /// <summary>
        /// Reads the properties for the node.
        /// </summary>
        private void ReadProperties(NodeId nodeId)
        {
            // build list of references to browse.
            BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection();

            BrowseDescription nodeToBrowse = new BrowseDescription();

            nodeToBrowse.NodeId          = nodeId;
            nodeToBrowse.BrowseDirection = BrowseDirection.Forward;
            nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HasProperty;
            nodeToBrowse.IncludeSubtypes = true;
            nodeToBrowse.NodeClassMask   = (uint)NodeClass.Variable;
            nodeToBrowse.ResultMask      = (uint)BrowseResultMask.All;

            nodesToBrowse.Add(nodeToBrowse);

            // find properties.
            ReferenceDescriptionCollection references = ClientUtils.Browse(m_session, View, nodesToBrowse, false);

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

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

                // ignore out of server references.
                if (reference.NodeId.IsAbsolute)
                {
                    continue;
                }

                ReadValueId nodeToRead = new ReadValueId();
                nodeToRead.NodeId      = (NodeId)reference.NodeId;
                nodeToRead.AttributeId = Attributes.Value;
                nodeToRead.Handle      = reference;
                nodesToRead.Add(nodeToRead);
            }

            if (nodesToRead.Count == 0)
            {
                return;
            }

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

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

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

            // add the results to the display.
            for (int ii = 0; ii < results.Count; ii++)
            {
                ReferenceDescription reference = (ReferenceDescription)nodesToRead[ii].Handle;

                TypeInfo typeInfo = TypeInfo.Construct(results[ii].Value);

                // add the metadata for the attribute.
                ListViewItem item = new ListViewItem(reference.ToString());
                item.SubItems.Add(typeInfo.BuiltInType.ToString());

                if (typeInfo.ValueRank >= 0)
                {
                    item.SubItems[1].Text += "[]";
                }

                // add the value.
                if (StatusCode.IsBad(results[ii].StatusCode))
                {
                    item.SubItems.Add(results[ii].StatusCode.ToString());
                }
                else
                {
                    item.SubItems.Add(results[ii].WrappedValue.ToString());
                }

                item.Tag = new AttributeInfo()
                {
                    NodeToRead = nodesToRead[ii], Value = results[ii]
                };
                item.ImageIndex = ClientUtils.GetImageIndex(m_session, NodeClass.Variable, Opc.Ua.VariableTypeIds.PropertyType, false);

                // display in list.
                AttributesLV.Items.Add(item);
            }
        }
Exemple #13
0
        /// <summary>
        /// Reads the attributes for the node.
        /// </summary>
        public void ReadAttributes(NodeId nodeId, bool showProperties)
        {
            AttributesLV.Items.Clear();

            if (NodeId.IsNull(nodeId))
            {
                return;
            }

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

            foreach (uint attributeId in Attributes.GetIdentifiers())
            {
                ReadValueId nodeToRead = new ReadValueId();
                nodeToRead.NodeId      = 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);

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

            // add the results to the display.
            for (int ii = 0; ii < results.Count; ii++)
            {
                // check for error.
                if (StatusCode.IsBad(results[ii].StatusCode))
                {
                    if (results[ii].StatusCode == StatusCodes.BadAttributeIdInvalid)
                    {
                        continue;
                    }
                }

                // add the metadata for the attribute.
                uint         attributeId = nodesToRead[ii].AttributeId;
                ListViewItem item        = new ListViewItem(Attributes.GetBrowseName(attributeId));
                item.SubItems.Add(Attributes.GetBuiltInType(attributeId).ToString());

                if (Attributes.GetValueRank(attributeId) >= 0)
                {
                    item.SubItems[0].Text += "[]";
                }

                // add the value.
                if (StatusCode.IsBad(results[ii].StatusCode))
                {
                    item.SubItems.Add(results[ii].StatusCode.ToString());
                }
                else
                {
                    item.SubItems.Add(ClientUtils.GetAttributeDisplayText(m_session, attributeId, results[ii].WrappedValue));
                }

                item.Tag = new AttributeInfo()
                {
                    NodeToRead = nodesToRead[ii], Value = results[ii]
                };
                item.ImageIndex = ClientUtils.GetImageIndex(nodesToRead[ii].AttributeId, results[ii].Value);

                // display in list.
                AttributesLV.Items.Add(item);
            }

            if (showProperties)
            {
                ReadProperties(nodeId);
            }

            // set the column widths.
            for (int ii = 0; ii < AttributesLV.Columns.Count; ii++)
            {
                AttributesLV.Columns[ii].Width = -2;
            }
        }