Opc.Ua.Com.Client.ComDaClient.FindElementParentId C# (CSharp) Method

FindElementParentId() public method

Finds the item id for the parent of the element.
public FindElementParentId ( string itemId ) : string
itemId string The item id.
return string
        public string FindElementParentId(string itemId)
        {
            if (String.IsNullOrEmpty(itemId))
            {
                return null;
            }

            // check in cache.
            DaElement element = null;

            lock (m_cache)
            {
                if (m_cache.TryGetValue(itemId, out element))
                {
                    if (element.ParentId != null)
                    {
                        return element.ParentId;
                    }
                }
            }

            // check if the element is a branch.
            if (!ChangeBrowsePosition(OPCBROWSEDIRECTION.OPC_BROWSE_TO, itemId))
            {
                return null;
            }

            // need to fetch list of branches to search.
            EnumString enumerator = CreateEnumerator(true);

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

            // find the child with the same item id.
            try
            {
                // process all branches.
                string name = null;

                do
                {
                    name = enumerator.Next();

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

                    // fetch the item id.
                    string targetId = GetItemId(name);

                    // check if target found.
                    if (targetId == itemId)
                    {
                        return GetItemId(String.Empty);
                    }
                }
                while (name != null);

            }
            finally
            {
                enumerator.Dispose();
            }

            return null;
        }