Пример #1
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);
            }
        }
Пример #2
0
        private void BrowseMI_Click(object sender, EventArgs e)
        {
            try {
                if (NodesTV.SelectedNode == null)
                {
                    return;
                }

                ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;

                if (reference == null || reference.NodeId == null || reference.NodeId.IsAbsolute)
                {
                    return;
                }

                new BrowseDlg().Show(m_browser.Session, (NodeId)reference.NodeId);
            } catch (Exception exception) {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Пример #3
0
        private void EncodingsMI_Click(object sender, EventArgs e)
        {
            try {
                if (NodesTV.SelectedNode == null)
                {
                    return;
                }

                ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;

                if (reference == null || (reference.NodeClass & NodeClass.Variable) == 0)
                {
                    return;
                }

                new DataEncodingDlg().ShowDialog(m_browser.Session, (NodeId)reference.NodeId);
            } catch (Exception exception) {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Пример #4
0
        /// <summary>
        /// Updates the display after a node is selected.
        /// </summary>
        private void BrowseNodesTV_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try
            {
                // get the source for the node.
                ReferenceDescription reference = e.Node.Tag as ReferenceDescription;

                if (reference == null || reference.NodeId.IsAbsolute)
                {
                    return;
                }

                // populate children.
                PopulateBranch((NodeId)reference.NodeId, e.Node.Nodes);
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
Пример #5
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is ReferenceDescription)
            {
                ReferenceDescription node = value as ReferenceDescription;
                switch (node.NodeClass)
                {
                case NodeClass.Unspecified:
                    break;

                case NodeClass.Object:
                    break;

                case NodeClass.Variable:
                    return(node.DisplayName.Text.Contains(':') ? (node.DisplayName.Text.Substring(0, node.DisplayName.Text.IndexOf(':'))) : node.DisplayName.Text);

                case NodeClass.Method:
                    break;

                case NodeClass.ObjectType:
                    break;

                case NodeClass.VariableType:
                    break;

                case NodeClass.ReferenceType:
                    break;

                case NodeClass.DataType:
                    break;

                case NodeClass.View:
                    break;

                default:
                    break;
                }
                return(node.DisplayName.ToString());
            }
            return(null);
        }
Пример #6
0
        private void GetTanks()
        {
            BrowseDescription nodeToBrowse = new BrowseDescription();

            nodeToBrowse.NodeId          = Opc.Ua.ObjectIds.ObjectsFolder;
            nodeToBrowse.BrowseDirection = BrowseDirection.Forward;
            nodeToBrowse.ReferenceTypeId = Opc.Ua.ReferenceTypeIds.HierarchicalReferences;
            nodeToBrowse.IncludeSubtypes = true;
            nodeToBrowse.NodeClassMask   = (uint)(NodeClass.Object);
            nodeToBrowse.ResultMask      = (uint)(BrowseResultMask.All);

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

            ReferenceDescription tank = null;

            if (references != null)
            {
                for (int ii = 1; ii < references.Count; ii++)
                {
                    //tanks.Add(references[ii]);
                    tank = references[ii];
                }
            }

            NamespaceTable wellKnownNamespaceUris = new NamespaceTable();

            string[] browsePaths = new string[]
            {
                "1:Level",
                "2:Temperature"
            };

            List <NodeId> nodes = ClientUtils.TranslateBrowsePaths(
                m_session,
                (NodeId)tank.NodeId,
                wellKnownNamespaceUris,
                browsePaths);
        }
Пример #7
0
        /// <summary>
        /// Event being fired when an item is dragged over the tree view control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void tvBrowseTree_ItemDrag(object sender, System.Windows.Forms.ItemDragEventArgs e)
        {
            if (((TreeNode)e.Item).Tag.GetType() == typeof(ReferenceDescription))
            {
                // Get the data about the tree node.
                ReferenceDescription reference = (ReferenceDescription)((TreeNode)e.Item).Tag;

                // Allow only variables drag and drop.
                if (reference.NodeId.IsAbsolute || reference.NodeClass != NodeClass.Variable)
                {
                    return;
                }

                // Start the drag and drop action.
                // We have to copy serializable data like strings.
                String sNodeId = reference.NodeId.ToString();

                // The data is copied to the target control.
                DragDropEffects dde = tvBrowseTree.DoDragDrop(sNodeId, DragDropEffects.Copy);
            }
        }
Пример #8
0
        /// <summary>
        /// Adds a item to a subscription.
        /// </summary>
        private void Subscribe(Subscription subscription, ReferenceDescription reference)
        {
            MonitoredItem monitoredItem = new MonitoredItem(subscription.DefaultItem);

            monitoredItem.DisplayName      = subscription.Session.NodeCache.GetDisplayText(reference);
            monitoredItem.StartNodeId      = (NodeId)reference.NodeId;
            monitoredItem.NodeClass        = (NodeClass)reference.NodeClass;
            monitoredItem.AttributeId      = Attributes.Value;
            monitoredItem.SamplingInterval = -1;

            // add condition fields to any event filter.
            EventFilter filter = monitoredItem.Filter as EventFilter;

            if (filter != null)
            {
                monitoredItem.AttributeId = Attributes.EventNotifier;
            }

            subscription.AddItem(monitoredItem);
            subscription.ApplyChanges();
        }
Пример #9
0
 private void BrowseCTRL_NodeSelected(object sender, TreeNodeActionEventArgs e)
 {
     if (e.Node != null)
     {
         ReferenceDescription reference = e.Node as ReferenceDescription;
         if (reference != null && reference.NodeClass == NodeClass.Variable)
         {
             CommandBTN.Visibility = Visibility.Visible;
             CommandBTN.Content    = "Report";
             RemoveAllClickEventsFromButton();
             CommandBTN.Click += ContextMenu_OnReport;
             CommandBTN.Tag    = e.Node;
         }
         else
         {
             RemoveAllClickEventsFromButton();
             CommandBTN.Visibility = Visibility.Collapsed;
             CommandBTN.Tag        = null;
         }
     }
 }
Пример #10
0
        private void ChangeBTN_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_session != null)
                {
                    ReferenceDescription reference = PhaseCB.SelectedItem as ReferenceDescription;

                    if (reference != null)
                    {
                        NodeId objectId = ExpandedNodeId.ToNodeId(DsatsDemo.ObjectIds.Rig, m_session.NamespaceUris);
                        NodeId methodId = ExpandedNodeId.ToNodeId(DsatsDemo.MethodIds.Rig_ChangePhase, m_session.NamespaceUris);
                        m_session.Call(objectId, methodId, (NodeId)reference.NodeId);
                    }
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        /// <summary>
        /// Helper function for reading attributes.
        /// </summary>
        /// <param name="treeNodeToRead"></param>
        /// <returns></returns>
        public int ReadAttributes(TreeNode treeNodeToRead)
        {
            ReadValueIdCollection nodesToRead;
            List <DataValue>      results = null;

            ReferenceDescription refDescr = (ReferenceDescription)treeNodeToRead.Tag;

            if (refDescr == null)
            {
                return(-1);
            }

            // Create a read request.
            buildAttributeList(refDescr, out nodesToRead);

            try
            {
                // Clear list view.
                this.lvAttributes.Items.Clear();

                results = m_Session.Read(
                    nodesToRead,
                    0,
                    TimestampsToReturn.Both,
                    null);

                // Show results in the listview.
                updateAttributeList(nodesToRead, results);
            }
            catch (Exception e)
            {
                // Update status label.
                OnUpdateStatusLabel("An exception occured while reading: " + e.Message, false);
                return(-1);
            }

            // Update status label.
            OnUpdateStatusLabel("Read succeeded for Node \"" + refDescr.DisplayName + "\".", true);
            return(0);
        }
Пример #12
0
        /// <summary>
        /// 根据ID号查询下一级子节点集合
        /// </summary>
        /// <param name="sourceId"></param>
        /// <returns></returns>
        private List <OpcNode> ShowMember_test(NodeId sourceId)
        {
            ReferenceDescriptionCollection references = GetReferenceDescriptionCollection(sourceId);

            if (references?.Count > 0)
            {
                // 获取所有要读取的子节点
                List <OpcNode> opcNodes = new List <OpcNode>();

                System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
                watch.Start();  //开始监视代码运行时间

                for (int ii = 0; ii < references.Count; ii++)
                {
                    ReferenceDescription target = references[ii];
                    //不为属性变量则显示
                    //if (target.NodeClass!=NodeClass.Variable)
                    //{
                    //    nodeIds.Add((NodeId)target.NodeId);
                    //}

                    string  key   = GetImageKeyFromDescription(target, sourceId);
                    OpcNode child = new OpcNode(Utils.Format("{0}", target), target.NodeId.ToString(), key);
                    child.Attribute = ReadOneNodeFiveAttribute(target.NodeId.ToString());
                    if (child.Attribute != null)
                    {
                        opcNodes.Add(child);
                    }
                }
                //需要测试的代码
                watch.Stop();                                                                         //停止监视
                TimeSpan timespan = watch.Elapsed;                                                    //获取当前实例测量得出的总时间
                System.Diagnostics.Debug.WriteLine("打开窗口代码执行时间:{0}(毫秒)", timespan.TotalMilliseconds); //总毫秒数
                return(opcNodes);
            }
            else
            {
                return(new List <OpcNode>());
            }
        }
        /// <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();
        }
Пример #14
0
        public LiveChartViewModel(UaClientApi uaClientApi, Messenger messenger)
        {
            _uaClientApi = uaClientApi;

            _subscription = _uaClientApi.Subscribe(2000, "LiveCharts");

            if (_subscription == null)
            {
                IoC.AppManager.ShowWarningMessage("Subscription creation failed, please restart application!");
            }

            AddCommand    = new MixRelayCommand(AddVariable, AddVariableCanUse);
            RemoveCommand = new MixRelayCommand(RemoveVariable, RemoveVariableCanUse);

            // Nastavenia grafu
            DateTimeFormatter = value => new DateTime((long)value).ToString("mm:ss");
            AxisStep          = TimeSpan.FromSeconds(15).Ticks;
            AxisUnit          = TimeSpan.TicksPerSecond;
            SetAxisLimits(DateTime.Now);

            messenger.Register <SendSelectedRefNode>(msg => _selectedNode = msg.ReferenceNode);
        }
Пример #15
0
        private void BrowseBTN_Click(object sender, EventArgs e)
        {
            try
            {
                ReferenceDescription reference = new SelectNodeDlg().ShowDialog(m_browser.Session, RootId, null, "", null);

                if (reference != null && reference.NodeId != null)
                {
                    NodeIdTB.Text = Utils.Format("{0}", reference.NodeId);
                    m_reference   = reference;

                    if (m_IdentifierChanged != null)
                    {
                        m_IdentifierChanged(this, null);
                    }
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Пример #16
0
        /// <summary>
        /// Recursively finds and selects a node in the control.
        /// </summary>
        private bool SelectNode(TreeNodeCollection nodes, NodeId nodeId)
        {
            foreach (TreeNode node in nodes)
            {
                ReferenceDescription reference = node.Tag as ReferenceDescription;

                if (reference != null)
                {
                    if (reference.NodeId == nodeId)
                    {
                        BrowseTV.SelectedNode = node;
                        node.EnsureVisible();
                        node.Checked = true;
                        return(true);
                    }
                }

                SelectNode(node.Nodes, nodeId);
            }

            return(false);
        }
Пример #17
0
 private void BrowsePage_Enter()
 {
     //if (Connect.myReferenceDescriptionCollection == null)
     //{
     try
     {
         Connect.myReferenceDescriptionCollection = Connect.myClientHelperAPI.BrowseRoot();
         foreach (ReferenceDescription refDesc in Connect.myReferenceDescriptionCollection)
         {
             _ref = refDesc;
             CustomTreeNode Root = new CustomTreeNode("Root");
             Root.Text = refDesc.DisplayName.ToString();
             Root.Tag  = _ref;
             nodeTreeView.Nodes.Add(Root);
         }
     }
     catch (Exception ex)
     {
         ClientScript.RegisterStartupScript(this.GetType(), "Alert", "mess('error','Opps...'," + ex.ToString() + ")", true);
     }
     //}
 }
Пример #18
0
        /// <summary>
        /// Handles the AfterSelect event of the BrowseTV control.
        /// </summary>
        private void BrowseTV_AfterSelect(object sender, TreeViewEventArgs e)
        {
            try {
                m_selectedNodeId = null;

                if (BrowseTV.SelectedNode == null)
                {
                    if (m_AfterSelect != null)
                    {
                        m_AfterSelect(this, new EventArgs());
                    }
                    return;
                }

                // get node to browse.
                ReferenceDescription reference = (ReferenceDescription)e.Node.Tag;
                NodeId nodeId = m_rootId;

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

                m_selectedNodeId = nodeId;

                if (AttributesControl != null)
                {
                    AttributesControl.ReadAttributes(m_selectedNodeId, true);
                }

                // raise event.
                if (m_AfterSelect != null)
                {
                    m_AfterSelect(this, new EventArgs());
                }
            } catch (Exception exception) {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
Пример #19
0
        private void WriteValueMI_Click(object sender, EventArgs e)
        {
            try
            {
                #region Task #B2 - Write Value
                // do nothing if nothing selected or if a off server reference was returned.
                ReferenceDescription reference = BrowseCTRL.SelectedNode;

                if (reference == null || reference.NodeId.IsAbsolute)
                {
                    return;
                }

                // display the dialog.
                new WriteValueDlg().ShowDialog(m_session, ExpandedNodeId.ToNodeId(reference.NodeId, m_session.NamespaceUris));
                #endregion
            }
            catch (Exception exception)
            {
                ClientUtils.HandleException(this.Text, exception);
            }
        }
Пример #20
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;
                }
            }
        }
Пример #21
0
        /// <summary>
        /// Collects the types selected in the control.
        /// </summary>
        private NodeId CollectTypeIds(TreeNode node, List <NodeId> typeIds)
        {
            if (!node.Checked)
            {
                return(null);
            }

            ReferenceDescription reference = node.Tag as ReferenceDescription;

            NodeId typeId     = null;
            int    childCount = 0;

            foreach (TreeNode child in node.Nodes)
            {
                NodeId childTypeId = CollectTypeIds(child, typeIds);

                if (childTypeId != null)
                {
                    typeId = childTypeId;
                    childCount++;
                }
            }

            if (reference != null)
            {
                if (childCount != 1)
                {
                    typeId = (NodeId)reference.NodeId;
                }

                if (childCount == 0)
                {
                    typeIds.Add((NodeId)reference.NodeId);
                }
            }

            return(typeId);
        }
Пример #22
0
        internal void WriteMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (NodesTV.SelectedNode == null)
                {
                    return;
                }

                ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;

                if (reference == null || (reference.NodeClass & (NodeClass.Variable | NodeClass.VariableType)) == 0)
                {
                    return;
                }

                Session session = m_browser.Session;

                // build list of nodes to read.
                WriteValueCollection values = new WriteValueCollection();

                WriteValue value = new WriteValue();

                value.NodeId      = (NodeId)reference.NodeId;
                value.AttributeId = Attributes.Value;
                value.IndexRange  = null;
                value.Value       = null;

                values.Add(value);

                // show form.
                new WriteDlg().Show(session, values);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Пример #23
0
        private void ReadMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (NodesTV.SelectedNode == null)
                {
                    return;
                }

                ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;

                if (reference == null || (reference.NodeClass & (NodeClass.Variable | NodeClass.VariableType)) == 0)
                {
                    return;
                }

                Session session = m_browser.Session;

                // build list of nodes to read.
                ReadValueIdCollection valueIds = new ReadValueIdCollection();

                ReadValueId valueId = new ReadValueId();

                valueId.NodeId       = (NodeId)reference.NodeId;
                valueId.AttributeId  = Attributes.Value;
                valueId.IndexRange   = null;
                valueId.DataEncoding = null;

                valueIds.Add(valueId);

                // show form.
                new ReadDlg().Show(session, valueIds);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Пример #24
0
        private void WriteMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (NodesTV.SelectedItem == null)
                {
                    return;
                }

                ReferenceDescription reference = NodesTV.SelectedItem.Item as ReferenceDescription;

                if (reference == null || (reference.NodeClass & (NodeClass.Variable | NodeClass.VariableType)) == 0)
                {
                    return;
                }

                Session session = m_browser.Session;

                // build list of nodes to read.
                WriteValueCollection values = new WriteValueCollection();

                WriteValue value = new WriteValue();

                value.NodeId      = (NodeId)reference.NodeId;
                value.AttributeId = Attributes.Value;
                value.IndexRange  = null;
                value.Value       = null;

                values.Add(value);

                // show form.
                //new WriteDlg().Show(session, values);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception);
            }
        }
Пример #25
0
        private void ViewAttributesMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (NodesTV.SelectedNode == null)
                {
                    return;
                }

                ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;

                if (reference == null)
                {
                    return;
                }

                new NodeAttributesDlg().ShowDialog(m_browser.Session, reference.NodeId);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Пример #26
0
        private bool IfItemToSub(ref List <ItemOPCUA> ItemsOPCUA, ReferenceDescription rd, int level)
        {
            bool continueOk = false;

            foreach (var itemUA in ItemsOPCUA)
            {
                string[] subIds = itemUA.id.Split(new string[] { ".:." }, StringSplitOptions.None);
                if (rd.DisplayName.Text == subIds[level])
                {
                    if (subIds.Length == level + 1) // item to sub
                    {
                        ItemsOPCUA[ItemsOPCUA.IndexOf(itemUA)].nodeId = (NodeId)rd.NodeId;
                        CreateMonitoredItem((NodeId)rd.NodeId, Opc.Ua.Utils.Format("{0}", rd), ItemsOPCUA[ItemsOPCUA.IndexOf(itemUA)].monMode, ItemsOPCUA[ItemsOPCUA.IndexOf(itemUA)].sampling);
                    }
                    else // folder to enter
                    {
                        continueOk = true;
                    }
                }
            }

            return(continueOk);
        }
Пример #27
0
        /// <summary>
        /// Adds a select clause to the control.
        /// </summary>
        public void AddSelectClause(ReferenceDescription reference)
        {
            if (reference == null)
            {
                return;
            }

            ILocalNode node = m_session.NodeCache.Find(reference.NodeId) as ILocalNode;

            if (node == null)
            {
                return;
            }

            SimpleAttributeOperand clause = new SimpleAttributeOperand();

            clause.TypeDefinitionId = m_session.NodeCache.BuildBrowsePath(node, clause.BrowsePath);
            clause.AttributeId      = Attributes.Value;

            AddItem(clause, "Property", -1);

            AdjustColumns();
        }
Пример #28
0
        private void ViewAttributesMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (NodesTV.SelectedItem == null)
                {
                    return;
                }

                ReferenceDescription reference = NodesTV.SelectedItem.Item as ReferenceDescription;

                if (reference == null)
                {
                    return;
                }

                //new NodeAttributesDlg().ShowDialog(m_browser.Session, reference.NodeId);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception);
            }
        }
