Skip to content

PinnacleTechnology/cognite-sdk-dotnet

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cognite logo

CogniteSdk for .NET

Build and Test codecov Nuget

CogniteSdk for .NET is a cross platform asynchronous SDK for accessing the Cognite Data Fusion API (v1) using .NET Standard 2.0 that works for all .NET implementations i.e both .NET Core and .NET Framework.

Unofficial: please note that this is an unofficial and community driven SDK. Feel free to open issues, or provide PRs if you want to improve the library.

The SDK may be used from both C# and F#.

  • C# SDK: The C# SDK is a fluent API using objects and method chaining. Errors will be raised as exceptions. The API is asynchronous and all API methods returns Task and is awaitable using async/await.

  • F# SDK: The F# API is written using plain asynchronous functions returning Task built on top of the Oryx HTTP handler library.

Supported Resources

Documentation

Installation

CogniteSdk is available as a NuGet package. To install:

Using Package Manager:

Install-Package CogniteSdk

Using .NET CLI:

dotnet add package CogniteSdk

Or directly in Visual Studio.

Quickstart

The SDK supports authentication through api-keys. The best way to use the SDK is by setting authentication values to environment values:

Using Windows Commands:

setx PROJECT=myprojet
setx API_KEY=mysecretkey

Using Shell:

export PROJECT=myprojet
export API_KEY=mysecretkey

All SDK methods are called with a Client object. A valid client requires:

  • API Key - key used for authentication with CDF.
  • Project Name - the name of your CDF project e.g publicdata.
  • App ID - an identifier for your application. It is a free text string. Example: asset-hierarchy-extractor
  • HTTP Client - The HttpClient that will be used for the remote connection. Having this separate from the SDK have many benefits like using e.g Polly for policy handling.
using CogniteSdk;

var apiKey = Environment.GetEnvironmentVariable("API_KEY");
var project = Environment.GetEnvironmentVariable("PROJECT");

using var httpClient = new HttpClient(handler);
var builder = new Client.Builder();
var client =
    builder
        .SetAppId("playground")
        .SetHttpClient(httpClient)
        .SetApiKey(apiKey)
        .SetProject(project)
        .Build();

// your logic using the client
var query = new Assets.AssetQuery
{
    Filter = new Assets.AssetFilter { Name = assetName }
};
var result = await client.Assets.ListAsync(query);

Examples

There are examples for both C# and F# in the Playground folder. To play with the example code, you need to set the CDF project and API key as environment variables.

Developing

Dotnet Tools

A dotnet tools manifest is used to version tools used by this repo. Install these tools with:

> dotnet tool restore

This will install Paket locally which is used for dependency management.

Dependencies

Dependencies for all projects are handled using Paket. To install dependencies:

> dotnet paket install

This will install the main dependencies and sub-dependencies. The main dependencies are:

Running tests locally

sh ./test.sh

For this script AAD env variables need to be defined: TEST_TENANT_ID_WRITE, TEST_CLIENT_ID_WRITE, TEST_CLIENT_SECRET_WRITE.

You also need read credentials for publicdata project TEST_TENANT_ID_READ, TEST_CLIENT_ID_READ, TEST_CLIENT_SECRET_READ.

Code of Conduct

This project follows https://www.contributor-covenant.org, see our Code of Conduct.

License

Apache v2, see LICENSE.

About

.NET SDK for Cognite Data Fusion (CDF)

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 71.0%
  • F# 28.9%
  • Shell 0.1%