예제 #1
0
        private void SelectChildrenMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_ItemsSelected == null || NodesTV.SelectedItem == null)
                {
                    return;
                }

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

                foreach (TreeItemViewModel child in NodesTV.SelectedItem.Children)
                {
                    ReferenceDescription reference = child.Item 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(String.Empty, GuiUtils.CallerName(), exception);
            }
        }
예제 #2
0
        private void SelectMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_nodesSelected != null)
                {
                    if (NodesTV.SelectedNode == null)
                    {
                        return;
                    }

                    ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;

                    if (reference != null)
                    {
                        ReferenceDescriptionCollection collection = new ReferenceDescriptionCollection();
                        collection.Add(reference);
                        m_nodesSelected(this, new NodesSelectedEventArgs(collection));
                    }
                }
            }
            catch (Exception exception)
            {
                GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
예제 #3
0
        // Get all nodes excluding Server Node in the references Collection
        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);

            if (references != null)
            {
                for (int ii = 0; ii < references.Count; ii++)
                {
                    // do not add Server node
                    if (!references[ii].BrowseName.Name.Equals("Server"))
                    {
                        tanksRef.Add(references[ii]);
                    }
                }
            }
        }
예제 #4
0
 public static ReferenceDescriptionCollection Browse(Session session, BrowseDescription nodeToBrowse, bool throwOnError)
 {
     try
       {
     var descriptionCollection = new ReferenceDescriptionCollection();
     var nodesToBrowse = new BrowseDescriptionCollection { nodeToBrowse };
     BrowseResultCollection results;
     DiagnosticInfoCollection diagnosticInfos;
     session.Browse(null, null, 0U, nodesToBrowse, out results, out diagnosticInfos);
     ClientBase.ValidateResponse(results, nodesToBrowse);
     ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse);
     while (!StatusCode.IsBad(results[0].StatusCode))
     {
       for (var index = 0; index < results[0].References.Count; ++index)
     descriptionCollection.Add(results[0].References[index]);
       if (results[0].References.Count == 0 || results[0].ContinuationPoint == null)
     return descriptionCollection;
       var continuationPoints = new ByteStringCollection();
       continuationPoints.Add(results[0].ContinuationPoint);
       session.BrowseNext(null, false, continuationPoints, out results, out diagnosticInfos);
       ClientBase.ValidateResponse(results, continuationPoints);
       ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints);
     }
     throw new ServiceResultException(results[0].StatusCode);
       }
       catch (Exception ex)
       {
     if (throwOnError)
       throw new ServiceResultException(ex, 2147549184U);
     return null;
       }
 }
예제 #5
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);
            }
        }
예제 #6
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);
                    }
                }
            }
        }
예제 #7
0
        /// <summary>
        /// Browses the address space and returns all of the supertypes of the specified type node.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="typeId">The NodeId for a type node in the address space.</param>
        /// <param name="throwOnError">if set to <c>true</c> a exception will be thrown on an error.</param>
        /// <returns>
        /// The references found. Null if an error occurred.
        /// </returns>
        public static ReferenceDescriptionCollection BrowseSuperTypes(Session session, NodeId typeId, bool throwOnError)
        {
            var supertypes = new ReferenceDescriptionCollection();

            try
            {
                // find all of the children of the field.
                var nodeToBrowse = new BrowseDescription
                {
                    NodeId          = typeId,
                    BrowseDirection = BrowseDirection.Inverse,
                    ReferenceTypeId = ReferenceTypeIds.HasSubtype,
                    IncludeSubtypes = false,
                    NodeClassMask   = 0,
                    ResultMask      = (uint)BrowseResultMask.All
                };

                var references = Browse(session, nodeToBrowse, throwOnError);

                while (references != null && references.Count > 0)
                {
                    // should never be more than one supertype.
                    supertypes.Add(references[0]);

                    // only follow references within this server.
                    if (references[0].NodeId.IsAbsolute)
                    {
                        break;
                    }

                    // get the references for the next level up.
                    nodeToBrowse.NodeId = (NodeId)references[0].NodeId;
                    references          = Browse(session, nodeToBrowse, throwOnError);
                }

                // return complete list.
                return(supertypes);
            }
            catch (Exception exception)
            {
                if (throwOnError)
                {
                    throw new ServiceResultException(exception, StatusCodes.BadUnexpectedError);
                }

                return(null);
            }
        }