Пример #29
0
        private void EncodingsMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (NodesTV.SelectedItem == null)
                {
                    return;
                }

                ReferenceDescription reference = NodesTV.SelectedItem.Item as ReferenceDescription;

                if (reference == null || (reference.NodeClass & NodeClass.Variable) == 0)
                {
                    return;
                }

                //new DataEncodingDlg().ShowDialog(m_browser.Session, (NodeId)reference.NodeId);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception);
            }
        }
Пример #30
0
        private void BrowseMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (NodesTV.SelectedItem == null)
                {
                    return;
                }

                ReferenceDescription reference = NodesTV.SelectedItem.Item as ReferenceDescription;

                if (reference == null || reference.NodeId == null || reference.NodeId.IsAbsolute)
                {
                    return;
                }

                new BrowseDlg().Show(m_browser.Session, (NodeId)reference.NodeId);
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(String.Empty, GuiUtils.CallerName(), exception);
            }
        }
Пример #31
0
        private void BrowseBTN_Click(object sender, EventArgs e)
        {
            try
            {
                ReferenceDescription reference = new SelectNodeDlg().ShowDialog(m_browser.Session, RootId, null, "", null);

                if (reference != null && reference.NodeId != null)
                {
                    NodeIdTB.Text = Utils.Format("{0}", reference.NodeId);
                    m_reference = reference;

                    if (m_IdentifierChanged != null)
                    {
                        m_IdentifierChanged(this, null);
                    }
                }
            }
            catch (Exception exception)
            {
				GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Пример #32
0
        private void BrowseCTRL_NodeSelected(object sender, TreeNodeActionEventArgs e)
        {
            try
            {
                // disable ok button if selection is not valid.
                OkBTN.Enabled = false;

                ReferenceDescription reference = e.Node as ReferenceDescription;
                
                if (reference == null)
                {
                    return;
                }

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

                // set the display name.
                DisplayNameTB.Text       = reference.ToString();
                NodeClassCB.SelectedItem = (NodeClass)reference.NodeClass;
                
                // set identifier type.
                IdentifierTypeCB.SelectedItem = reference.NodeId.IdType;

                // set namespace uri.
                if (!String.IsNullOrEmpty(reference.NodeId.NamespaceUri))
                {
                    NamespaceUriCB.SelectedIndex = -1;
                    NamespaceUriCB.Text = reference.NodeId.NamespaceUri;
                }
                else
                {
                    if (reference.NodeId.NamespaceIndex < NamespaceUriCB.Items.Count)
                    {
                        NamespaceUriCB.SelectedIndex = (int)reference.NodeId.NamespaceIndex;
                    }
                    else
                    {
                        NamespaceUriCB.SelectedIndex = -1;
                        NamespaceUriCB.Text = null;
                    }
                }
                
                // set identifier.
                switch (reference.NodeId.IdType)
                {
                    case IdType.Opaque:
                    {
                        NodeIdentifierTB.Text = Convert.ToBase64String((byte[])reference.NodeId.Identifier);
                        break;
                    }

                    default:
                    {
                        NodeIdentifierTB.Text = Utils.Format("{0}", reference.NodeId.Identifier);
                        break;
                    }
                }

                // selection valid - enable ok.
                OkBTN.Enabled = true;
                m_reference = reference;
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
Пример #33
0
 private void IdentifierTypeCB_SelectedIndexChanged(object sender, EventArgs e)
 {
     m_reference = null;
     OkBTN.Enabled = false;
 }
Пример #34
0
        /// <summary>
        /// Recursively processes the elements in the RelativePath starting at the specified index.
        /// </summary>
        private void TranslateBrowsePath(
            OperationContext           context,
            INodeManager               nodeManager,
            object                     sourceHandle,
            RelativePath               relativePath,
            BrowsePathTargetCollection targets,
            int                        index)
        {
            Debug.Assert(nodeManager != null);
            Debug.Assert(sourceHandle != null);
            Debug.Assert(relativePath != null);
            Debug.Assert(targets != null);

            // check for end of list.
            if (index < 0 || index >= relativePath.Elements.Count)
            {
                return;
            }
            
            // follow the next hop.
            RelativePathElement element = relativePath.Elements[index];

            // check for valid reference type.
            if (!element.IncludeSubtypes && NodeId.IsNull(element.ReferenceTypeId))
            {
                return;
            }

            // check for valid target name.
            if (QualifiedName.IsNull(element.TargetName))
            {
                throw new ServiceResultException(StatusCodes.BadBrowseNameInvalid);
            }

            List<ExpandedNodeId> targetIds = new List<ExpandedNodeId>();
            List<NodeId> externalTargetIds = new List<NodeId>();

            try
            {
                nodeManager.TranslateBrowsePath(
                    context,
                    sourceHandle,
                    element,
                    targetIds,
                    externalTargetIds);
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error translating browse path.");
                return;
            }

            // must check the browse name on all external targets.
            for (int ii = 0; ii < externalTargetIds.Count; ii++)
            {
                // get the browse name from another node manager.
                ReferenceDescription description = new ReferenceDescription();

                UpdateReferenceDescription(
                    context,
                    externalTargetIds[ii],
                    NodeClass.Unspecified,
                    BrowseResultMask.BrowseName,
                    description);    
                
                // add to list if target name matches.
                if (description.BrowseName == element.TargetName)
                {
                    bool found = false;

                    for (int jj = 0; jj < targetIds.Count; jj++)
                    {
                        if (targetIds[jj] == externalTargetIds[ii])
                        {
                            found = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        targetIds.Add(externalTargetIds[ii]);
                    }
                }
            }

            // check if done after a final hop.
            if (index == relativePath.Elements.Count-1)
            {
                for (int ii = 0; ii < targetIds.Count; ii++)
                {
                    BrowsePathTarget target = new BrowsePathTarget();   
                 
                    target.TargetId = targetIds[ii];
                    target.RemainingPathIndex = UInt32.MaxValue;

                    targets.Add(target);
                }

                return;
            }

            // process next hops.
            for (int ii = 0; ii < targetIds.Count; ii++)
            {
                ExpandedNodeId targetId = targetIds[ii];

                // check for external reference.
                if (targetId.IsAbsolute)
                {
                    BrowsePathTarget target = new BrowsePathTarget();   
                 
                    target.TargetId = targetId;
                    target.RemainingPathIndex = (uint)(index+1);

                    targets.Add(target);
                    continue;
                }

                // check for valid start node.   
                sourceHandle = GetManagerHandle((NodeId)targetId, out nodeManager);

                if (sourceHandle == null)
                {
                    continue;
                }
            
                // recusively follow hops.
                TranslateBrowsePath(
                    context,
                    nodeManager,
                    sourceHandle,
                    relativePath,
                    targets,
                    index+1);
            }
        }
Пример #35
0
        /// <summary>
        /// Creates an item from a reference.
        /// </summary>
        public void AddItem(ReferenceDescription reference)
        {
            if (reference == null)
            {
                return;
            }

            Node node = m_subscription.Session.NodeCache.Find(reference.NodeId) as Node;

            if (node == null)
            {
                return;
            }

            Node parent = null;

            // if the NodeId is of type string and contains '.' do not use relative paths
            if (node.NodeId.IdType != IdType.String || (node.NodeId.Identifier.ToString().IndexOf('.') == -1 && node.NodeId.Identifier.ToString().IndexOf('/') == -1))
            {
                parent = FindParent(node);
            }

            MonitoredItem monitoredItem = new MonitoredItem(m_subscription.DefaultItem);

            if (parent != null)
            {
                monitoredItem.DisplayName = String.Format("{0}.{1}", parent, node);
            }
            else
            {
                monitoredItem.DisplayName = String.Format("{0}", node);
            }
             
            monitoredItem.StartNodeId = node.NodeId;
            monitoredItem.NodeClass   = node.NodeClass;

            if (parent != null)
            {
                List<Node> parents = new List<Node>();
                parents.Add(parent);

                while (parent.NodeClass != NodeClass.ObjectType && parent.NodeClass != NodeClass.VariableType)
                {
                    parent = FindParent(parent);

                    if (parent == null)
                    {
                        break;
                    }
                        
                    parents.Add(parent);
                }
                
                monitoredItem.StartNodeId = parents[parents.Count-1].NodeId;

                StringBuilder relativePath = new StringBuilder();

                for (int ii = parents.Count-2; ii >= 0; ii--)
                {
                    relativePath.AppendFormat(".{0}", parents[ii].BrowseName);
                }

                relativePath.AppendFormat(".{0}", node.BrowseName);

                monitoredItem.RelativePath = relativePath.ToString();
            }

            Session session = m_subscription.Session;

            if (node.NodeClass == NodeClass.Object || node.NodeClass == NodeClass.Variable)
            {
                node.Find(ReferenceTypeIds.HasChild, true);

            }

            m_subscription.AddItem(monitoredItem);
        }
        /// <summary>
        /// Returns the references for the node that meets the criteria specified.
        /// </summary>
        private ReferenceDescription GetReferenceDescription(
            OperationContext context,
            IReference reference,
            ContinuationPoint continuationPoint)
        {
            // create the type definition reference.        
            ReferenceDescription description = new ReferenceDescription();

            description.NodeId = reference.TargetId;
            description.SetReferenceType(continuationPoint.ResultMask, reference.ReferenceTypeId, !reference.IsInverse);

            // 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)
            {
                NodeId targetId = (NodeId)reference.TargetId;

                if (IsNodeIdInNamespace(targetId))
                {
                    if (!PredefinedNodes.TryGetValue(targetId, out target))
                    {
                        target = 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;
            }

            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;
        }
Пример #37
0
        /// <summary>
        /// Initializes the form and creates a session with the server.
        /// </summary>
        public ClientForm()
        {
            InitializeComponent();

            ServerStatusTB.Text = "Unknown";
            PublishingStatusTB.Text = "Stopped";

            // The server certificate is stored locally in this example.
            // It can be retrieved automatically using the UA discovery endpoint.
            
            /*
            X509Certificate2 serverCertificate = SecurityUtils.Find(
                StoreName.My,
                StoreLocation.CurrentUser,
                "My Server Name");

            // The client object will create the WCF channel when a method is called.
            m_client = MyClient.Create("http://localhost:40000/UA/SampleServer", serverCertificate);
            // m_client = MyClient.Create("net.tcp://localhost:40001/UA/SampleServer", serverCertificate);
            // m_client = MyClient.Create("net.pipe://localhost/40000/UA/SampleServer", serverCertificate);
            */
            
            X509Certificate2 serverCertificate = SecurityUtils.Find(
                StoreName.My,
                StoreLocation.LocalMachine,
                "UA Sample Server");
             
            m_client = MyClient.Create("http://localhost:51211/UA/SampleServer", serverCertificate);
            
            // connecting the the full UA sample application will require that the UA sample application be placed in the
            // LocalMachine/TrustedPeople store. This can be done via the Certificate control panel which can be accessed by:
            //
            // 1) run mmc.exe
            // 2) select 'add snap-in'
            // 3) select 'add'
            // 4) select 'Certificates'
            // 5) select 'Computer Account'
            // 6) click next/ok.

            m_client.CreateSession();
            ServerStatusTB.Text = "Connected";

            TreeNode root = new TreeNode("Root");

            ReferenceDescription reference = new ReferenceDescription();

            reference.ReferenceTypeId = new NodeId(ReferenceTypes.Organizes);
            reference.IsForward = true;
            reference.NodeId = new ExpandedNodeId(Objects.RootFolder);
            reference.BrowseName = new QualifiedName("Root");
            reference.DisplayName = new LocalizedText("Root");
            reference.NodeClass = NodeClass.Object_1;
            reference.TypeDefinition = new ExpandedNodeId(ObjectTypes.FolderType);

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

            BrowseTV.Nodes.Add(root);
        }
Пример #38
0
        private void SelectChildrenMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_ItemsSelected == null || NodesTV.SelectedNode == null)
                {
                    return;
                }

                m_parent = GetParentOfSelected();
                m_references = new ReferenceDescriptionCollection();

                foreach (TreeNode child in NodesTV.SelectedNode.Nodes)
                {
                    ReferenceDescription reference = child.Tag as ReferenceDescription;

                    if (reference != null)
                    {
                        m_references.Add(reference);
                    }                    
                }

                if (m_references.Count > 0)
                {
                    m_ItemsSelected(this, new NodesSelectedEventArgs(m_parent.NodeId, m_references));
                }
            }
            catch (Exception exception)
            {
				GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
        /// <see cref="INodeManager.Browse" />
        public void Browse(
            OperationContext            context,
            ref ContinuationPoint       continuationPoint,
            IList<ReferenceDescription> references)
        {              
            if (context == null) throw new ArgumentNullException("context");
            if (continuationPoint == null) throw new ArgumentNullException("continuationPoint");
            if (references == null) throw new ArgumentNullException("references");
            
            // check for valid handle.
            ILocalNode source = continuationPoint.NodeToBrowse as ILocalNode;

            if (source == null)
            {
                throw new ServiceResultException(StatusCodes.BadNodeIdUnknown);
            }
            
            // check for view.
            if (!ViewDescription.IsDefault(continuationPoint.View))
            {
                throw new ServiceResultException(StatusCodes.BadViewIdUnknown);
            }

            lock (m_lock)
            {
                // construct list of references.
                uint maxResultsToReturn = continuationPoint.MaxResultsToReturn;

                // get previous enumerator.
                IEnumerator<IReference> enumerator = continuationPoint.Data as IEnumerator<IReference>;
            
                // fetch a snapshot all references for node.
                if (enumerator == null)
                {
                    List<IReference> copy = new List<IReference>(source.References);
                    enumerator = copy.GetEnumerator();
                    enumerator.MoveNext();
                }

                do
                {
                    IReference reference = enumerator.Current;

                    // silently ignore bad values.
                    if (reference == null || NodeId.IsNull(reference.ReferenceTypeId) || NodeId.IsNull(reference.TargetId))
                    {
                        continue;
                    }

                    // apply browse filters.
                    bool include = ApplyBrowseFilters(
                        reference,
                        continuationPoint.BrowseDirection,
                        continuationPoint.ReferenceTypeId,
                        continuationPoint.IncludeSubtypes);

                    if (include)
                    {                 
                        ReferenceDescription description = new ReferenceDescription();
                        
                        description.NodeId = reference.TargetId;
                        description.SetReferenceType(continuationPoint.ResultMask, reference.ReferenceTypeId, !reference.IsInverse);

                        // only fetch the metadata if it is requested.
                        if (continuationPoint.TargetAttributesRequired)
                        {                        
                            // get the metadata for the node.
                            NodeMetadata metadata = GetNodeMetadata(context, GetManagerHandle(reference.TargetId), continuationPoint.ResultMask);

                            // update description with local node metadata.
                            if (metadata != null)
                            {
                                description.SetTargetAttributes(
                                    continuationPoint.ResultMask,
                                    metadata.NodeClass,
                                    metadata.BrowseName,
                                    metadata.DisplayName,
                                    metadata.TypeDefinition);

                                // check node class mask.
                                if (!CheckNodeClassMask(continuationPoint.NodeClassMask, description.NodeClass))
                                {
                                    continue;
                                }
                            }

                            // any target that is not remote must be owned by another node manager.
                            else if (!reference.TargetId.IsAbsolute)
                            {
                                description.Unfiltered = true;
                            }
                        }

                        // add reference to list.
                        references.Add(description);

                        // construct continuation point if max results reached.
                        if (maxResultsToReturn > 0 && references.Count >= maxResultsToReturn)
                        { 
                            continuationPoint.Index = 0;
                            continuationPoint.Data  = enumerator;
                            enumerator.MoveNext();
                            return;
                        }
                    }
                }
                while (enumerator.MoveNext());
                
                // nothing more to browse if it exits from the loop normally.
                continuationPoint.Dispose();
                continuationPoint = null;
            }
        }
Пример #40
0
        /// <summary>
        /// Returns to display text for the target of a reference.
        /// </summary>
        public string GetTargetText(ReferenceDescription reference)
        {
            if (reference != null)
            {
                if (reference.DisplayName != null && !String.IsNullOrEmpty(reference.DisplayName.Text))
                {
                    return reference.DisplayName.Text;
                }

                if (reference.BrowseName != null)
                {
                    return reference.BrowseName.Name;
                }
            }

            return null;  
        }
Пример #41
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;
        }
Пример #42
0
        /// <summary>
        /// Browses the references for the specified node.
        /// </summary>
        public void Browse(
            BrowseDescription request,
            BrowseResult result,
            DiagnosticInfo diagnosticInfo)
        {
            lock (m_lock)
            {
                // find the starting nodes.
                Node source = m_nodes.Find(request.NodeId);

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

                result.References = new ListOfReferenceDescription();

                // return all of the references that meet the filter criteria.
                foreach (ReferenceNode reference in source.References)
                {
                    if (reference.IsInverse && request.BrowseDirection == BrowseDirection.Forward_0)
                    {
                        continue;
                    }

                    if (!reference.IsInverse && request.BrowseDirection == BrowseDirection.Inverse_1)
                    {
                        continue;
                    }

                    // the reference type filter can be an exact match or it can be for any subtype.
                    if (reference.ReferenceTypeId != request.ReferenceTypeId)
                    {
                        if (!request.IncludeSubtypes)
                        {
                            continue;
                        }

                        if (!IsTypeOf(reference.ReferenceTypeId, request.ReferenceTypeId))
                        {
                            continue;
                        }
                    }

                    // need to look up the target to find the attributes.
                    // note that the result filter mask is being ignored. production servers only need to 
                    // look up the attributes requested by the client.
                    Node target = m_nodes.Find(reference.TargetId);

                    if (target != null)
                    {
                        ReferenceDescription description = new ReferenceDescription();

                        description.NodeId = reference.TargetId;
                        description.IsForward = !reference.IsInverse;
                        description.ReferenceTypeId = reference.ReferenceTypeId;
                        description.BrowseName = target.BrowseName;
                        description.DisplayName = target.DisplayName;
                        description.NodeClass = target.NodeClass;
                        description.TypeDefinition = GetTypeDefinition(target);

                        result.References.Add(description);
                    }
                }
            }
        }
Пример #43
0
        /// <see cref="BaseTreeCtrl.SelectNode" />
        protected override void SelectNode()
        {
            base.SelectNode();
            
            // check if node is selected.
            if (NodesTV.SelectedNode == null)
            {
                return;
            }
            
            m_parent = GetParentOfSelected();

            ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;

            // update the attributes control.
            if (m_AttributesCtrl != null)
            {              
                if (reference != null)
                {
                    m_AttributesCtrl.Initialize(m_browser.Session, reference.NodeId);
                }
                else
                {
                    m_AttributesCtrl.Clear();
                }
            }
                        
            // check for single reference.
            if (reference != null)
            {
                m_references = new ReferenceDescription[] { reference };
                return;
            }
            
            // check if reference type folder is selected.
            NodeId referenceTypeId = NodesTV.SelectedNode.Tag as NodeId;

            if (referenceTypeId != null)
            {
                m_references = new ReferenceDescriptionCollection();

                foreach (TreeNode child in NodesTV.SelectedNode.Nodes)
                {                        
                    reference = child.Tag as ReferenceDescription;

                    if (reference != null)
                    {
                        m_references.Add(reference);
                    }
                }
            }      
        }
Пример #44
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();
            }
        }
Пример #45
0
        private TagViewModel AddTagInternal(ReferenceDescription tag, TagViewModel parentTagViewModel)
		{
			var tagViewModel = new TagViewModel(tag);
            if (parentTagViewModel != null)
                tagViewModel.Path = parentTagViewModel.Path + "/" + tagViewModel.Address;
            if (Subscription.MonitoredItems.Any(x => x.NodeId.ToString() == tagViewModel.Address))
            {
                tagViewModel.IsTagUsed = true;
                tagViewModel.IsExpanded = true;
                tagViewModel.ExpandToThis();
            }
            /*tagViewModel.Path = parentTagViewModel == null
                ? tagViewModel.Tag.DisplayName.ToString()
                : parentTagViewModel.Path + tagViewModel.Tag.DisplayName.ToString();*/
            if (parentTagViewModel != null)
				parentTagViewModel.AddChild(tagViewModel);

            if (tag != null)
                foreach (var childTag in Session.Browse(new NodeId(tag.NodeId), null))
                    AddTagInternal(childTag, tagViewModel);
            else
                foreach (var childTag in Session.Browse(null, null))
                    AddTagInternal(childTag, tagViewModel);
            return tagViewModel;
		}
Пример #46
0
        /// <summary>
        /// Starts monitoring the value of the currently selected item.
        /// </summary>
        public void CreateMonitoredItem(ReferenceDescription node)
        {
            ListOfMonitoredItemCreateRequest itemsToCreate = new ListOfMonitoredItemCreateRequest();

            MonitoredItemCreateRequest itemToCreate = new MonitoredItemCreateRequest();

            itemToCreate.ItemToMonitor = new ReadValueId();
            itemToCreate.ItemToMonitor.NodeId = new NodeId(node.NodeId);
            itemToCreate.ItemToMonitor.AttributeId = Attributes.Value;
            itemToCreate.MonitoringMode = MonitoringMode.Reporting_2;
            itemToCreate.RequestedParameters = new MonitoringParameters();
            itemToCreate.RequestedParameters.ClientHandle = ++m_monitoredItemCount;
            itemToCreate.RequestedParameters.SamplingInterval = 1000;
            itemToCreate.RequestedParameters.QueueSize = 0;
            itemToCreate.RequestedParameters.DiscardOldest = true;
            itemToCreate.RequestedParameters.Filter = new ExtensionObject();

            itemsToCreate.Add(itemToCreate);

            ListOfMonitoredItemCreateResult results;
            ListOfDiagnosticInfo diagnosticInfos;

            m_client.CreateMonitoredItems(
                m_client.CreateRequestHeader(),
                m_subscriptionId,
                TimestampsToReturn.Both_2,
                itemsToCreate,
                out results,
                out diagnosticInfos);

            if (results != null)
            {
                // update the list view.
                MonitoredItemCreateResult result = results[0];

                ListViewItem item = new ListViewItem(itemToCreate.RequestedParameters.ClientHandle.ToString());

                item.SubItems.Add(new ListViewItem.ListViewSubItem());
                item.SubItems[1].Text = node.DisplayName.Text;

                item.SubItems.Add(new ListViewItem.ListViewSubItem());
                item.SubItems[2].Text = "<Unknown>";

                item.SubItems.Add(new ListViewItem.ListViewSubItem());
                item.SubItems[3].Text = String.Format("{0}", result.StatusCode);

                item.SubItems.Add(new ListViewItem.ListViewSubItem());
                item.SubItems[4].Text = String.Format("{0:HH:mm:ss}", DateTime.Now);

                UpdatesLV.Items.Add(item);

                // save the monitored item.
                MonitoredItem monitoredItem = new MonitoredItem();

                monitoredItem.MonitoredItemId = result.MonitoredItemId;
                monitoredItem.ItemToMonitor = itemToCreate.ItemToMonitor;
                monitoredItem.MonitoringMode = itemToCreate.MonitoringMode;
                monitoredItem.Parameters = itemToCreate.RequestedParameters;

                monitoredItem.Parameters.SamplingInterval = result.RevisedSamplingInterval;
                monitoredItem.Parameters.QueueSize = result.RevisedQueueSize;

                m_monitoredItems.Add(itemToCreate.RequestedParameters.ClientHandle, monitoredItem);

                item.Tag = monitoredItem;
            }
        }
        /// <summary>
        /// Returns a display name for the target of a reference.
        /// </summary>
        public string GetDisplayText(ReferenceDescription reference)
        {
            if (reference == null || NodeId.IsNull(reference.NodeId))
            {
                return String.Empty;
            }

            INode node = Find(reference.NodeId);

            if (node != null)
            {
                return GetDisplayText(node);
            }

            return reference.ToString();
        }
Пример #48
0
        /// <summary>
        /// Sets the nodes in the control.
        /// </summary>
        public void Update(Session session, ReferenceDescription reference)
        {
            if (session == null) throw new ArgumentNullException("session");
            
            Clear();

            if (reference == null)
            {
                return;                
            }
            
            m_session = session;

            AddProperties(reference.NodeId);

            AdjustColumns();
        }
Пример #49
0
        /// <summary>
        /// Adds a value to the control.
        /// </summary>
        public void AddValueId(ReferenceDescription reference)
        {
            Node node = m_session.NodeCache.Find(reference.NodeId) as Node;

            if (node == null)
            {
                return;
            }

            ReadValueId valueId = new ReadValueId();

            valueId.NodeId       = node.NodeId;
            valueId.AttributeId  = Attributes.Value;
            valueId.IndexRange   = null;
            valueId.DataEncoding = null;

            // read the display name for non-variables.
            if ((node.NodeClass & (NodeClass.Variable | NodeClass.VariableType)) == 0)
            {
                valueId.AttributeId  = Attributes.DisplayName;
            }

            AddItem(valueId);
            AdjustColumns();
        }
Пример #50
0
 private void NodeIdentifierTB_TextChanged(object sender, EventArgs e)
 {
     m_reference = null;
     OkBTN.Enabled = false;
 }
        /// <summary>
        /// Loads the dictionary idetified by the node id.
        /// </summary>
        public async Task Load(ReferenceDescription dictionary)
        {
            if (dictionary == null) throw new ArgumentNullException("dictionary");

            NodeId dictionaryId = ExpandedNodeId.ToNodeId(dictionary.NodeId, m_session.NamespaceUris);

            GetTypeSystem(dictionaryId);

            byte[] schema = ReadDictionary(dictionaryId);

            if (schema == null || schema.Length == 0)
            {
                throw ServiceResultException.Create(StatusCodes.BadUnexpectedError, "Cannot parse empty data dictionary.");
            }

            await Validate(schema);

            ReadDataTypes(dictionaryId);

            m_dictionaryId = dictionaryId;
            m_name = dictionary.ToString();
        }
Пример #52
0
        /// <summary>
        /// Updates the reference description with the node attributes.
        /// </summary>
        private bool UpdateReferenceDescription(
            OperationContext     context,
            NodeId               targetId,
            NodeClass            nodeClassMask,
            BrowseResultMask     resultMask,
            ReferenceDescription description)
        {
            if (targetId == null)    throw new ArgumentNullException("targetId");
            if (description == null) throw new ArgumentNullException("description");
                        
            // find node manager that owns the node.
            INodeManager nodeManager = null;                
            object handle = GetManagerHandle(targetId, out nodeManager);

            // dangling reference - nothing more to do.
            if (handle == null)
            {
                return false;
            }

            // fetch the node attributes.
            NodeMetadata metadata = nodeManager.GetNodeMetadata(context, handle, resultMask);

            if (metadata == null)
            {
                return false;
            }

            // check nodeclass filter.
            if (nodeClassMask != NodeClass.Unspecified && (metadata.NodeClass & nodeClassMask) == 0)
            {
                return false;
            }

            // update attributes.
            description.NodeId = metadata.NodeId;
            
            description.SetTargetAttributes(
                resultMask,
                metadata.NodeClass,
                metadata.BrowseName,
                metadata.DisplayName,
                metadata.TypeDefinition);

            description.Unfiltered = false;

            return true;
        }        
Пример #53
0
 /// <summary>
 /// Adds a node to the list.
 /// </summary>
 public void AddNodeId(ReferenceDescription reference)
 {
     if (reference != null)
     {
         AddNodeId(reference.NodeId);
         AdjustColumns();
     }
 }
Пример #54
0
        /// <summary>
        /// Verifies the isforward flag.
        /// </summary>
        private bool VerifyIsForward(Node node, BrowseDescription description, ReferenceDescription reference)
        {      
            // check if field was not requested.
            if ((description.ResultMask & (uint)BrowseResultMask.IsForward) == 0)
            {
                if (reference.IsForward)
                {
                    Log("Returned unexpected IsForward=True when Browsing Node '{0}'. NodeId = {1}", node, node.NodeId);
                    return false;
                }

                return true;
            }

            if (reference.IsForward)
            {
                if (description.BrowseDirection == BrowseDirection.Inverse)
                {
                    Log("Returned unexpected IsForward=False when Browsing Node '{0}'. NodeId = {1}", node, node.NodeId);
                    return false;
                }
            }
            else
            {
                if (description.BrowseDirection == BrowseDirection.Forward)
                {
                    Log("Returned unexpected IsForward=True when Browsing Node '{0}'. NodeId = {1}", node, node.NodeId);
                    return false;
                }
            }
                
            return true;
        }
Пример #55
0
 /// <summary>
 /// Returns to display icon for the target of a reference.
 /// </summary>
 public static string GetTargetIcon(Session session, ReferenceDescription reference)
 {
     return GetTargetIcon(session, reference.NodeClass, reference.TypeDefinition);
 }
Пример #56
0
        /// <summary>
        /// Returns the available encodings for a node
        /// </summary>
        /// <param name="variableId">The variable node.</param>
        /// <returns></returns>
        public ReferenceDescriptionCollection ReadAvailableEncodings(NodeId variableId)
        {
            VariableNode variable = NodeCache.Find(variableId) as VariableNode;

            if (variable == null)
            {
                throw ServiceResultException.Create(StatusCodes.BadNodeIdInvalid, "NodeId does not refer to a valid variable node.");
            }

            // no encodings available if there was a problem reading the data type for the node.
            if (NodeId.IsNull(variable.DataType))
            {
                return new ReferenceDescriptionCollection();
            }

            // no encodings for non-structures.
            if (!TypeTree.IsTypeOf(variable.DataType, DataTypes.Structure))
            {
                return new ReferenceDescriptionCollection();
            }

            // look for cached values.
            IList<INode> encodings = NodeCache.Find(variableId, ReferenceTypeIds.HasEncoding, false, true);

            if (encodings.Count > 0)
            {
                ReferenceDescriptionCollection references = new ReferenceDescriptionCollection();

                foreach (INode encoding in encodings)
                {
                    ReferenceDescription reference = new ReferenceDescription();

                    reference.ReferenceTypeId = ReferenceTypeIds.HasEncoding;
                    reference.IsForward       = true;
                    reference.NodeId          = encoding.NodeId;
                    reference.NodeClass       = encoding.NodeClass;
                    reference.BrowseName      = encoding.BrowseName;
                    reference.DisplayName     = encoding.DisplayName;
                    reference.TypeDefinition  = encoding.TypeDefinitionId;
                
                    references.Add(reference);
                }

                return references;
            }

            Browser browser = new Browser(this);
                        
            browser.BrowseDirection = BrowseDirection.Forward;
            browser.ReferenceTypeId = ReferenceTypeIds.HasEncoding;
            browser.IncludeSubtypes = false;
            browser.NodeClassMask   = 0;
                        
            return browser.Browse(variable.DataType);
        }
Пример #57
0
        /// <summary>
        /// Displays the a root in the control.
        /// </summary>
        public void Initialize(
            Session session, 
            NodeId rootId, 
            NodeId viewId,
            NodeId referenceTypeId, 
            BrowseDirection browseDirection)
        {
            m_session = session;
            m_rootId = rootId;
            m_viewId = viewId;
            m_referenceTypeId = referenceTypeId;
            m_browseDirection = browseDirection;

            NodesTV.Nodes.Clear();

            if (m_session == null)
            {
                return;
            }

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

            if (NodeId.IsNull(m_referenceTypeId))
            {
                m_referenceTypeId = ReferenceTypeIds.HierarchicalReferences;
            }

            ReferenceTypeCTRL.Initialize(m_session, ReferenceTypeIds.HierarchicalReferences);
            ReferenceTypeCTRL.SelectedTypeId = m_referenceTypeId;

            ILocalNode root = m_session.NodeCache.Find(m_rootId) as ILocalNode;

            if (root == null)
            {
                return;
            }
            
            ReferenceDescription reference = new ReferenceDescription();

            reference.ReferenceTypeId = referenceTypeId;
            reference.IsForward = true;
            reference.NodeId = root.NodeId;
            reference.NodeClass = root.NodeClass;
            reference.BrowseName = root.BrowseName;
            reference.DisplayName = root.DisplayName;
            reference.TypeDefinition = root.TypeDefinitionId;

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

            rootNode.ImageKey = rootNode.SelectedImageKey = GuiUtils.GetTargetIcon(session, reference);
            rootNode.Tag = reference;
            rootNode.Nodes.Add(new TreeNode());
            
            NodesTV.Nodes.Add(rootNode);
        }
Пример #58
0
 private void NamespaceUriCB_TextChanged(object sender, EventArgs e)
 {
     m_reference = null;
     OkBTN.Enabled = false;
 }
Пример #59
0
        /// <summary>
        /// Adds a item to a subscription.
        /// </summary>
        private void Subscribe(Subscription subscription, ReferenceDescription reference)
        {    
            MonitoredItem monitoredItem = new MonitoredItem(subscription.DefaultItem);

            monitoredItem.DisplayName      = subscription.Session.NodeCache.GetDisplayText(reference);
            monitoredItem.StartNodeId      = (NodeId)reference.NodeId;
            monitoredItem.NodeClass        = (NodeClass)reference.NodeClass;
            monitoredItem.AttributeId      = Attributes.Value;
            monitoredItem.SamplingInterval = 0;
            monitoredItem.QueueSize        = 1;

            // add condition fields to any event filter.
            EventFilter filter = monitoredItem.Filter as EventFilter;

            if (filter != null)
            {
                monitoredItem.AttributeId = Attributes.EventNotifier;
				monitoredItem.QueueSize = 0;
            }
            
            subscription.AddItem(monitoredItem);
            subscription.ApplyChanges();
        }
Пример #60
0
        /// <summary>
        /// Adds a node as an attribute to the EventCategories list
        /// </summary>
        /// <param name="EventTypeNodeId">The event type node</param>
        /// <param name="AttrRef">The reference node being added as an attribute</param>
        private void ProcessNodeAsAttribute(NodeId EventTypeNodeId, ReferenceDescription AttrRef)
        {
            try
            {
                EventAttribute attr = new EventAttribute();
                DataValue value = new DataValue();

                attr.AttributeID = m_attrID++;
                attr.strNodeId = AttrRef.NodeId.ToString();
                attr.BrowseName = AttrRef.BrowseName.Name;
                attr.BrowseNameNSIndex = AttrRef.BrowseName.NamespaceIndex;
                attr.AttrDesc = AttrRef.DisplayName.Text;

                Node node = m_session.ReadNode((NodeId)AttrRef.NodeId);
                node.Read(null, Attributes.DataType, value);
                NodeId typenode = (NodeId)value.Value;
                attr.strDataTypeNodeId = typenode.ToString();
                attr.ActualDataType = DataTypes.GetSystemType(typenode, EncodeableFactory.GlobalFactory);
                attr.strEventNodeId = EventTypeNodeId.ToString();

                node.Read(null, Attributes.ValueRank, value);
                //TODO: Used to be ArraySize. Does ValueRank have the same definition?
                if ((int)value.Value >= 0) //TODO: is there a constant that can be used
                    attr.IsArray = true;
                else
                    attr.IsArray = false;

                m_EventAttributes.Add(attr);
            }
            catch (Exception e)
            {
                Utils.Trace(e, "Unexpected error in ProcessNodesAsAttribute");
            }
        }