public BrowseNext ( RequestHeader requestHeader, bool releaseContinuationPoint, byte continuationPoint, byte &revisedContinuationPoint, ReferenceDescriptionCollection &references ) : ResponseHeader | ||
requestHeader | RequestHeader | |
releaseContinuationPoint | bool | |
continuationPoint | byte | |
revisedContinuationPoint | byte | |
references | ReferenceDescriptionCollection | |
리턴 | ResponseHeader |
public static ReferenceDescriptionCollection Browse(Session session, BrowseDescription nodeToBrowse, bool throwOnError) { try { var descriptionCollection = new ReferenceDescriptionCollection(); var nodesToBrowse = new BrowseDescriptionCollection { nodeToBrowse }; BrowseResultCollection results; DiagnosticInfoCollection diagnosticInfos; session.Browse(null, null, 0U, nodesToBrowse, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, nodesToBrowse); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse); while (!StatusCode.IsBad(results[0].StatusCode)) { for (var index = 0; index < results[0].References.Count; ++index) descriptionCollection.Add(results[0].References[index]); if (results[0].References.Count == 0 || results[0].ContinuationPoint == null) return descriptionCollection; var continuationPoints = new ByteStringCollection(); continuationPoints.Add(results[0].ContinuationPoint); session.BrowseNext(null, false, continuationPoints, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, continuationPoints); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints); } throw new ServiceResultException(results[0].StatusCode); } catch (Exception ex) { if (throwOnError) throw new ServiceResultException(ex, 2147549184U); return null; } }
/// <summary> /// Browses the address space and returns the references found. /// </summary> public static ReferenceDescriptionCollection Browse(Session session, ViewDescription view, BrowseDescription nodeToBrowse, bool throwOnError) { try { ReferenceDescriptionCollection references = new ReferenceDescriptionCollection(); // construct browse request. BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection(); nodesToBrowse.Add(nodeToBrowse); // start the browse operation. BrowseResultCollection results = null; DiagnosticInfoCollection diagnosticInfos = null; session.Browse( null, view, 0, nodesToBrowse, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, nodesToBrowse); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse); do { // check for error. if (StatusCode.IsBad(results[0].StatusCode)) { throw new ServiceResultException(results[0].StatusCode); } // process results. for (int ii = 0; ii < results[0].References.Count; ii++) { references.Add(results[0].References[ii]); } // check if all references have been fetched. if (results[0].References.Count == 0 || results[0].ContinuationPoint == null) { break; } // continue browse operation. ByteStringCollection continuationPoints = new ByteStringCollection(); continuationPoints.Add(results[0].ContinuationPoint); session.BrowseNext( null, false, continuationPoints, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, continuationPoints); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints); } while (true); //return complete list. return references; } catch (Exception exception) { if (throwOnError) { throw new ServiceResultException(exception, StatusCodes.BadUnexpectedError); } return null; } }
/// <summary> /// Browses the address space and returns the references found. /// </summary> public static ReferenceDescriptionCollection Browse(Session session, ViewDescription view, BrowseDescriptionCollection nodesToBrowse, bool throwOnError) { try { ReferenceDescriptionCollection references = new ReferenceDescriptionCollection(); BrowseDescriptionCollection unprocessedOperations = new BrowseDescriptionCollection(); while (nodesToBrowse.Count > 0) { // start the browse operation. BrowseResultCollection results = null; DiagnosticInfoCollection diagnosticInfos = null; session.Browse( null, view, 0, nodesToBrowse, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, nodesToBrowse); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse); ByteStringCollection continuationPoints = new ByteStringCollection(); for (int ii = 0; ii < nodesToBrowse.Count; ii++) { // check for error. if (StatusCode.IsBad(results[ii].StatusCode)) { // this error indicates that the server does not have enough simultaneously active // continuation points. This request will need to be resent after the other operations // have been completed and their continuation points released. if (results[ii].StatusCode == StatusCodes.BadNoContinuationPoints) { unprocessedOperations.Add(nodesToBrowse[ii]); } continue; } // check if all references have been fetched. if (results[ii].References.Count == 0) { continue; } // save results. references.AddRange(results[ii].References); // check for continuation point. if (results[ii].ContinuationPoint != null) { continuationPoints.Add(results[ii].ContinuationPoint); } } // process continuation points. ByteStringCollection revisedContiuationPoints = new ByteStringCollection(); while (continuationPoints.Count > 0) { // continue browse operation. session.BrowseNext( null, false, continuationPoints, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, continuationPoints); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints); for (int ii = 0; ii < continuationPoints.Count; ii++) { // check for error. if (StatusCode.IsBad(results[ii].StatusCode)) { continue; } // check if all references have been fetched. if (results[ii].References.Count == 0) { continue; } // save results. references.AddRange(results[ii].References); // check for continuation point. if (results[ii].ContinuationPoint != null) { revisedContiuationPoints.Add(results[ii].ContinuationPoint); } } // check if browsing must continue; revisedContiuationPoints = continuationPoints; } // check if unprocessed results exist. nodesToBrowse = unprocessedOperations; } // return complete list. return references; } catch (Exception exception) { if (throwOnError) { throw new ServiceResultException(exception, StatusCodes.BadUnexpectedError); } return null; } }
/// <summary> /// Finds the targets for the specified reference. /// </summary> private static List<NodeId> FindTargetOfReference(Session session, List<NodeId> nodeIds, NodeId referenceTypeId, bool throwOnError) { try { // construct browse request. BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection(); for (int ii = 0; ii < nodeIds.Count; ii++) { BrowseDescription nodeToBrowse = new BrowseDescription(); nodeToBrowse.NodeId = nodeIds[ii]; nodeToBrowse.BrowseDirection = BrowseDirection.Forward; nodeToBrowse.ReferenceTypeId = referenceTypeId; nodeToBrowse.IncludeSubtypes = false; nodeToBrowse.NodeClassMask = 0; nodeToBrowse.ResultMask = (uint)BrowseResultMask.None; nodesToBrowse.Add(nodeToBrowse); } // start the browse operation. BrowseResultCollection results = null; DiagnosticInfoCollection diagnosticInfos = null; session.Browse( null, null, 1, nodesToBrowse, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, nodesToBrowse); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse); List<NodeId> targetIds = new List<NodeId>(); ByteStringCollection continuationPoints = new ByteStringCollection(); for (int ii = 0; ii < nodeIds.Count; ii++) { targetIds.Add(null); // check for error. if (StatusCode.IsBad(results[ii].StatusCode)) { continue; } // check for continuation point. if (results[ii].ContinuationPoint != null && results[ii].ContinuationPoint.Length > 0) { continuationPoints.Add(results[ii].ContinuationPoint); } // get the node id. if (results[ii].References.Count > 0) { if (NodeId.IsNull(results[ii].References[0].NodeId) || results[ii].References[0].NodeId.IsAbsolute) { continue; } targetIds[ii] = (NodeId)results[ii].References[0].NodeId; } } // release continuation points. if (continuationPoints.Count > 0) { session.BrowseNext( null, true, continuationPoints, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, nodesToBrowse); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse); } //return complete list. return targetIds; } catch (Exception exception) { if (throwOnError) { throw new ServiceResultException(exception, StatusCodes.BadUnexpectedError); } return null; } }
/// <summary> /// Fetches the references for the node. /// </summary> private List<ReferenceDescription> Browse(Session session, NodeId nodeId) { List<ReferenceDescription> references = new List<ReferenceDescription>(); // specify the references to follow and the fields to return. BrowseDescription nodeToBrowse = new BrowseDescription(); nodeToBrowse.NodeId = nodeId; nodeToBrowse.ReferenceTypeId = ReferenceTypeIds.References; nodeToBrowse.IncludeSubtypes = true; nodeToBrowse.BrowseDirection = BrowseDirection.Both; nodeToBrowse.NodeClassMask = 0; nodeToBrowse.ResultMask = (uint)BrowseResultMask.All; BrowseDescriptionCollection nodesToBrowse = new BrowseDescriptionCollection(); nodesToBrowse.Add(nodeToBrowse); // start the browse operation. BrowseResultCollection results = null; DiagnosticInfoCollection diagnosticInfos = null; ResponseHeader responseHeader = session.Browse( null, null, 2, nodesToBrowse, out results, out diagnosticInfos); // these do sanity checks on the result - make sure response matched the request. ClientBase.ValidateResponse(results, nodesToBrowse); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, nodesToBrowse); // check status. if (StatusCode.IsBad(results[0].StatusCode)) { // embed the diagnostic information in a exception. throw ServiceResultException.Create(results[0].StatusCode, 0, diagnosticInfos, responseHeader.StringTable); } // add first batch. references.AddRange(results[0].References); // check if server limited the results. while (results[0].ContinuationPoint != null && results[0].ContinuationPoint.Length > 0) { ByteStringCollection continuationPoints = new ByteStringCollection(); continuationPoints.Add(results[0].ContinuationPoint); // continue browse operation. responseHeader = session.BrowseNext( null, false, continuationPoints, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, continuationPoints); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints); // check status. if (StatusCode.IsBad(results[0].StatusCode)) { // embed the diagnostic information in a exception. throw ServiceResultException.Create(results[0].StatusCode, 0, diagnosticInfos, responseHeader.StringTable); } // add next batch. references.AddRange(results[0].References); } return references; }
/// <summary> /// Sends the browse request to the server. /// </summary> /// <param name="session">The session.</param> /// <param name="nodesToBrowse">The nodes to browse.</param> /// <returns></returns> private BrowseResultCollection BrowseBlock(Session session, BrowseDescriptionCollection nodesToBrowse) { try { // Utils.Trace("Browsing {0} Nodes", nodesToBrowse.Count); ViewDescription view = new ViewDescription(); Dictionary<int,BrowseResult> combinedResults = new Dictionary<int, BrowseResult>(); // initialize the table of indexes used to correlate results. BrowseDescriptionCollection browseOperations = nodesToBrowse; List<int> browseIndexes = new List<int>(); for (int ii = 0; ii < nodesToBrowse.Count; ii++) { browseIndexes.Add(ii); } BrowseDescriptionCollection unprocessedOperations = new BrowseDescriptionCollection(); List<int> unprocessedBrowseIndexes = new List<int>(); while (browseOperations.Count > 0) { // start the browse operation. BrowseResultCollection results = null; DiagnosticInfoCollection diagnosticInfos = null; session.Browse( null, view, 0, browseOperations, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, browseOperations); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, browseOperations); unprocessedOperations.Clear(); unprocessedBrowseIndexes.Clear(); ByteStringCollection continuationPoints = new ByteStringCollection(); List<int> continuationPointIndexes = new List<int>(); for (int ii = 0; ii < browseOperations.Count; ii++) { int index = browseIndexes[ii]; // Utils.Trace("{0}/{1}/{2}", browseOperations[ii].NodeId, browseOperations[ii].ReferenceTypeId, results[ii].References.Count); // look up results. BrowseResult combinedResult = null; if (!combinedResults.TryGetValue(index, out combinedResult)) { combinedResults[index] = combinedResult = new BrowseResult(); } // check for error. if (StatusCode.IsBad(results[ii].StatusCode)) { // this error indicates that the server does not have enough simultaneously active // continuation points. This request will need to be resent after the other operations // have been completed and their continuation points released. if (results[ii].StatusCode == StatusCodes.BadNoContinuationPoints) { unprocessedOperations.Add(browseOperations[ii]); unprocessedBrowseIndexes.Add(index); continue; } // save error. if (StatusCode.IsGood(combinedResult.StatusCode)) { combinedResult.StatusCode = results[ii].StatusCode; } continue; } // check if all references have been fetched. if (results[ii].References.Count == 0) { continue; } // save results. combinedResult.References.AddRange(results[ii].References); // check for continuation point. if (results[ii].ContinuationPoint != null && results[ii].ContinuationPoint.Length > 0) { continuationPoints.Add(results[ii].ContinuationPoint); continuationPointIndexes.Add(index); } } // process continuation points. ByteStringCollection revisedContinuationPoints = new ByteStringCollection(); List<int> revisedContinuationPointIndexes = new List<int>(); while (continuationPoints.Count > 0) { bool releaseContinuationPoints = false; // continue browse operation. session.BrowseNext( null, releaseContinuationPoints, continuationPoints, out results, out diagnosticInfos); ClientBase.ValidateResponse(results, continuationPoints); ClientBase.ValidateDiagnosticInfos(diagnosticInfos, continuationPoints); revisedContinuationPoints.Clear(); revisedContinuationPointIndexes.Clear(); for (int ii = 0; ii < continuationPoints.Count; ii++) { int index = continuationPointIndexes[ii]; // look up results. BrowseResult combinedResult = null; if (!combinedResults.TryGetValue(index, out combinedResult)) { combinedResults[index] = new BrowseResult(); } // check for error. if (StatusCode.IsBad(results[ii].StatusCode)) { // save error. if (StatusCode.IsGood(combinedResult.StatusCode)) { combinedResult.StatusCode = results[ii].StatusCode; } continue; } // check if all references have been fetched. if (results[ii].References.Count == 0) { continue; } // save results. combinedResult.References.AddRange(results[ii].References); // check for continuation point. if (results[ii].ContinuationPoint != null && results[ii].ContinuationPoint.Length > 0) { revisedContinuationPoints.Add(results[ii].ContinuationPoint); revisedContinuationPointIndexes.Add(index); } } // check if browsing must continue; continuationPoints = revisedContinuationPoints; continuationPointIndexes = revisedContinuationPointIndexes; } // check if unprocessed results exist. browseOperations = unprocessedOperations; browseIndexes = unprocessedBrowseIndexes; } // reconstruct list of combined results. BrowseResultCollection finalResults = new BrowseResultCollection(); for (int ii = 0; ii < nodesToBrowse.Count; ii++) { BrowseResult combinedResult = null; if (!combinedResults.TryGetValue(ii, out combinedResult)) { combinedResult = new BrowseResult(); } finalResults.Add(combinedResult); } // return complete list. return finalResults; } catch (Exception e) { throw ComUtils.CreateComException(e, ResultIds.E_FAIL); } }