Skylight Docs
Search…
Integration API / SDKs
The Skylight Integration API provides the ability to connect your Skylight applications to external systems. The APIs are offered as SDKs and are currently available for C#.
The SDKs are wrappers around APIs generated using OpenAPI Generator that provides functionality for querying information about applications and sessions, as well as event handling for session events.
The SDK takes care of fundamental aspects of Skylight integration code development that would otherwise be repeated between implementations, including:
    Authenticating with Skylight
    Refreshing access tokens when necessary
    Subscribing to MQTT topics
    Reconnecting to the MQTT broker when necessary
    Providing models for Skylight applications and sessions
While the syntax may differ between the various languages, the concepts and provided methods of the different SDKs strive to be as similar as possible.

Getting Started

C#
To use the C# SDK in your code, follow these steps:
    1.
    Ensure that .NET Core 3.1 is installed on your machine.
      dotnet --version should return 3.1.301 or higher
      dotnet nuget --version should return 5.6.0.5 or higher
    2.
    Scaffold out your project: dotnet new console -n myService cd myService
    3.
    Connect to the NuGet feed: https://pkgs.dev.azure.com/UpskillSDK/skylight-sdk/_packaging/release/nuget/v3/index.json -n skylightSdkRelease
      For Visual Studio, use the NuGet package manager to connect to this feed.
      For Visual Studio Code or other IDEs, connect to this feed by adding this feed in the nuget.config file, or by using the command: dotnet nuget add source https://pkgs.dev.azure.com/UpskillSDK/skylight-sdk/_packaging/release/nuget/v3/index.json -n skylightSdkRelease
    4.
    Install the Skylight SDK NuGet package:
      For Visual Studio, use the NuGet package manager to install the latest version from this feed.
      For Visual Studio Code or other IDEs, install the package by running dotnet add package Skylight.Sdk.

SDK Reference

The reference provides documentation on the SDK methods, events, and objects:

Example Code

