Opc.Ua.Com.Server.ComAe2Browser.BrowseTo C# (CSharp) Method

BrowseTo() public method

Moves the current browse position to the specified item.
public BrowseTo ( string itemId ) : void
itemId string
return void
        public void BrowseTo(string itemId)
        {
            Session session = m_server.Session;

            if (session == null)
            {
                throw ComUtils.CreateComException(ResultIds.E_FAIL);
            }

            lock (m_lock)
            {
                // check if value has been cached.
                if (itemId == null)
                {
                    itemId = String.Empty;
                }

                AeBrowseElement element = null;

                if (m_cache.TryGetValue(itemId, out element))
                {
                    m_position = element;
                    return;
                }

                // parse the item id looking for a known parent.
                Stack<string> names = new Stack<string>();
                AeBrowseElement root = null;
                string currentId = itemId;

                while (!String.IsNullOrEmpty(currentId))
                {
                    string parentId = null;
                    string itemName = currentId;

                    int index = currentId.LastIndexOf('/');

                    if (index >= 0)
                    {
                        parentId = currentId.Substring(0, index);
                        itemName = currentId.Substring(index + 1);
                    }

                    // save time by using an intermediate parent if it has already been cached.
                    if (!String.IsNullOrEmpty(parentId))
                    {
                        if (m_cache.TryGetValue(parentId, out root))
                        {
                            names.Push(itemName);
                            break;
                        }
                    }

                    currentId = parentId;
                    names.Push(itemName);
                    root = null;
                }

                // use root if no parent found.
                if (root == null)
                {
                    root = m_cache[String.Empty];
                }

                // find the element.
                element = Find(session, itemId, root, names, true);

                if (element == null)
                {
                    throw ComUtils.CreateComException(ResultIds.E_INVALIDBRANCHNAME);
                }

                // update cache and set position.
                m_cache[itemId] = element;
                m_position = element;
            }
        }