Opc.Ua.Com.Client.ComAeBrowserClient.FindSource C# (CSharp) Method

FindSource() public method

Finds the source.
public FindSource ( ISystemContext context, string areaName, string sourceName, ushort namespaceIndex ) : BaseObjectState
context ISystemContext The context.
areaName string Name of the area.
sourceName string Name of the source.
namespaceIndex ushort Index of the namespace.
return Opc.Ua.BaseObjectState
        public BaseObjectState FindSource(ISystemContext context, string areaName, string sourceName, ushort namespaceIndex)
        {
            // create the browser.
            if (base.Unknown == null)
            {
                base.Unknown = m_client.CreateAreaBrowser();

                if (base.Unknown == null)
                {
                    return null;
                }
            }

            if (!ChangeBrowsePosition(OPCAEBROWSEDIRECTION.OPCAE_BROWSE_TO, areaName))
            {
                return null;
            }

            // remove the enumerator.
            if (m_enumerator != null)
            {
                m_enumerator.Dispose();
                m_enumerator = null;
            }

            m_enumerator = CreateEnumerator(true);

            do
            {
                // fetch the next name.
                string name = m_enumerator.Next();

                // a null indicates the end of list.
                if (name == null)
                {
                    m_completed = true;
                    return null;
                }

                // create the node.
                if (sourceName == name)
                {
                    string qualifiedName = GetQualifiedSourceName(name);
                    return new AeSourceState(context, m_qualifiedName, qualifiedName, name, namespaceIndex);
                }
            }
            while (!m_completed);

            // return node.
            return null;
        }
        #endregion

Usage Example

コード例 #1
0
        /// <summary>
        /// Verifies that the specified node exists.
        /// </summary>
        protected override NodeState ValidateNode(
            ServerSystemContext context,
            NodeHandle handle,
            IDictionary <NodeId, NodeState> cache)
        {
            // not valid if no root.
            if (handle == null)
            {
                return(null);
            }

            // check if previously validated.
            if (handle.Validated)
            {
                return(handle.Node);
            }

            NodeState target = null;

            // check if already in the cache.
            if (cache != null)
            {
                if (cache.TryGetValue(handle.NodeId, out target))
                {
                    // nulls mean a NodeId which was previously found to be invalid has been referenced again.
                    if (target == null)
                    {
                        return(null);
                    }

                    handle.Node      = target;
                    handle.Validated = true;
                    return(handle.Node);
                }

                target = null;
            }

            try
            {
                // check if the node id has been parsed.
                AeParsedNodeId parsedNodeId = handle.ParsedNodeId as AeParsedNodeId;

                if (parsedNodeId == null)
                {
                    return(null);
                }

                ComAeClient client = m_system.SelectClient(context, false);

                switch (parsedNodeId.RootType)
                {
                case AeModelUtils.AeSimpleEventType:
                case AeModelUtils.AeTrackingEventType:
                case AeModelUtils.AeConditionEventType:
                {
                    if (m_typeCache == null)
                    {
                        return(null);
                    }

                    BaseObjectTypeState eventTypeNode = null;
                    NodeId rootId = AeParsedNodeId.Construct(parsedNodeId.RootType, parsedNodeId.CategoryId, parsedNodeId.ConditionName, parsedNodeId.NamespaceIndex);

                    if (!m_typeCache.EventTypeNodes.TryGetValue(rootId, out eventTypeNode))
                    {
                        return(null);
                    }

                    target = eventTypeNode;
                    break;
                }

                case AeModelUtils.AeArea:
                {
                    ComAeBrowserClient browser = new ComAeBrowserClient(client, null);
                    target = browser.FindArea(context, parsedNodeId.RootId, NamespaceIndex);
                    browser.Dispose();

                    handle.Validated = true;
                    handle.Node      = target;
                    return(handle.Node);
                }

                case AeModelUtils.AeSource:
                {
                    ComAeBrowserClient browser = new ComAeBrowserClient(client, null);
                    target = browser.FindSource(context, parsedNodeId.RootId, parsedNodeId.ComponentPath, NamespaceIndex);
                    browser.Dispose();

                    handle.Validated = true;
                    handle.Node      = target;
                    return(handle.Node);
                }

                case AeModelUtils.AeCondition:
                {
                    target = new AeConditionState(context, handle, m_templateAlarm.Acknowledge);
                    break;
                }
                }

                // node does not exist.
                if (target == null)
                {
                    return(null);
                }

                if (!String.IsNullOrEmpty(parsedNodeId.ComponentPath))
                {
                    // validate component.
                    NodeState component = target.FindChildBySymbolicName(context, parsedNodeId.ComponentPath);

                    // component does not exist.
                    if (component == null)
                    {
                        return(null);
                    }

                    target = component;
                }

                // found a valid component.
                handle.Validated = true;
                handle.Node      = target;
                return(handle.Node);
            }
            finally
            {
                // store the node in the cache to optimize subsequent lookups.
                if (cache != null)
                {
                    cache.Add(handle.NodeId, target);
                }
            }
        }
All Usage Examples Of Opc.Ua.Com.Client.ComAeBrowserClient::FindSource