Class ApiUtils
Utility methods for the CogniteSDK.
Inherited Members
Namespace: Cognite.Extensions
Assembly: Cognite.Extensions.dll
Syntax
public static class ApiUtils
Methods
| Edit this page View SourceFollowCursor<TResult, TQuery>(TQuery?, Func<TQuery, CancellationToken, Task<IItemsWithCursor<TResult>>>, CancellationToken)
Return an async enumerator for the specified method, following the cursor to exhaustion.
query
is reused, so a filter can be passed to it.
Declaration
public static IAsyncEnumerable<TResult> FollowCursor<TResult, TQuery>(TQuery? query, Func<TQuery, CancellationToken, Task<IItemsWithCursor<TResult>>> method, CancellationToken token) where TQuery : CursorQueryBase
Parameters
Type | Name | Description |
---|---|---|
TQuery | query | Initial query. If this is null, a default instance is created |
Func<TQuery, CancellationToken, Task<IItemsWithCursor<TResult>>> | method | Method to call to fetch the next chunk. |
CancellationToken | token | Optional cancellation token. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TResult> | An asynchronous enumerable iterating over the full result collection. New queries to CDF will be made as the previous results are exhausted. |
Type Parameters
Name | Description |
---|---|
TResult | The actual result type |
TQuery | Query type, must be a subtype of CursorQueryBase |
ReadAllPartitioned<TResult, TQuery>(Func<TQuery>, Func<TQuery, CancellationToken, Task<IItemsWithCursor<TResult>>>, int, int, CancellationToken)
Retrieve all elements from a resource that allows reading with partitions.
Declaration
public static Task<IEnumerable<TResult>> ReadAllPartitioned<TResult, TQuery>(Func<TQuery> queryGenerator, Func<TQuery, CancellationToken, Task<IItemsWithCursor<TResult>>> method, int numPartitions, int parallelism, CancellationToken token) where TQuery : CursorQueryBase, IPartitionedQuery
Parameters
Type | Name | Description |
---|---|---|
Func<TQuery> | queryGenerator | Function to return the query. Needs to return separate queries since we need one instance per parallel request, as they will be used at the same time. |
Func<TQuery, CancellationToken, Task<IItemsWithCursor<TResult>>> | method | SDK method accepting the query |
int | numPartitions | Number of partitions. Must be a number greater than 0. |
int | parallelism | Maximum number of parallel requests. |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<IEnumerable<TResult>> | The full list of retrieved items, in no particular order |
Type Parameters
Name | Description |
---|---|
TResult | Result type |
TQuery | Type of query, must be both a CursorQueryBase and IPartitionedQuery |
ToListAsync<T>(IAsyncEnumerable<T>, CancellationToken)
Utility method to convert an async enumerable to a synchronous collection. This will exhaust the enumerable.
Declaration
public static Task<IEnumerable<T>> ToListAsync<T>(this IAsyncEnumerable<T> items, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<T> | items | Items to exhaust. |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<IEnumerable<T>> | The contents of the enumerable in a synchronous collection. |
Type Parameters
Name | Description |
---|---|
T | Type of enumerable |