.NET SDK
Switch's official .NET client library for OpenADR VTN.
Overview
The OpenADR 3 VTN Client SDK for .NET enables applications to interact with the Switch OpenADR 3 VTN API from .NET using C# and other .NET languages such as F#, and VB.NET. The SDK itself is written in C#, and some of its idiomatic patterns reflect that choice. It offers an asynchronous API based on the Task-based Asynchronous Pattern (TAP).
Requirements
In order to use this SDK in your application ensure you have installed:
Installation
This C# SDK client is provided as is and it is used in the .NET environment. It contains wrapper classes that you can use to call an OpenADR v3 Virtual Top Node (aka VTN) API from your application without having to deal with HTTP requests and responses. The SDK is used by the BL and/or VEN components which need to talk to an OpenADR VTN.
Install using Visual Studio
In Solution Explorer, right-click the Dependecies on the project and select Manage Nuget Packages…
On the Browse tab search for OpenAdr.Client. Select the OpenAdr.Client package from the list, then click Install.
Install using Package Manager Console
From the Visual Studio menu bar, click Tools
Select NuGet Package Manager > Package Manager Console.
In the console, enter the following package installation command to install the latest version:
Install using dotnet CLI
Open a command line and switch to the directory that contains your project file (.csproj).
Use the following command to install the latest version of OpenAdr.Client package to that project:
Usage
Prerequisites
Before using and configuring the SDK in your application, you need to:
Create VTN credential client for your application as desribed in Create credentials client.
Note the VTN URL, for the selected environment under VTN Endpoint.
Note the Token Endpoint and Scope for the selected environment under Token Endpoint.
Having this information you are ready to start configuring your application.
Step by Step
Create new console application
Configure your application to use the SDK. The easiest way to configure the SDK in your client application is to add and use the
appsettings.json
file. Ensure that you have the following configuration available in your settings file (replace the values for ClientId and ClientSecret with the ones that you got when creating your VTN credential client):Install the following NuGet packages to enable additional functionalities in your client application:
Sample
Program.cs
for your client application will look like the following:Create new hosted service which will repesent your client (aka VEN):
Register your service in
Program.cs
insideConfigureServices
method of the host builder and start it:
Last updated
Was this helpful?