private void EditMI_Click(object sender, EventArgs e)
        {
            try
            {
                Argument[] arguments = GetSelectedItems(typeof(Argument)) as Argument[];

                if (arguments == null || arguments.Length != 1)
                {
                    return;
                }

                object value = GuiUtils2.EditValue(m_session, arguments[0].Value, arguments[0].DataType, arguments[0].ValueRank);

                if (value != null)
                {
                    arguments[0].Value = value;
                }

                UpdateItem(ItemsLV.SelectedItems[0], arguments[0]);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, System.Reflection.MethodBase.GetCurrentMethod(), exception);
            }
        }
        private void EditMI_Click(object sender, EventArgs e)
        {
            try
            {
                NodeField[] items = GetSelectedItems(typeof(NodeField)) as NodeField[];

                if (items != null && items.Length == 1)
                {
                    object value = GuiUtils2.EditValue(m_session, items[0].Value);

                    if (!m_readOnly)
                    {
                        if (value != null)
                        {
                            items[0].Value = value;
                            UpdateItem(ItemsLV.SelectedItems[0], items[0]);
                        }
                    }
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
示例#3
0
        /// <summary>
        /// Sets the root node for the control.
        /// </summary>
        public void SetRoot(Browser browser, NodeId rootId)
        {
            Clear();

            ShowReferencesMI.Checked = m_showReferences;

            m_rootId  = rootId;
            m_browser = browser;

            if (m_browser != null)
            {
                m_browser.MoreReferences += m_BrowserMoreReferences;
            }

            // check if session is connected.
            if (m_browser == null || !m_browser.Session.Connected)
            {
                return;
            }

            if (NodeId.IsNull(rootId))
            {
                m_rootId = Objects.RootFolder;
            }

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

                if (node == null)
                {
                    return;
                }

                ReferenceDescription reference = new ReferenceDescription();

                reference.ReferenceTypeId = ReferenceTypeIds.References;
                reference.IsForward       = true;
                reference.NodeId          = node.NodeId;
                reference.NodeClass       = (NodeClass)node.NodeClass;
                reference.BrowseName      = node.BrowseName;
                reference.DisplayName     = node.DisplayName;
                reference.TypeDefinition  = null;

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

                TreeNode root = AddNode(null, reference, text, icon);
                root.Nodes.Add(new TreeNode());
                root.Expand();
            }
        }
        private void EditValueMI_Click(object sender, EventArgs e)
        {
            try
            {
                WriteValue[] values = GetSelectedItems(typeof(WriteValue)) as WriteValue[];

                if (values == null || values.Length != 1)
                {
                    return;
                }

                NodeId datatypeId = Attributes.GetDataTypeId(values[0].AttributeId);
                int    valueRank  = Attributes.GetValueRank(values[0].AttributeId);

                if (values[0].AttributeId == Attributes.Value)
                {
                    VariableNode node = m_session.NodeCache.Find(values[0].NodeId) as VariableNode;

                    if (node != null)
                    {
                        datatypeId = node.DataType;
                        valueRank  = node.ValueRank;
                    }
                }

                object value = GuiUtils2.EditValue(m_session, values[0].Value.Value, datatypeId, valueRank);

                if (value != null)
                {
                    values[0].Value.Value           = value;
                    values[0].Value.StatusCode      = StatusCodes.Good;
                    values[0].Value.ServerTimestamp = DateTime.MinValue;
                    values[0].Value.SourceTimestamp = DateTime.MinValue;

                    UpdateItem(ItemsLV.SelectedItems[0], values[0]);

                    AdjustColumns();
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
示例#5
0
        /// <summary>
        /// Adds a target to the tree control.
        /// </summary>
        private void AddReferences(TreeNode parent, ReferenceDescriptionCollection references)
        {
            foreach (ReferenceDescription reference in references)
            {
                // supress 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);
                }

                TreeNode child = AddNode(container, reference, text, icon);
                child.Nodes.Add(new TreeNode());
            }
        }
示例#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();
        }