private void GetTargets(Node start, IList<RelativePathElement> path, int index, BrowsePathResult result)
{
// check for invalid parameters.
if (index >= path.Count)
{
return;
}
// look for list of references for node.
ReferenceDescriptionCollection references = start.Handle as ReferenceDescriptionCollection;
if (references == null || references.Count == 0)
{
return;
}
RelativePathElement element = path[index];
// each list of references.
for (int ii = 0; ii < references.Count; ii++)
{
ReferenceDescription reference = references[ii];
// check for a reference match.
if (element.IsInverse == reference.IsForward)
{
continue;
}
if (element.ReferenceTypeId != reference.ReferenceTypeId)
{
if (!element.IncludeSubtypes)
{
continue;
}
if (!Session.TypeTree.IsTypeOf(reference.ReferenceTypeId, element.ReferenceTypeId))
{
continue;
}
}
// check for a browse name match.
if (element.TargetName != reference.BrowseName)
{
continue;
}
// check for end of list.
if (index == path.Count-1)
{
BrowsePathTarget item = new BrowsePathTarget();
item.TargetId = reference.NodeId;
item.RemainingPathIndex = UInt32.MaxValue;
result.Targets.Add(item);
continue;
}
// check for external reference.
if (reference.NodeId.IsAbsolute)
{
BrowsePathTarget item = new BrowsePathTarget();
item.TargetId = reference.NodeId;
item.RemainingPathIndex = (uint)index+1;
result.Targets.Add(item);
continue;
}
// check for targets.
Node target = null;
if (!AvailableNodes.TryGetValue((NodeId)reference.NodeId, out target))
{
BrowsePathTarget item = new BrowsePathTarget();
item.TargetId = reference.NodeId;
item.RemainingPathIndex = (uint)index+1;
result.Targets.Add(item);
continue;
}
// recursively follow targets.
GetTargets(target, path, index+1, result);
}
}