Class DataModelUtils
General utils for data models.
Inherited Members
Namespace: Cognite.Extensions.DataModels
Assembly: Cognite.Extensions.dll
Syntax
public static class DataModelUtils
Methods
| Edit this page View SourceEnsureResourcesExistsAsync<T, T2>(T2, IEnumerable<SourcedNodeWrite<T>>, Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)>, int, int, RetryMode, SanitationMode, CancellationToken)
Ensures that all resources in resourcesToEnsure
exists in CDF.
Tries to create resources 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 asset, duplicated externalId, duplicated
legacy name, or missing dataSetId, they can be removed before retrying by setting retryMode
Resources will be returned in the same order as given in resourcesToEnsure
Declaration
public static Task<CogniteResult<SourcedNode<T>, SourcedNodeWrite<T>>> EnsureResourcesExistsAsync<T, T2>(T2 resource, IEnumerable<SourcedNodeWrite<T>> resourcesToEnsure, Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)> sanitizationMethod, int chunkSize, int throttleSize, RetryMode retryMode, SanitationMode sanitationMode, CancellationToken token) where T2 : BaseDataModelResource<T>
Parameters
Type | Name | Description |
---|---|---|
T2 | resource | CogniteSdk CDM Asset resource |
IEnumerable<SourcedNodeWrite<T>> | resourcesToEnsure | List of CogniteSdk SourcedNodeWrite objects |
Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)> | sanitizationMethod | Function that sanitizes CogniteSdk SourcedNodeWrite 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 resources before creating |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<CogniteResult<SourcedNode<T>, SourcedNodeWrite<T>>> | A CogniteResult<TResult, TError> containing errors that occured and a list of the created resources |
Type Parameters
Name | Description |
---|---|
T | |
T2 |
GetOrCreateResourcesAsync<T, T2>(T2, IEnumerable<InstanceIdentifier>, Func<IEnumerable<InstanceIdentifier>, IEnumerable<SourcedNodeWrite<T>>>, Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)>, int, int, RetryMode, SanitationMode, CancellationToken)
Get or create the resources with the provided instanceIds
if they exist in CDF.
If one or more do not exist, use the buildResources
function to construct
the missing resource 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 asset, duplicated externalId, duplicated
legacy name, or missing dataSetId, they can be removed before retrying by setting retryMode
Declaration
public static Task<CogniteResult<SourcedNode<T>, SourcedNodeWrite<T>>> GetOrCreateResourcesAsync<T, T2>(this T2 resource, IEnumerable<InstanceIdentifier> instanceIds, Func<IEnumerable<InstanceIdentifier>, IEnumerable<SourcedNodeWrite<T>>> buildResources, Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)> sanitizationMethod, int chunkSize, int throttleSize, RetryMode retryMode, SanitationMode sanitationMode, CancellationToken token) where T2 : BaseDataModelResource<T>
Parameters
Type | Name | Description |
---|---|---|
T2 | resource | CogniteSdk CDM Asset resource |
IEnumerable<InstanceIdentifier> | instanceIds | Instance Ids |
Func<IEnumerable<InstanceIdentifier>, IEnumerable<SourcedNodeWrite<T>>> | buildResources | Function that builds CogniteSdk SourcedNodeWrite objects |
Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)> | sanitizationMethod | Function that sanitizes CogniteSdk SourcedNodeWrite 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 resources before creating |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<CogniteResult<SourcedNode<T>, SourcedNodeWrite<T>>> | A CogniteResult<TResult, TError> containing errors that occured and a list of the created and found resources |
Type Parameters
Name | Description |
---|---|
T | |
T2 |
GetOrCreateResourcesAsync<T, T2>(T2, IEnumerable<InstanceIdentifier>, Func<IEnumerable<InstanceIdentifier>, Task<IEnumerable<SourcedNodeWrite<T>>>>, Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)>, int, int, RetryMode, SanitationMode, CancellationToken)
Get or create the resources with the provided instanceIds
if they exist in CDF.
If one or more do not exist, use the buildResources
function to construct
the missing resource 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 asset, duplicated externalId, duplicated
legacy name, or missing dataSetId, they can be removed before retrying by setting retryMode
Declaration
public static Task<CogniteResult<SourcedNode<T>, SourcedNodeWrite<T>>> GetOrCreateResourcesAsync<T, T2>(T2 resource, IEnumerable<InstanceIdentifier> instanceIds, Func<IEnumerable<InstanceIdentifier>, Task<IEnumerable<SourcedNodeWrite<T>>>> buildResources, Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)> sanitizationMethod, int chunkSize, int throttleSize, RetryMode retryMode, SanitationMode sanitationMode, CancellationToken token) where T2 : BaseDataModelResource<T>
Parameters
Type | Name | Description |
---|---|---|
T2 | resource | CogniteSdk CDM Asset resource |
IEnumerable<InstanceIdentifier> | instanceIds | External Ids |
Func<IEnumerable<InstanceIdentifier>, Task<IEnumerable<SourcedNodeWrite<T>>>> | buildResources | Async function that builds CogniteSdk SourcedNodeWrite objects |
Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)> | sanitizationMethod | Function that sanitizes CogniteSdk SourcedNodeWrite 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 resources before creating |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<CogniteResult<SourcedNode<T>, SourcedNodeWrite<T>>> | A CogniteResult<TResult, TError> containing errors that occured and a list of the created and found resources |
Type Parameters
Name | Description |
---|---|
T | |
T2 |
GetResourcesByIdsIgnoreErrors<T, T2>(T2, IEnumerable<Identity>, int, int, CancellationToken)
Get the resources with the provided ids
. Ignore any
unknown ids
Declaration
public static Task<IEnumerable<SourcedNode<T>>> GetResourcesByIdsIgnoreErrors<T, T2>(T2 resource, IEnumerable<Identity> ids, int chunkSize, int throttleSize, CancellationToken token) where T2 : BaseDataModelResource<T>
Parameters
Type | Name | Description |
---|---|---|
T2 | resource | CogniteSdk CDM Asset 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<SourcedNode<T>>> |
Type Parameters
Name | Description |
---|---|
T | |
T2 |
ToView(ContainerCreate, string, params ViewIdentifier[])
Create a view from this container, mapping over all properties.
Note that direct relation properties constrained to a container
will be mapped over to point to a view, so if a relation is constrained to the
container (containerSpace, containerExternalId), it will point to
the view given by (containerSpace, version
, containerExternalId)
in the created view.
This method is convenient since you need views in order to query the data, so this can reduce boilerplate.
The new view will have the same name, description, externalId, and space as the container.
Declaration
public static ViewCreate ToView(this ContainerCreate container, string version, params ViewIdentifier[] baseViews)
Parameters
Type | Name | Description |
---|---|---|
ContainerCreate | container | Container to convert |
string | version | Version of the created view |
ViewIdentifier[] | baseViews | List of views this view should implement |
Returns
Type | Description |
---|---|
ViewCreate | Mapped view |
UpsertAsync<T, T2>(T2, IEnumerable<SourcedNodeWrite<T>>, Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)>, int, int, RetryMode, SanitationMode, CancellationToken)
Upsert resources.
If any items fail to be created due to duplicated instance ids, they can be removed before retrying by setting retryMode
Resources will be returned in the same order as given in items
Declaration
public static Task<CogniteResult<SlimInstance, SourcedNodeWrite<T>>> UpsertAsync<T, T2>(T2 resource, IEnumerable<SourcedNodeWrite<T>> items, Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)> sanitizationMethod, int chunkSize, int throttleSize, RetryMode retryMode, SanitationMode sanitationMode, CancellationToken token) where T2 : BaseDataModelResource<T>
Parameters
Type | Name | Description |
---|---|---|
T2 | resource | CogniteSdk CDM Asset resource |
IEnumerable<SourcedNodeWrite<T>> | items | List of resource updates |
Func<IEnumerable<SourcedNodeWrite<T>>, SanitationMode, (IEnumerable<SourcedNodeWrite<T>>, IEnumerable<CogniteError<SourcedNodeWrite<T>>>)> | sanitizationMethod | Function that sanitizes CogniteSdk SourcedNodeWrite objects |
int | chunkSize | Maximum number of resources per request |
int | throttleSize | Maximum number of parallel requests |
RetryMode | retryMode | How to handle retries |
SanitationMode | sanitationMode | What kind of pre-request sanitation to perform |
CancellationToken | token | Cancellation token |
Returns
Type | Description |
---|---|
Task<CogniteResult<SlimInstance, SourcedNodeWrite<T>>> | A CogniteResult<TResult, TError> containing errors that occured and a list of the updated resources |
Type Parameters
Name | Description |
---|---|
T | |
T2 |