/// <summary> /// Browse all references /// </summary> private static async Task <BrowseResponseApiModel> NodeBrowseAsync( ITwinServiceApi service, string endpoint, BrowseRequestApiModel request) { while (true) { var result = await service.NodeBrowseFirstAsync(endpoint, request); while (result.ContinuationToken != null) { try { var next = await service.NodeBrowseNextAsync(endpoint, new BrowseNextRequestApiModel { ContinuationToken = result.ContinuationToken, Header = request.Header, ReadVariableValues = request.ReadVariableValues, TargetNodesOnly = request.TargetNodesOnly }); result.References.AddRange(next.References); result.ContinuationToken = next.ContinuationToken; } catch (Exception) { await Try.Async(() => service.NodeBrowseNextAsync(endpoint, new BrowseNextRequestApiModel { ContinuationToken = result.ContinuationToken, Abort = true })); throw; } } return(result); } }
/// <summary> /// Browse all references if max references is null and user /// wants all. If user has requested maximum to return uses /// <see cref="ITwinServiceApi.NodeBrowseFirstAsync"/> /// </summary> /// <param name="service"></param> /// <param name="endpoint"></param> /// <param name="request"></param> /// <param name="ct"></param> /// <returns></returns> public static async Task <BrowseResponseApiModel> NodeBrowseAsync( this ITwinServiceApi service, string endpoint, BrowseRequestApiModel request, CancellationToken ct = default) { if (request.MaxReferencesToReturn != null) { return(await service.NodeBrowseFirstAsync(endpoint, request, ct)); } while (true) { // Limit size of batches to a reasonable default to avoid communication timeouts. request.MaxReferencesToReturn = 500; var result = await service.NodeBrowseFirstAsync(endpoint, request, ct); while (result.ContinuationToken != null) { try { var next = await service.NodeBrowseNextAsync(endpoint, new BrowseNextRequestApiModel { ContinuationToken = result.ContinuationToken, Header = request.Header, ReadVariableValues = request.ReadVariableValues, TargetNodesOnly = request.TargetNodesOnly }, ct); result.References.AddRange(next.References); result.ContinuationToken = next.ContinuationToken; } catch (Exception) { await Try.Async(() => service.NodeBrowseNextAsync(endpoint, new BrowseNextRequestApiModel { ContinuationToken = result.ContinuationToken, Abort = true })); throw; } } return(result); } }