예제 #8
0
        /// <see cref="BaseListCtrl.GetDataToDrag" />
        protected override object GetDataToDrag()
        {
            ReferenceDescriptionCollection references = new ReferenceDescriptionCollection();

            foreach (ListViewItem listItem in ItemsLV.SelectedItems)
            {
                PropertyItem property = listItem.Tag as PropertyItem;

                if (property != null)
                {
                    references.Add(property.Reference);
                }
            }

            return(references);
        }
예제 #9
0
        private ReferenceDescriptionCollection FetchObjectReferences(ExpandedNodeId expandedNodeId)
        {
            try
            {
                NodeId id;
                if (expandedNodeId == null)
                {
                    id = Objects.ObjectsFolder;
                }
                else
                {
                    id = client.ToNodeId(expandedNodeId);
                }

                uint mask;

                mask = (uint)(NodeClass.Object);
                var objRefs = new ReferenceDescriptionCollection();
                client.Browse(id, mask, out objRefs);

                mask = (uint)(NodeClass.Variable);
                var varRefs = new ReferenceDescriptionCollection();
                client.Browse(id, mask, out varRefs);

                foreach (var varRef in varRefs)
                {
                    objRefs.Add(varRef);
                }

                return(objRefs);
            }
            catch (Exception ex)
            {
                this.EventAggregator
                .GetEvent <Events.ErrorNotificationEvent>()
                .Publish(new Events.ErrorNotification(ex));

                return(null);
            }
        }
예제 #10
0
        public ReferenceDescriptionCollection GetServerTagList()
        {
            ReferenceDescriptionCollection result = new ReferenceDescriptionCollection();

            try
            {
                ReferenceDescriptionCollection referenceDescriptions           = session.FetchReferences(ObjectIds.ObjectsFolder);
                ReferenceDescriptionCollection additionalReferenceDescriptions = new ReferenceDescriptionCollection();
                result.AddRange(referenceDescriptions);
                for (var i = 0; i < referenceDescriptions.Count; i++)
                {
                    try
                    {
                        var refDef = FetchReferences(ExpandedNodeId.ToNodeId(referenceDescriptions[i].NodeId, session.NamespaceUris));
                        foreach (var r in refDef)
                        {
                            var item = referenceDescriptions.FirstOrDefault(x => x.NodeId == r.NodeId);
                            if (item == null)
                            {
                                referenceDescriptions.Add(r);
                            }
                            additionalReferenceDescriptions.Add(r);
                        }
                    }catch (Exception ex)
                    {
                        var e = new Exception($"{i}: {referenceDescriptions[i].NodeId}", ex);
                        e.Data.Add($"{i}", referenceDescriptions[i]);
                        throw e;
                    }
                    //Recurse(rd, result);
                }
            }
            catch (Exception ex)
            {
            }

            return(result);
        }
예제 #11
0
        /// <summary>
        /// Browses the address space and returns the references found.
        /// </summary>
        public static ReferenceDescriptionCollection Browse(Session session, ViewDescription view, BrowseDescription nodeToBrowse, bool throwOnError)
        {
            try
            {
                ReferenceDescriptionCollection references = new ReferenceDescriptionCollection();

                // construct browse request.
                BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection();
                nodesToBrowse.Add(nodeToBrowse);

                // start the browse operation.
                BrowseResultCollection   results         = null;
                DiagnosticInfoCollection diagnosticInfos = null;

                session.Browse(
                    null,
                    view,
                    0,
                    nodesToBrowse,
                    out results,
                    out diagnosticInfos);

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

                do
                {
                    // check for error.
                    if (StatusCode.IsBad(results[0].StatusCode))
                    {
                        throw new ServiceResultException(results[0].StatusCode);
                    }

                    // process results.
                    for (int ii = 0; ii < results[0].References.Count; ii++)
                    {
                        references.Add(results[0].References[ii]);
                    }

                    // check if all references have been fetched.
                    if (results[0].References.Count == 0 || results[0].ContinuationPoint == null)
                    {
                        break;
                    }

                    // continue browse operation.
                    ByteStringCollection continuationPoints = new ByteStringCollection();
                    continuationPoints.Add(results[0].ContinuationPoint);

                    session.BrowseNext(
                        null,
                        false,
                        continuationPoints,
                        out results,
                        out diagnosticInfos);

                    ClientBase.ValidateResponse(results, continuationPoints);
                    ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints);
                }while (true);

                //return complete list.
                return(references);
            }
            catch (Exception exception)
            {
                if (throwOnError)
                {
                    throw new ServiceResultException(exception, StatusCodes.BadUnexpectedError);
                }

                return(null);
            }
        }
