Refer to the test project for a short console application demonstrating the usage of the SDK.
Note: when referencing the smip.sdk accross solutions, the following packages need to get installed:
- GraphQL.Client
- GraphQL.Client.Serializer.Newtonsoft
- Microsoft.Extensions.Configuration.Binder
- Microsoft.Extensions.Configuration.EnvironmentVariables
- Microsoft.Extensions.Configuration.UserSecrets
- Newtonsoft.Json
- System.IdentityModel.Tokens.Jwt
We can use either an appsettings.json or a user secrets json file to store the required authenticator information, including:
- graphQlEndpoint
- clientId
- clientSecret
- role
- userName
SmipAuthenticator authenticator = config.GetRequiredSection("SMIP").Get<SmipAuthenticator>();A new instance is created with the authenticator object. The client automatically pulls a token if none is present or renews the token when an existing token is about to expire. Alternatively, we can explicitely pull a token:
SmipEntry aEntry = new SmipEntry(authenticator);
await aEntry.AuthorizeGraphQLClient();
Console.WriteLine(aEntry.tokenString);We have two methods to make requests: either get a JObject with the complete response or specify the node and have the response explicitely cast as a SMIP SDK object.
The following object types are included:
- Attribute
- Equipment
- MeasurementUnit
- Quantity
- Thing (the base class for most object types in the smip)
- TimeSeries (a time series record with timestamp, intvalue, and an example of timezone conversion using NodaTime)
The list can easily be extended as needed.
// get quantities
var aResult = await aEntry.GetGraphQLDataAsync("query q1{quantities{id displayName}}");
Console.WriteLine(JsonConvert.SerializeObject(aResult, Formatting.Indented));// get quantities as object
// here we return a List<SmipQuantity>
// note that each quantity can include units if they are included in the query
var allQuantities = await aEntry.GetGraphQLDataAsync<List<SmipQuantity>>(
"query q1{quantities{id displayName measurementUnits{displayName}}}",
"quantities"
);