public void FindComponentIds(
NodeId instanceId,
IList<string> componentPaths,
out NodeIdCollection componentIds,
out List<ServiceResult> errors)
{
componentIds = new NodeIdCollection();
errors = new List<ServiceResult>();
// build list of paths to translate.
BrowsePathCollection pathsToTranslate = new BrowsePathCollection();
for (int ii = 0; ii < componentPaths.Count; ii++)
{
BrowsePath pathToTranslate = new BrowsePath();
pathToTranslate.StartingNode = instanceId;
pathToTranslate.RelativePath = RelativePath.Parse(componentPaths[ii], TypeTree);
pathsToTranslate.Add(pathToTranslate);
}
// translate the paths.
BrowsePathResultCollection results = null;
DiagnosticInfoCollection diagnosticInfos = null;
ResponseHeader responseHeader = TranslateBrowsePathsToNodeIds(
null,
pathsToTranslate,
out results,
out diagnosticInfos);
// verify that the server returned the correct number of results.
ClientBase.ValidateResponse(results, pathsToTranslate);
ClientBase.ValidateDiagnosticInfos(diagnosticInfos, pathsToTranslate);
for (int ii = 0; ii < componentPaths.Count; ii++)
{
componentIds.Add(NodeId.Null);
errors.Add(ServiceResult.Good);
// process any diagnostics associated with any error.
if (StatusCode.IsBad(results[ii].StatusCode))
{
errors[ii] = new ServiceResult(results[ii].StatusCode, ii, diagnosticInfos, responseHeader.StringTable);
continue;
}
// Expecting exact one NodeId for a local node.
// Report an error if the server returns anything other than that.
if (results[ii].Targets.Count == 0)
{
errors[ii] = ServiceResult.Create(
StatusCodes.BadTargetNodeIdInvalid,
"Could not find target for path: {0}.",
componentPaths[ii]);
continue;
}
if (results[ii].Targets.Count != 1)
{
errors[ii] = ServiceResult.Create(
StatusCodes.BadTooManyMatches,
"Too many matches found for path: {0}.",
componentPaths[ii]);
continue;
}
if (results[ii].Targets[0].RemainingPathIndex != UInt32.MaxValue)
{
errors[ii] = ServiceResult.Create(
StatusCodes.BadTargetNodeIdInvalid,
"Cannot follow path to external server: {0}.",
componentPaths[ii]);
continue;
}
if (NodeId.IsNull(results[ii].Targets[0].TargetId))
{
errors[ii] = ServiceResult.Create(
StatusCodes.BadUnexpectedError,
"Server returned a null NodeId for path: {0}.",
componentPaths[ii]);
continue;
}
if (results[ii].Targets[0].TargetId.IsAbsolute)
{
errors[ii] = ServiceResult.Create(
StatusCodes.BadUnexpectedError,
"Server returned a remote node for path: {0}.",
componentPaths[ii]);
continue;
}
// suitable target found.
componentIds[ii] = ExpandedNodeId.ToNodeId(results[ii].Targets[0].TargetId, m_namespaceUris);
}
}