예제 #12
0
        private void MonitorMethodUpdateNotification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
        {
            try
            {
                if (!(e.NotificationValue is EventFieldList notification))
                {
                    return;
                }
                NodeId eventTypeId = null;
                if (!(monitoredItem.Status.Filter is EventFilter filter))
                {
                    return;
                }
                for (int index = 0; index < filter.SelectClauses.Count; index++)
                {
                    SimpleAttributeOperand simpleAttributeOperand = filter.SelectClauses[index];
                    if (simpleAttributeOperand.BrowsePath.Count != 1 ||
                        simpleAttributeOperand.BrowsePath[0] != BrowseNames.EventType)
                    {
                        continue;
                    }
                    eventTypeId = notification.EventFields[index].Value as NodeId;
                }

                // look up the known event type.
                Dictionary <NodeId, NodeId> eventTypeMappings = new Dictionary <NodeId, NodeId>();
                if (eventTypeId == null || NodeId.IsNull(eventTypeId))
                {
                    return;
                }
                if (!eventTypeMappings.TryGetValue(eventTypeId, out NodeId knownTypeId))
                {
                    // check for a known type
                    if (KnownEventTypes.Any(nodeId => nodeId == eventTypeId))
                    {
                        knownTypeId = eventTypeId;
                        eventTypeMappings.Add(eventTypeId, eventTypeId);
                    }

                    // browse for the supertypes of the event type.
                    if (knownTypeId == null)
                    {
                        ReferenceDescriptionCollection supertypes = new ReferenceDescriptionCollection();
                        // find all of the children of the field.
                        BrowseDescription nodeToBrowse = new BrowseDescription
                        {
                            NodeId          = eventTypeId,
                            BrowseDirection = BrowseDirection.Inverse,
                            ReferenceTypeId = ReferenceTypeIds.HasSubtype,
                            IncludeSubtypes = false, // more efficient to use IncludeSubtypes=False when possible.
                            NodeClassMask   = 0,     // the HasSubtype reference already restricts the targets to Types.
                            ResultMask      = (uint)BrowseResultMask.All
                        };

                        ReferenceDescriptionCollection
                            references = _applicationInstanceManager.Browse(nodeToBrowse);
                        while (references != null && references.Count > 0)
                        {
                            // should never be more than one supertype.
                            supertypes.Add(references[0]);
                            // only follow references within this server.
                            if (references[0].NodeId.IsAbsolute)
                            {
                                break;
                            }

                            // get the references for the next level up.
                            nodeToBrowse.NodeId = (NodeId)references[0].NodeId;
                            references          = _applicationInstanceManager.Browse(nodeToBrowse);
                        }

                        // find the first super type that matches a known event type.
                        foreach (ReferenceDescription referenceDescription in supertypes)
                        {
                            foreach (NodeId nodeId in KnownEventTypes)
                            {
                                if (nodeId != referenceDescription.NodeId)
                                {
                                    continue;
                                }
                                knownTypeId = nodeId;
                                eventTypeMappings.Add(eventTypeId, knownTypeId);
                                break;
                            }

                            if (knownTypeId != null)
                            {
                                break;
                            }
                        }
                    }
                }

                if (knownTypeId == null)
                {
                    return;
                }
                // all of the known event types have a UInt32 as identifier.
                uint?id = knownTypeId.Identifier as uint?;
                if (id == null)
                {
                    return;
                }
                // construct the event based on the known event type.
                BaseEventState baseEventState = null;

                switch (id.Value)
                {
                case ObjectTypes.ConditionType:
                {
                    baseEventState = new ConditionState(null);
                    break;
                }

                case ObjectTypes.DialogConditionType:
                {
                    baseEventState = new DialogConditionState(null);
                    break;
                }

                case ObjectTypes.AlarmConditionType:
                {
                    baseEventState = new AlarmConditionState(null);
                    break;
                }

                case ObjectTypes.ExclusiveLimitAlarmType:
                {
                    baseEventState = new ExclusiveLimitAlarmState(null);
                    break;
                }

                case ObjectTypes.NonExclusiveLimitAlarmType:
                {
                    baseEventState = new NonExclusiveLimitAlarmState(null);
                    break;
                }

                case ObjectTypes.AuditEventType:
                {
                    baseEventState = new AuditEventState(null);
                    break;
                }

                case ObjectTypes.AuditUpdateMethodEventType:
                {
                    baseEventState = new AuditUpdateMethodEventState(null);
                    break;
                }

                default:
                {
                    baseEventState = new BaseEventState(null);
                    break;
                }
                }

                // get the filter which defines the contents of the notification.
                filter = monitoredItem.Status.Filter as EventFilter;
                // initialize the event with the values in the notification.
                baseEventState.Update(_applicationInstanceManager.Session.SystemContext, filter.SelectClauses,
                                      notification);
                // save the original notification.
                baseEventState.Handle = notification;
                // construct the audit object.
                if (baseEventState is AuditUpdateMethodEventState audit)
                {
                    // look up the condition type metadata in the local cache.
                    string sourceName = "";
                    if (audit.SourceName.Value != null)
                    {
                        sourceName = Utils.Format("{0}", audit.SourceName.Value);
                    }
                    string type = "";
                    if (audit.TypeDefinitionId != null)
                    {
                        type = Utils.Format("{0}",
                                            _applicationInstanceManager.Session.NodeCache.Find(audit.TypeDefinitionId));
                    }

                    string method = "";
                    if (audit.MethodId != null)
                    {
                        method = Utils.Format("{0}",
                                              _applicationInstanceManager.Session.NodeCache.Find(
                                                  BaseVariableState.GetValue(audit.MethodId)));
                    }

                    string status = "";
                    if (audit.Status != null)
                    {
                        status = Utils.Format("{0}", audit.Status.Value);
                    }

                    string time = "";
                    if (audit.Time != null)
                    {
                        time = Utils.Format("{0:HH:mm:ss.fff}", audit.Time.Value.ToLocalTime());
                    }

                    string message = "";
                    if (audit.Message != null)
                    {
                        message = Utils.Format("{0}", audit.Message.Value);
                    }

                    string inputArguments = "";
                    if (audit.InputArguments != null)
                    {
                        inputArguments = Utils.Format("{0}", new Variant(audit.InputArguments.Value));
                    }


                    InformationDisplay(
                        $"sourceName: {sourceName}, type:{type}, method:{method}, status:{status}, time:{time}, message:{message}, inputArguments:{inputArguments}");
                }
            }
            catch (Exception ex)
            {
                InformationDisplay($"Monitored Item Notification exception: {ex.StackTrace}");
            }
        }
        /// <summary>
        /// Browses the address space and returns all of the supertypes of the specified type node.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <param name="typeId">The NodeId for a type node in the address space.</param>
        /// <param name="throwOnError">if set to <c>true</c> a exception will be thrown on an error.</param>
        /// <returns>
        /// The references found. Null if an error occurred.
        /// </returns>
        public static ReferenceDescriptionCollection BrowseSuperTypes(Session session, NodeId typeId, bool throwOnError)
        {
            ReferenceDescriptionCollection supertypes = new ReferenceDescriptionCollection();

            try
            {
                // find all of the children of the field.
                BrowseDescription nodeToBrowse = new BrowseDescription();

                nodeToBrowse.NodeId = typeId;
                nodeToBrowse.BrowseDirection = BrowseDirection.Inverse;
                nodeToBrowse.ReferenceTypeId = ReferenceTypeIds.HasSubtype;
                nodeToBrowse.IncludeSubtypes = false; // more efficient to use IncludeSubtypes=False when possible.
                nodeToBrowse.NodeClassMask = 0; // the HasSubtype reference already restricts the targets to Types. 
                nodeToBrowse.ResultMask = (uint)BrowseResultMask.All;

                ReferenceDescriptionCollection references = Browse(session, nodeToBrowse, throwOnError);

                while (references != null && references.Count > 0)
                {
                    // should never be more than one supertype.
                    supertypes.Add(references[0]);

                    // only follow references within this server.
                    if (references[0].NodeId.IsAbsolute)
                    {
                        break;
                    }

                    // get the references for the next level up.
                    nodeToBrowse.NodeId = (NodeId)references[0].NodeId;
                    references = Browse(session, nodeToBrowse, throwOnError);
                }

                // return complete list.
                return supertypes;
            }
            catch (Exception exception)
            {
                if (throwOnError)
                {
                    throw new ServiceResultException(exception, StatusCodes.BadUnexpectedError);
                }

                return null;
            }
        }
