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

Next() public method

Returns the next AE area or source.
public Next ( ISystemContext context, ushort namespaceIndex ) : BaseObjectState
context ISystemContext
namespaceIndex ushort
return Opc.Ua.BaseObjectState
        public BaseObjectState Next(ISystemContext context, ushort namespaceIndex)
        {
            // check if already completed.
            if (m_completed)
            {
                return null;
            }

            // create the browser.
            if (base.Unknown == null)
            {
                base.Unknown = m_client.CreateAreaBrowser();

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

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

            // create the enumerator if not already created.
            if (m_enumerator == null)
            {
                m_enumerator = CreateEnumerator(false);
                m_sources = false;

                // a null indicates an error.
                if (m_enumerator == null)
                {
                    m_completed = true;
                    return null;
                }
            }

            // need a loop in case errors occur fetching element metadata.
            BaseObjectState node = null;

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

                // a null indicates the end of list.
                if (name == null)
                {
                    if (!m_sources)
                    {
                        m_enumerator.Dispose();
                        m_enumerator = CreateEnumerator(true);
                        m_sources = true;
                        continue;
                    }

                    m_completed = true;
                    return null;
                }

                // create the node.
                if (m_sources)
                {
                    string qualifiedName = GetQualifiedSourceName(name);

                    if (String.IsNullOrEmpty(qualifiedName))
                    {
                        continue;
                    }

                    node = new AeSourceState(context, m_qualifiedName, qualifiedName, name, namespaceIndex);
                }
                else
                {
                    string qualifiedName = GetQualifiedAreaName(name);

                    if (String.IsNullOrEmpty(qualifiedName))
                    {
                        continue;
                    }

                    node = new AeAreaState(context, qualifiedName, name, namespaceIndex);
                }

                break;
            }
            while (node == null);

            // return node.
            return node;
        }