Class AssetExtensions
Extension utility methods for CogniteSDK Client.
Inherited Members
Namespace: Cognite.Extensions
Assembly: Cognite.Extensions.dll
Syntax
public static class AssetExtensions
Methods
| Edit this page View SourceEnsureExistsAsync(AssetsResource, IEnumerable<AssetCreate>, int, int, RetryMode, SanitationMode, CancellationToken)
Ensures that all assets in assetsToEnsure
exist in CDF.
Tries to create the assets and returns when all are created or have been removed
due to issues with the request.
If any items fail to be created due to missing parent, duplicated externalId or missing dataset
they can be removed before retrying by setting retryMode
.
Assets will be returned in the same order as given in assetsToEnsure
.
Declaration
public static Task<CogniteResult<Asset, AssetCreate>> EnsureExistsAsync(this AssetsResource assets, IEnumerable<AssetCreate> assetsToEnsure, int chunkSize, int throttleSize, RetryMode retryMode, SanitationMode sanitationMode, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
AssetsResource | assets | Cognite assets resource |
IEnumerable<AssetCreate> | assetsToEnsure | List of AssetCreate objects |
int | chunkSize | Chunk size |
int | throttleSize | Throttle size |
RetryMode | retryMode | How to do retries. Keeping duplicates is not valid for this method. |
SanitationMode | sanitationMode | The type of sanitation to apply to assets before creating |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<CogniteResult<Asset, AssetCreate>> | A CogniteResult<TResult, TError> containing errors that occured and a list of the created assets |
GetAssetsByIdsIgnoreErrors(AssetsResource, IEnumerable<Identity>, int, int, CancellationToken)
Get the assets with the provided ids
. Ignore any
unknown ids
Declaration
public static Task<IEnumerable<Asset>> GetAssetsByIdsIgnoreErrors(this AssetsResource assets, IEnumerable<Identity> ids, int chunkSize, int throttleSize, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
AssetsResource | assets | A CogniteSdk Assets resource |
IEnumerable<Identity> | ids | List of CogniteSdk.Identity objects |
int | chunkSize | Chunk size |
int | throttleSize | Throttle size |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<IEnumerable<Asset>> |
GetOrCreateAsync(AssetsResource, IEnumerable<string>, Func<IEnumerable<string>, IEnumerable<AssetCreate>>, int, int, RetryMode, SanitationMode, CancellationToken)
Get or create the assets with the provided externalIds
exist in CDF.
If one or more do not exist, use the buildAssets
function to construct
the missing asset objects and upload them to CDF using the chunking of items and throttling
passed as parameters
If any items fail to be created due to missing parent, duplicated externalId or missing dataset
they can be removed before retrying by setting retryMode
.
Declaration
public static Task<CogniteResult<Asset, AssetCreate>> GetOrCreateAsync(this AssetsResource assets, IEnumerable<string> externalIds, Func<IEnumerable<string>, IEnumerable<AssetCreate>> buildAssets, int chunkSize, int throttleSize, RetryMode retryMode, SanitationMode sanitationMode, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
AssetsResource | assets | Cognite assets resource |
IEnumerable<string> | externalIds | External Ids |
Func<IEnumerable<string>, IEnumerable<AssetCreate>> | buildAssets | Async function that builds AssetCreate objects |
int | chunkSize | Chunk size |
int | throttleSize | Throttle size |
RetryMode | retryMode | How to handle failed requests |
SanitationMode | sanitationMode | The type of sanitation to apply to assets before creating |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<CogniteResult<Asset, AssetCreate>> | A CogniteResult<TResult, TError> containing errors that occured and a list of the created and found assets |
GetOrCreateAsync(AssetsResource, IEnumerable<string>, Func<IEnumerable<string>, Task<IEnumerable<AssetCreate>>>, int, int, RetryMode, SanitationMode, CancellationToken)
Get or create the assets with the provided externalIds
exist in CDF.
If one or more do not exist, use the buildAssets
function to construct
the missing asset objects and upload them to CDF using the chunking of items and throttling
passed as parameters
If any items fail to be created due to missing parent, duplicated externalId or missing dataset
they can be removed before retrying by setting retryMode
.
Declaration
public static Task<CogniteResult<Asset, AssetCreate>> GetOrCreateAsync(this AssetsResource assets, IEnumerable<string> externalIds, Func<IEnumerable<string>, Task<IEnumerable<AssetCreate>>> buildAssets, int chunkSize, int throttleSize, RetryMode retryMode, SanitationMode sanitationMode, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
AssetsResource | assets | Cognite assets resource |
IEnumerable<string> | externalIds | External Ids |
Func<IEnumerable<string>, Task<IEnumerable<AssetCreate>>> | buildAssets | Async function that builds AssetCreate objects |
int | chunkSize | Chunk size |
int | throttleSize | Throttle size |
RetryMode | retryMode | How to handle failed requests |
SanitationMode | sanitationMode | The type of sanitation to apply to assets before creating |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<CogniteResult<Asset, AssetCreate>> | A CogniteResult<TResult, TError> containing errors that occured and a list of the created and found assets |
UpdateAsync(AssetsResource, IEnumerable<AssetUpdateItem>, int, int, RetryMode, SanitationMode, CancellationToken)
Attempt to update all assets in updates
, will retry
and attempt to handle errors.
Assets will be returned in the same order as given.
Declaration
public static Task<CogniteResult<Asset, AssetUpdateItem>> UpdateAsync(this AssetsResource assets, IEnumerable<AssetUpdateItem> updates, int chunkSize, int throttleSize, RetryMode retryMode, SanitationMode sanitationMode, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
AssetsResource | assets | Cognite assets resource |
IEnumerable<AssetUpdateItem> | updates | List of AssetUpdateItem objects |
int | chunkSize | Chunk size |
int | throttleSize | Throttle size |
RetryMode | retryMode | How to do retries. Keeping duplicates is not valid for this method. |
SanitationMode | sanitationMode | The type of sanitation to apply to assets before updating |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<CogniteResult<Asset, AssetUpdateItem>> | A CogniteResult<TResult, TError> containing errors that occured and a list of the updated assets |
UpsertAsync(AssetsResource, IEnumerable<AssetCreate>, int, int, RetryMode, SanitationMode, UpsertParams?, CancellationToken)
Insert or update a list of assets, handling errors that come up during both insert and update. Only assets that differ from assets in CDF are updated.
All given assets must have an external id, so it is not in practice possible to use this to change the externalId of assets.
Assets are returned in the same order as given.
Declaration
public static Task<CogniteResult<Asset, AssetCreate>> UpsertAsync(this AssetsResource assets, IEnumerable<AssetCreate> upserts, int chunkSize, int throttleSize, RetryMode retryMode, SanitationMode sanitationMode, UpsertParams? options, CancellationToken token)
Parameters
Type | Name | Description |
---|---|---|
AssetsResource | assets | Assets resource |
IEnumerable<AssetCreate> | upserts | Assets to upsert |
int | chunkSize | Number of asset creates, retrieves or updates per request |
int | throttleSize | Maximum number of parallel requests |
RetryMode | retryMode | How to handle retries on errors |
SanitationMode | sanitationMode | How to sanitize creates and updates |
UpsertParams | options | How to update existing assets |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<CogniteResult<Asset, AssetCreate>> | Result with failed creates/updates and list of assets |
Exceptions
Type | Condition |
---|---|
ArgumentException | All upserted assets must have external id |