예제 #14
0
        /// <see cref="BaseListCtrl.GetDataToDrag" />
        protected override object GetDataToDrag()
        {
            ReferenceDescriptionCollection references = new ReferenceDescriptionCollection();

            foreach (ListViewItem listItem in ItemsLV.SelectedItems)
            {
                PropertyItem property = listItem.Tag as PropertyItem;

                if (property != null)
                {
                    references.Add(property.Reference);
                }
            }

            return references;
        }
예제 #15
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);
        }
        /// <summary>
        /// Browses the address space and returns the references found.
        /// </summary>
        public static ReferenceDescriptionCollection Browse(Session session, ViewDescription view, BrowseDescription nodeToBrowse, bool throwOnError)
        {
            try
            {
                ReferenceDescriptionCollection references = new ReferenceDescriptionCollection();

                // construct browse request.
                BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection();
                nodesToBrowse.Add(nodeToBrowse);

                // start the browse operation.
                BrowseResultCollection results = null;
                DiagnosticInfoCollection diagnosticInfos = null;

                session.Browse(
                    null,
                    view,
                    0,
                    nodesToBrowse,
                    out results,
                    out diagnosticInfos);

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

                do
                {
                    // check for error.
                    if (StatusCode.IsBad(results[0].StatusCode))
                    {
                        throw new ServiceResultException(results[0].StatusCode);
                    }

                    // process results.
                    for (int ii = 0; ii < results[0].References.Count; ii++)
                    {
                        references.Add(results[0].References[ii]);
                    }

                    // check if all references have been fetched.
                    if (results[0].References.Count == 0 || results[0].ContinuationPoint == null)
                    {
                        break;
                    }

                    // continue browse operation.
                    ByteStringCollection continuationPoints = new ByteStringCollection();
                    continuationPoints.Add(results[0].ContinuationPoint);

                    session.BrowseNext(
                        null,
                        false,
                        continuationPoints,
                        out results,
                        out diagnosticInfos);

                    ClientBase.ValidateResponse(results, continuationPoints);
                    ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints);
                }
                while (true);

                //return complete list.
                return references;
            }
            catch (Exception exception)
            {
                if (throwOnError)
                {
                    throw new ServiceResultException(exception, StatusCodes.BadUnexpectedError);
                }

                return null;
            }
        }
