Opc.Ua.Com.Client.ComAeClientNodeManager.ValidateNode C# (CSharp) Method

ValidateNode() protected method

Verifies that the specified node exists.
protected ValidateNode ( ServerSystemContext context, NodeHandle handle, NodeState>.IDictionary cache ) : NodeState
context Opc.Ua.Server.ServerSystemContext
handle Opc.Ua.Server.NodeHandle
cache NodeState>.IDictionary
return NodeState
        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);
                }
            }
        }