C#
The following snippet showcases the self-contained main .cs file of a project that uses the C# SDK.
This example uses a configuration file to handle credentials.
In production scenarios, we suggest utilizing environment variables or some other more secure method for storing secrets.
If you wish to use the configuration code listed in this sample, add the ConfigurationManager package to your solution by running the command dotnet add package System.Configuration.ConfigurationManager
1
using System;
2
using System.IO;
3
using System.Timers;
4
using System.Dynamic;
5
using System.Configuration;
6
using System.Threading.Tasks;
7
using System.Collections.Generic;
8
using System.Collections.Specialized;
9
10
using System.Net;
11
using System.Net.Http;
12
using System.Net.Http.Headers;
13
14
using Skylight.Model;
15
using Skylight.Sdk;
16
using Newtonsoft.Json.Linq;
17
18
namespace SkylightSample
19
{
20
class Program : ISessionEventListener
21
{
22
// We'll store an instance of our Skylight.Sdk.Manager
23
static Manager _skyManager;
24
25
// These variables are used to store credentials and application information in config files. In a production setting, these should likely be stored/read as environment variables
26
static NameValueCollection _credentialsConfig, _applicationConfig;
27
28
// This is our main entry point
29
static async Task Main(string[] args)
30
{
31
// Retrieve our credentials and application configuration
32
SetupAppConfig();
33
34
// Create our manager
35
_skyManager = new Manager(new Program());
36
37
// Configure our credentials using one of three methods:
38
_skyManager.SetCredentials(_credentialsConfig["Username"], _credentialsConfig["Password"], _credentialsConfig["Realm"], _credentialsConfig["ApiUrl"], _credentialsConfig["MqttUrl"]);
39
40
// Configure manager after instantiation, here. Right now, this just sets the verbosity of the SDK.
41
_skyManager.SetVerbosity(Logger.Verbosity.Verbose);
42
43
// Connect our manager, which will connect us to Skylight APIs and MQTT.
44
await _skyManager.Connect();
45
46
// Run our various application and session method examples
47
//await RunApplicationExamples();
48
await RunSessionExamples();
49
50
//This keeps our program alive. Note that anything after this line will NOT get called. If we wish to use user input as our method of keeping the program alive, we should replace this line.
51
_skyManager.KeepAlive();
52
}
53
54
// This retrieves our credentials/application configuration -- in a product setting, this should likely read from environment variables
55
static void SetupAppConfig() {
56
//Open config
57
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
58
59
//Update appconfig file path
60
config.AppSettings.File = Path.Join("config", "App.config");
61
62
//Save the configuration file.
63
config.Save(ConfigurationSaveMode.Modified);
64
65
//Force a reload in memory of the changed section.
66
ConfigurationManager.RefreshSection("applicationConfig");
67
ConfigurationManager.RefreshSection("credentialsConfig");
68
69
_credentialsConfig = ConfigurationManager.GetSection("credentialsConfig") as NameValueCollection;
70
_applicationConfig = ConfigurationManager.GetSection("applicationConfig") as NameValueCollection;
71
}
72
73
/*
74
Application and Session Method Examples
75
*/
76
static async Task RunApplicationExamples()
77
{
78
// Get Applications
79
Console.WriteLine("Get Applications");
80
var applications = await _skyManager.GetApplications();
81
foreach (var applicationFromList in applications)
82
{
83
Console.WriteLine(applicationFromList);
84
}
85
86
// Get Application
87
Console.WriteLine("Get Application");
88
var application = await _skyManager.GetApplication(_applicationConfig["Id"]);
89
Console.WriteLine(application);
90
91
// Get Application Roles
92
Console.WriteLine("Get Application Roles");
93
var applicationRoles = await _skyManager.GetApplicationRoles(_applicationConfig["Id"]);
94
foreach (var applicationRole in applicationRoles)
95
{
96
Console.WriteLine(applicationRole);
97
}
98
}
99
100
static async Task RunSessionExamples()
101
{
102
// Get Sessions
103
Console.WriteLine("Get Sessions");
104
var sessions = await _skyManager.GetSessions(_applicationConfig["Id"]);
105
foreach (var sessionFromApplication in sessions) {
106
Console.WriteLine(sessionFromApplication);
107
}
108
109
// Create Session
110
Console.WriteLine("Create Session");
111
var newSessionProperties = new Dictionary<string, string>();
112
newSessionProperties["customKey"] = "customValue";
113
var newSession = await _skyManager.CreateSession(_applicationConfig["Id"], "New Session", "This is a new session.", newSessionProperties);
114
Console.WriteLine(newSession);
115
116
// Patch Session
117
Console.WriteLine("Patch Session");
118
var sessionPatch = new SessionPatchRequest()
119
{
120
Name = "Patched Session",
121
Description = "This session has been patched."
122
};
123
await _skyManager.PatchSession(_applicationConfig["Id"], newSession.SessionId, sessionPatch);
124
125
// Get Session
126
Console.WriteLine("Get Session");
127
var patchedSession = await _skyManager.GetSession(_applicationConfig["Id"], newSession.SessionId);
128
Console.WriteLine(patchedSession);
129
130
// Update Session Name
131
Console.WriteLine("Update Session Name");
132
await _skyManager.UpdateSessionName(_applicationConfig["Id"], newSession.SessionId, "Latest Session");
133
134
// Update Session Description
135
Console.WriteLine("Update Session Description");
136
await _skyManager.UpdateSessionDescription(_applicationConfig["Id"], newSession.SessionId, "This session description has been updated.");
137
138
// Update Session Properties
139
Console.WriteLine("Update Session Properties");
140
var updatedSessionProperties = new Dictionary<string, string>();
141
updatedSessionProperties["anotherCustomKey"] = "anotherCustomValue";
142
await _skyManager.UpdateSessionProperties(_applicationConfig["Id"], newSession.SessionId, updatedSessionProperties);
143
144
// Patch Session Data
145
Console.WriteLine("Patch Session Data");
146
await _skyManager.PatchSessionData(_applicationConfig["Id"], newSession.SessionId, new Worklist("Worklist 0"));
147
148
// Get Session Data
149
Console.WriteLine("Get Session Data");
150
var worklist = await _skyManager.GetSessionData<Worklist>(_applicationConfig["Id"], newSession.SessionId);
151
Console.WriteLine(worklist);
152
153
// Add Session Participant
154
Console.WriteLine("Add Participant");
155
//await _skyManager.AddParticipant(_applicationConfig["Id"], newSession.SessionId, "dummy-group-id", SessionParticipantPostRequest.TypeEnum.Group);
156
157
// Close Session
158
Console.WriteLine("Close Session");
159
await _skyManager.CloseSession(_applicationConfig["Id"], newSession.SessionId);
160
161
}
162
163
/*
164
Event Listener Examples
165
*/
166
async Task ISessionEventListener.OnSessionCreated(SessionEventBase sessionEvent)
167
{
168
Console.WriteLine("Session created");
169
Console.WriteLine(sessionEvent.ToString());
170
var properties = sessionEvent.Session.Properties;
171
Console.WriteLine(properties.ToString());
172
foreach (KeyValuePair<string, string> kvp in properties)
173
{
174
Console.WriteLine("{"+kvp.Key + "," + kvp.Value+"}");
175
}
176
}
177
178
async Task ISessionEventListener.OnSessionPropertiesUpdated(SessionEventBase sessionEvent)
179
{
180
Console.WriteLine("Session properties updated: " + sessionEvent.SessionId);
181
Console.WriteLine(sessionEvent.ToString());
182
var properties = sessionEvent.Session.Properties;
183
Console.WriteLine(properties.ToString());
184
foreach (KeyValuePair<string, string> kvp in properties)
185
{
186
Console.WriteLine("{"+kvp.Key + "," + kvp.Value+"}");
187
}
188
}
189
190
async Task ISessionEventListener.OnSessionUpdated(SessionEventBase sessionEvent)
191
{
192
Console.WriteLine("Session updated");
193
Console.WriteLine(sessionEvent.ToString());
194
}
195
196
async Task ISessionEventListener.OnSessionClosed(SessionEventBase sessionEvent)
197
{
198
Console.WriteLine("Session closed: " + sessionEvent.SessionId);
199
Console.WriteLine(sessionEvent.ToString());
200
}
201
202
async Task ISessionEventListener.OnSessionDataUpdated(SessionEventBase sessionEvent)
203
{
204
Console.WriteLine("Session data updated");
205
Console.WriteLine(sessionEvent.ToString());
206
JObject data = sessionEvent.Data as JObject;
207
Console.WriteLine(data.ToString());
208
209
// Example of converting the JSON Object to our own class that we passed into the session data update
210
try {
211
Worklist worklist = data.ToObject<Worklist>();
212
Console.WriteLine("Our session data as a worklist object:");
213
Console.WriteLine(worklist.title);
214
} catch (Exception e) {
215
Console.Error.WriteLine(e);
216
}
217
}
218
219
async Task ISessionEventListener.OnSessionEventCreated(SessionEventBase sessionEvent)
220
{
221
Console.WriteLine("Session event created");
222
Console.WriteLine(sessionEvent.ToString());
223
}
224
}
225
226
// This is an example of an object used to represent a worklist
227
class Worklist {
228
public string title;
229
public List<Step> steps;
230
231
public Worklist(string title) {
232
this.title = title;
233
}
234
}
235
236
// This is an example of an object used to represent a step in worklist
237
class Step {
238
public string name;
239
public Step otherStep;
240
public void Hello() {
241
Console.WriteLine("Hi this is a step");
242
}
243
}
244
}
Copied!
Last modified 5mo ago