예제 #17
0
        private void GetIDsAtConstruction()
        {
            ReferenceDescriptionCollection refDescCol      = new ReferenceDescriptionCollection();
            ReferenceDescriptionCollection foundRefDescCol = new ReferenceDescriptionCollection();

            refDescCol = myHelperApi.BrowseRoot();

            foreach (ReferenceDescription refDescA in refDescCol)
            {
                if (refDescA.BrowseName.Name == "Objects")
                {
                    refDescCol = myHelperApi.BrowseNode(refDescA);
                    foreach (ReferenceDescription refDescB in refDescCol)
                    {
                        if (refDescB.BrowseName.Name == "DeviceSet")
                        {
                            refDescCol = myHelperApi.BrowseNode(refDescB);
                            foreach (ReferenceDescription refDescC in refDescCol)
                            {
                                if (refDescC.TypeDefinition == new ExpandedNodeId(AutoID.ObjectTypes.RfidReaderDeviceType, (ushort)myHelperApi.GetNamespaceIndex(AutoID.Namespaces.AutoID)))
                                {
                                    foundRefDescCol.Add(refDescC);
                                }
                            }
                        }
                    }
                }
            }

            MethodIds methodIds;

            for (int i = 0; i < foundRefDescCol.Count; i++)
            {
                refDescCol = myHelperApi.BrowseNode(foundRefDescCol[i]);

                foreach (ReferenceDescription refDescD in refDescCol)
                {
                    if (refDescD.BrowseName.Name == "Scan")
                    {
                        objectIdentifier       = (uint)foundRefDescCol[i].NodeId.Identifier;
                        methodIdentifier       = (uint)refDescD.NodeId.Identifier;
                        methodIds.method       = MethodToCall.Scan;
                        methodIds.readpoint    = i;
                        methodIds.methodNodeId = methodIdentifier;
                        methodIds.objectNodeId = objectIdentifier;
                        methodIdList[i].Add(methodIds);
                    }
                    else if (refDescD.BrowseName.Name == "ScanStart")
                    {
                        objectIdentifier       = (uint)foundRefDescCol[i].NodeId.Identifier;
                        methodIdentifier       = (uint)refDescD.NodeId.Identifier;
                        methodIds.method       = MethodToCall.ScanStart;
                        methodIds.readpoint    = i;
                        methodIds.methodNodeId = methodIdentifier;
                        methodIds.objectNodeId = objectIdentifier;
                        methodIdList[i].Add(methodIds);
                    }
                    else if (refDescD.BrowseName.Name == "ScanStop")
                    {
                        objectIdentifier       = (uint)foundRefDescCol[i].NodeId.Identifier;
                        methodIdentifier       = (uint)refDescD.NodeId.Identifier;
                        methodIds.method       = MethodToCall.ScanStop;
                        methodIds.readpoint    = i;
                        methodIds.methodNodeId = methodIdentifier;
                        methodIds.objectNodeId = objectIdentifier;
                        methodIdList[i].Add(methodIds);
                    }
                    else if (refDescD.BrowseName.Name == "ReadTag")
                    {
                        objectIdentifier       = (uint)foundRefDescCol[i].NodeId.Identifier;
                        methodIdentifier       = (uint)refDescD.NodeId.Identifier;
                        methodIds.method       = MethodToCall.ReadTag;
                        methodIds.readpoint    = i;
                        methodIds.methodNodeId = methodIdentifier;
                        methodIds.objectNodeId = objectIdentifier;
                        methodIdList[i].Add(methodIds);
                    }
                    else if (refDescD.BrowseName.Name == "WriteTag")
                    {
                        objectIdentifier       = (uint)foundRefDescCol[i].NodeId.Identifier;
                        methodIdentifier       = (uint)refDescD.NodeId.Identifier;
                        methodIds.method       = MethodToCall.WriteTag;
                        methodIds.readpoint    = i;
                        methodIds.methodNodeId = methodIdentifier;
                        methodIds.objectNodeId = objectIdentifier;
                        methodIdList[i].Add(methodIds);
                    }
                    else if (refDescD.BrowseName.Name == "KillTag")
                    {
                        objectIdentifier       = (uint)foundRefDescCol[i].NodeId.Identifier;
                        methodIdentifier       = (uint)refDescD.NodeId.Identifier;
                        methodIds.method       = MethodToCall.KillTag;
                        methodIds.readpoint    = i;
                        methodIds.methodNodeId = methodIdentifier;
                        methodIds.objectNodeId = objectIdentifier;
                        methodIdList[i].Add(methodIds);
                    }
                    else if (refDescD.BrowseName.Name == "LockTag")
                    {
                        objectIdentifier       = (uint)foundRefDescCol[i].NodeId.Identifier;
                        methodIdentifier       = (uint)refDescD.NodeId.Identifier;
                        methodIds.method       = MethodToCall.LockTag;
                        methodIds.readpoint    = i;
                        methodIds.methodNodeId = methodIdentifier;
                        methodIds.objectNodeId = objectIdentifier;
                        methodIdList[i].Add(methodIds);
                    }
                    else if (refDescD.BrowseName.Name == "SetTagPassword")
                    {
                        objectIdentifier       = (uint)foundRefDescCol[i].NodeId.Identifier;
                        methodIdentifier       = (uint)refDescD.NodeId.Identifier;
                        methodIds.method       = MethodToCall.SetTagPw;
                        methodIds.readpoint    = i;
                        methodIds.methodNodeId = methodIdentifier;
                        methodIds.objectNodeId = objectIdentifier;
                        methodIdList[i].Add(methodIds);
                    }
                }
            }
        }
