Opc.Ua.ServerTest.TranslatePathTest.AddMultiHopPaths C# (CSharp) Method

AddMultiHopPaths() private method

Adds a single hop path for all references for the node.
private AddMultiHopPaths ( Node node, Node baseNode, IList basePath, BrowsePathCollection pathsToTranslate, int hops ) : void
node Node
baseNode Node
basePath IList
pathsToTranslate BrowsePathCollection
hops int
return void
        private void AddMultiHopPaths(
            Node node, 
            Node baseNode,
            IList<RelativePathElement> basePath,
            BrowsePathCollection pathsToTranslate,
            int hops)
        {
            ReferenceDescriptionCollection references = node.Handle as ReferenceDescriptionCollection;

            if (references == null)
            {
                return;
            }

            for (int ii = 0; ii < references.Count; ii++)
            {
                ReferenceDescription reference = references[ii];
                
                BrowsePath browsePath = new BrowsePath();

                browsePath.StartingNode = baseNode.NodeId;
                browsePath.Handle = baseNode;

                if (basePath != null)
                {
                    browsePath.RelativePath.Elements.AddRange(basePath);
                }
                
                RelativePathElement element = new RelativePathElement();

                element.ReferenceTypeId = ReferenceTypeIds.NonHierarchicalReferences;
                element.IsInverse = !reference.IsForward;
                element.IncludeSubtypes = true;
                element.TargetName = reference.BrowseName;

                browsePath.RelativePath.Elements.Add(element);
                pathsToTranslate.Add(browsePath);

                // only follow forward heiarchical
                if (!Session.TypeTree.IsTypeOf(reference.ReferenceTypeId, ReferenceTypeIds.HierarchicalReferences))
                {
                    continue;
                }

                element.ReferenceTypeId = ReferenceTypeIds.HierarchicalReferences;

                // can't do anything with absolute or inverse references.
                if (!reference.IsForward || reference.NodeId.IsAbsolute)
                {
                    continue;
                }
                                    
                // look up target
                if (browsePath.RelativePath.Elements.Count < hops)
                {
                    Node target = null;

                    if (!AvailableNodes.TryGetValue((NodeId)reference.NodeId, out target))
                    {
                        continue;
                    }

                    AddMultiHopPaths(target, baseNode, browsePath.RelativePath.Elements, pathsToTranslate, hops);
                }
            }
        }
        #endregion