예제 #18
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);
            }
        }
예제 #19
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);
                    }
                }
            }      
        }
예제 #20
0
        private void SelectMI_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_nodesSelected != null)
                {
                    if (NodesTV.SelectedNode == null)
                    {
                        return;
                    }

                    ReferenceDescription reference = NodesTV.SelectedNode.Tag as ReferenceDescription;

                    if (reference != null)
                    {
                        ReferenceDescriptionCollection collection = new ReferenceDescriptionCollection();
                        collection.Add(reference);
                        m_nodesSelected(this, new NodesSelectedEventArgs(collection));
                    }
                }        
			}
            catch (Exception exception)
            {
				GuiUtils.HandleException(this.Text, MethodBase.GetCurrentMethod(), exception);
            }
        }
예제 #21
0
        /// <summary>
        /// Loops until browse is complete for max results reached.
        /// </summary>
        protected ServiceResult FetchReferences(
            OperationContext                   context,
            bool                               assignContinuationPoint,
            ref ContinuationPoint              cp, 
            ref ReferenceDescriptionCollection references)
        {
            Debug.Assert(context != null);
            Debug.Assert(cp != null);
            Debug.Assert(references != null);

            INodeManager nodeManager = cp.Manager;
            NodeClass nodeClassMask = (NodeClass)cp.NodeClassMask;
            BrowseResultMask resultMask = cp.ResultMask;

            // loop until browse is complete or max results.
            while (cp != null)
            {
                // fetch next batch.
                nodeManager.Browse(context, ref cp, references);
                
                ReferenceDescriptionCollection referencesToKeep = new ReferenceDescriptionCollection(references.Count);

                // check for incomplete reference descriptions.
                for (int ii = 0; ii < references.Count; ii++)
                {
                    ReferenceDescription reference = references[ii];
                    
                    // check if filtering must be applied.
                    if (reference.Unfiltered)
                    {                   
                        // ignore unknown external references.
                        if (reference.NodeId.IsAbsolute)
                        {
                            continue;
                        }

                        // update the description.
                        bool include = UpdateReferenceDescription(
                            context,
                            (NodeId)reference.NodeId,
                            nodeClassMask,
                            resultMask,
                            reference);

                        if (!include)
                        {
                            continue;
                        }
                    }

                    // add to list.
                    referencesToKeep.Add(reference);
                }

                // replace list.
                references = referencesToKeep;

                // check if browse limit reached.
                if (cp != null && references.Count >= cp.MaxResultsToReturn)
                {
                    if (!assignContinuationPoint)
                    {
                        return StatusCodes.BadNoContinuationPoints;
                    }

                    cp.Id = Guid.NewGuid();
                    context.Session.SaveContinuationPoint(cp);
                    break;
                }
            }

            // all is good.
            return ServiceResult.Good;
        }