-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathutility.ts
563 lines (505 loc) · 27.2 KB
/
utility.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
"use strict";
import { ResultWithHttpResponse } from "azure-iot-common";
import { ConnectionString as DeviceConnectionString, SharedAccessSignature as DeviceSharedAccessSignature } from "azure-iot-device";
import { ConnectionString, Registry, SharedAccessSignature, Twin } from "azure-iothub";
import { IotHubModels} from "@azure/arm-iothub";
import * as crypto from "crypto";
import * as fs from "fs";
import * as os from "os";
import * as path from "path";
import * as vscode from "vscode";
import { Constants } from "./constants";
import { DeviceItem } from "./Model/DeviceItem";
import { ModuleItem } from "./Model/ModuleItem";
import { CommandNode } from "./Nodes/CommandNode";
import { InfoNode } from "./Nodes/InfoNode";
import { INode } from "./Nodes/INode";
import { TelemetryClient } from "./telemetryClient";
import { ReceivedEventData, EventData } from "@azure/event-hubs";
import { AxiosRequestConfig, Method } from "axios";
import { AzureAccount } from "./azure-account.api";
import { CredentialStore } from "./credentialStore";
import { ResultWithIncomingMessage } from "azure-iothub/dist/interfaces";
export class Utility {
public static getConfiguration(): vscode.WorkspaceConfiguration {
return vscode.workspace.getConfiguration("azure-iot-toolkit");
}
public static async getConnectionString(id: string, name: string, askForConnectionString: boolean = true) {
const connectionString = await this.getConnectionStringWithId(id);
if (!connectionString && askForConnectionString) {
return this.setConnectionString(id, name);
}
return connectionString;
}
public static async setConnectionString(id: string, name: string) {
TelemetryClient.sendEvent("General.SetConfig.Popup");
return new Promise<string>((resolve, reject) => {
let value;
const input = vscode.window.createInputBox();
input.prompt = name;
input.placeholder = Constants.ConnectionStringFormat[id];
input.ignoreFocusOut = true;
input.onDidAccept(async () => {
value = input.value;
if (this.isValidConnectionString(id, value)) {
TelemetryClient.sendEvent("General.SetConfig.Done", { Result: "Success" });
await CredentialStore.setPassword(id, value);
if (id === Constants.IotHubConnectionStringKey) {
await Utility.deleteIoTHubInfo();
}
resolve(value);
input.dispose();
} else {
TelemetryClient.sendEvent("General.SetConfig.Done", { Result: "Fail" });
vscode.commands.executeCommand("markdown.showPreview", vscode.Uri.file(Constants.ExtensionContext.asAbsolutePath(path.join("resources", "iot-hub-connection-string.md"))));
input.validationMessage = `The format should be "${Constants.ConnectionStringFormat[id]}"`;
}
});
input.onDidHide(() => {
resolve();
input.dispose();
if (!value) {
this.showIoTHubInformationMessage();
}
});
input.show();
});
}
public static async getConnectionStringWithId(id: string) {
let configValue = await CredentialStore.getPassword(id);
if (!configValue) {
configValue = Utility.getConfiguration().get<string>(id);
}
if (!this.isValidConnectionString(id, configValue)) {
return null;
}
return configValue;
}
public static getConfig<T>(id: string): T {
const config = Utility.getConfiguration();
return config.get<T>(id);
}
public static getHostName(iotHubConnectionString: string): string {
const result = /^HostName=([^=]+);/.exec(iotHubConnectionString);
return result ? result[1] : "";
}
public static getIoTHubName(iotHubConnectionString: string): string {
const result = /^HostName=([^.]+)./.exec(iotHubConnectionString);
return result ? result[1] : "";
}
public static getPostfixFromHostName(hostName: string): string {
const result = /^[^.]+\.(.+)$/.exec(hostName);
return result ? result[1] : "";
}
public static hash(data: string): string {
return crypto.createHash("sha256").update(data).digest("hex");
}
public static generateSasTokenForService(iotHubConnectionString: string, expiryInHours = 1): string {
const connectionString = ConnectionString.parse(iotHubConnectionString);
const expiry = Math.floor(Date.now() / 1000) + expiryInHours * 60 * 60;
return SharedAccessSignature.create(connectionString.HostName, connectionString.SharedAccessKeyName, connectionString.SharedAccessKey, expiry).toString();
}
public static generateSasTokenForDevice(deviceConnectionString: string, expiryInHours = 1): string {
const connectionString = DeviceConnectionString.parse(deviceConnectionString);
const expiry = Math.floor(Date.now() / 1000) + expiryInHours * 60 * 60;
return DeviceSharedAccessSignature.create(connectionString.HostName, connectionString.DeviceId, connectionString.SharedAccessKey, expiry).toString();
}
public static adjustTerminalCommand(command: string): string {
return (os.platform() === "linux" || os.platform() === "darwin") ? `sudo ${command}` : command;
}
public static adjustFilePath(filePath: string): string {
if (os.platform() !== "win32") {
return filePath;
}
const windowsShell = vscode.workspace.getConfiguration("terminal").get<string>("integrated.shell.windows");
if (!windowsShell) {
return filePath;
}
const terminalRoot = Utility.getConfiguration().get<string>("terminalRoot");
if (terminalRoot) {
return filePath.replace(/^([A-Za-z]):/, (match, p1) => `${terminalRoot}${p1.toLowerCase()}`).replace(/\\/g, "/");
}
const winshellLowercase = windowsShell.toLowerCase();
if (winshellLowercase.indexOf("bash") > -1 && winshellLowercase.indexOf("git") > -1) {
// Git Bash
return filePath.replace(/^([A-Za-z]):/, (match, p1) => `/${p1.toLowerCase()}`).replace(/\\/g, "/");
}
if (winshellLowercase.indexOf("bash") > -1 && winshellLowercase.indexOf("windows") > -1) {
// Bash on Ubuntu on Windows
return filePath.replace(/^([A-Za-z]):/, (match, p1) => `/mnt/${p1.toLowerCase()}`).replace(/\\/g, "/");
}
return filePath;
}
public static getDefaultPath(filename?: string): vscode.Uri {
if (filename) {
const defaultPath: string = vscode.workspace.workspaceFolders ? path.join(vscode.workspace.workspaceFolders[0].uri.fsPath, filename) : `*/${filename}`;
return vscode.Uri.file(defaultPath);
} else {
return vscode.workspace.workspaceFolders ? vscode.workspace.workspaceFolders[0].uri : undefined;
}
}
public static writeFile(filePath: vscode.Uri, content: string): void {
fs.writeFile(filePath.fsPath, content, (err) => {
if (err) {
vscode.window.showErrorMessage(err.message);
return;
}
vscode.window.showTextDocument(filePath);
});
}
public static async getModuleItems(iotHubConnectionString: string, deviceItem: DeviceItem, context: vscode.ExtensionContext) {
const modules = await Utility.getModules(iotHubConnectionString, deviceItem.deviceId);
return modules.map((module) => {
const isConnected = module.connectionState === "Connected";
const state = isConnected ? "on" : "off";
const iconPath = context.asAbsolutePath(path.join("resources", `module-${state}.svg`));
return new ModuleItem(deviceItem, module.moduleId, module.connectionString, module.connectionState, null, iconPath, "module");
});
}
public static async getModuleItemsForEdge(iotHubConnectionString: string, deviceItem: DeviceItem, context: vscode.ExtensionContext) {
/**
* modules: contains connection state of each module
* edgeAgent.properties.reported: contains runtime status of each module
*/
const [modules, edgeAgent] = await Promise.all([
Utility.getModules(iotHubConnectionString, deviceItem.deviceId),
Utility.getModuleTwin(iotHubConnectionString, deviceItem.deviceId, "$edgeAgent"),
]);
const desiredTwin = (edgeAgent as any).properties.desired;
const reportedTwin = (edgeAgent as any).properties.reported;
return modules.map((module) => {
let isConnected = module.connectionState === "Connected";
// Due to https://github.com/Azure/iotedge/issues/39, use $edgeAgent's connectionState for $edgeHub as workaround
if (module.moduleId === "$edgeHub") {
isConnected = isConnected || (edgeAgent as any).connectionState === "Connected";
if (isConnected) {
module.connectionState = "Connected";
}
}
const state = isConnected ? "on" : "off";
const iconPath = context.asAbsolutePath(path.join("resources", `module-${state}.svg`));
if (module.moduleId.startsWith("$")) {
const moduleId = module.moduleId.substring(1);
if (desiredTwin.systemModules && desiredTwin.systemModules[moduleId]) {
return new ModuleItem(deviceItem, module.moduleId, module.connectionString, module.connectionState,
reportedTwin ? this.getModuleRuntimeStatus(moduleId, reportedTwin.systemModules) : undefined, iconPath, "edge-module");
}
} else {
if (desiredTwin.modules && desiredTwin.modules[module.moduleId]) {
return new ModuleItem(deviceItem, module.moduleId, module.connectionString, module.connectionState,
reportedTwin ? this.getModuleRuntimeStatus(module.moduleId, reportedTwin.modules) : undefined, iconPath, "edge-module");
}
}
const moduleType = module.moduleId.startsWith("$") ? "edge-module" : "module";
// If Module Id starts with "$", then it is a IoT Edge System Module.
// Otherwise, if a Module does not exist in desired properties of edgeAgent, then it is a Module Identity.
return new ModuleItem(deviceItem, module.moduleId, module.connectionString, module.connectionState, null, iconPath, moduleType);
}).filter((module) => module);
}
public static async getModules(iotHubConnectionString: string, deviceId: string): Promise<any[]> {
const registry: Registry = Registry.fromConnectionString(iotHubConnectionString);
const hostName: string = Utility.getHostName(iotHubConnectionString);
return new Promise<any[]>((resolve, reject) => {
registry.getModulesOnDevice(deviceId, (err, modules) => {
if (err) {
reject(err);
} else {
resolve(modules.map((module) => {
if (module.authentication.symmetricKey.primaryKey) {
(module as any).connectionString = Utility.createModuleConnectionString(hostName, deviceId, module.moduleId, module.authentication.symmetricKey.primaryKey);
}
return module;
}));
}
});
});
}
public static async getModuleTwin(iotHubConnectionString: string, deviceId: string, moduleId: string): Promise<Twin> {
const registry: Registry = Registry.fromConnectionString(iotHubConnectionString);
return ((await registry.getModuleTwin(deviceId, moduleId)) as ResultWithHttpResponse<Twin>).responseBody;
}
public static async updateModuleTwin(iotHubConnectionString: string, deviceId: string, moduleId: string, twin: any): Promise<void> {
const registry: Registry = Registry.fromConnectionString(iotHubConnectionString);
await registry.updateModuleTwin(deviceId, moduleId, twin, "*");
}
public static async readFromActiveFile(fileName: string): Promise<string> {
const activeTextEditor = vscode.window.activeTextEditor;
if (!activeTextEditor || !activeTextEditor.document || path.basename(activeTextEditor.document.fileName) !== fileName) {
vscode.window.showWarningMessage(`Please open ${fileName} and try again.`);
return "";
}
const document = activeTextEditor.document;
await document.save();
return document.getText();
}
public static writeJson(filePath: string, data) {
const directory = path.dirname(filePath);
if (!fs.existsSync(directory)) {
fs.mkdirSync(directory);
}
fs.writeFileSync(filePath, `${JSON.stringify(data, null, 4)}`);
}
public static async getInputDevice(deviceItem: DeviceItem, eventName: string, onlyEdgeDevice: boolean = false, iotHubConnectionString?: string): Promise<DeviceItem> {
if (!deviceItem) {
if (eventName) {
TelemetryClient.sendEvent(eventName, { entry: "commandPalette" });
}
if (!iotHubConnectionString) {
iotHubConnectionString = await Utility.getConnectionString(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
if (!iotHubConnectionString) {
return null;
}
}
const deviceList: Promise<DeviceItem[]> = Utility.getFilteredDeviceList(iotHubConnectionString, onlyEdgeDevice);
deviceItem = await vscode.window.showQuickPick(deviceList, { placeHolder: "Select an IoT Hub device" });
return deviceItem;
} else {
if (eventName) {
TelemetryClient.sendEvent(eventName, { entry: "contextMenu", deviceType: deviceItem.contextValue });
}
return deviceItem;
}
}
public static async getDeviceList(iotHubConnectionString: string, context?: vscode.ExtensionContext): Promise<DeviceItem[]> {
const [deviceList, edgeDeviceIdSet] = await Promise.all([Utility.getIoTDeviceList(iotHubConnectionString), Utility.getEdgeDeviceIdSet(iotHubConnectionString)]);
return deviceList.map((device) => {
const isConnected = device.connectionState.toString() === "Connected";
const state: string = isConnected ? "on" : "off";
let deviceType: string;
if (edgeDeviceIdSet.has(device.deviceId)) {
deviceType = "edge";
device.contextValue = "edge";
device.tooltip = "";
} else {
deviceType = "device";
}
if (context) {
device.iconPath = context.asAbsolutePath(path.join("resources", `${deviceType}-${state}.svg`));
}
return device;
});
}
public static async getNoneEdgeDeviceIdList(iotHubConnectionString: string): Promise<string[]> {
const noneEdgeDevices = await this.queryDeviceTwins(iotHubConnectionString, false);
const deviceIdList = [];
for (const noneEdgeDevice of noneEdgeDevices) {
deviceIdList.push(noneEdgeDevice.deviceId);
}
return deviceIdList;
}
public static isValidTargetCondition(value: string): boolean {
return /^(\*|((deviceId|tags\..+|properties\.reported\..+).*=.+))$/.test(value);
}
public static getResourceGroupNameFromId(resourceId: string): string {
const result = /resourceGroups\/([^/]+)\//.exec(resourceId);
return result[1];
}
public static createModuleConnectionString(hostName: string, deviceId: string, moduleId: string, sharedAccessKey: string): string {
return `HostName=${hostName};DeviceId=${deviceId};ModuleId=${moduleId};SharedAccessKey=${sharedAccessKey}`;
}
public static getDefaultTreeItems(): INode[] {
TelemetryClient.sendEvent("General.Load.DefaultTreeItems");
const items = [];
items.push(new CommandNode("-> Set IoT Hub Connection String", "azure-iot-toolkit.setIoTHubConnectionString"));
items.push(new CommandNode("-> Select IoT Hub", "azure-iot-toolkit.selectIoTHub"));
items.push(new CommandNode("-> Create IoT Hub", "azure-iot-toolkit.createIoTHub"));
return items;
}
public static getErrorMessageTreeItems(item: string, error: string): INode[] {
const items = [];
items.push(new InfoNode(`Failed to list ${item}`));
items.push(new InfoNode(`Error: ${error}`));
items.push(new InfoNode(`Try another IoT Hub?`));
items.push(...this.getDefaultTreeItems());
return items;
}
public static parseReportedSamplingMode(twin: any): boolean {
const reportedDistributedTwinObject = twin.properties.reported[Constants.DISTRIBUTED_TWIN_NAME];
if (reportedDistributedTwinObject.sampling_mode === undefined || reportedDistributedTwinObject.sampling_mode.value === undefined) {
return undefined;
}
return twin.properties.reported[Constants.DISTRIBUTED_TWIN_NAME].sampling_mode.value === 1;
}
public static parseReportedSamplingRate(twin: any): number {
const reportedDistributedTwinObject = twin.properties.reported[Constants.DISTRIBUTED_TWIN_NAME];
if (reportedDistributedTwinObject.sampling_rate === undefined) {
return undefined;
}
return twin.properties.reported[Constants.DISTRIBUTED_TWIN_NAME].sampling_rate.value;
}
public static parseDesiredSamplingMode(twin: any): boolean {
if (twin.properties.desired[Constants.DISTRIBUTED_TWIN_NAME].sampling_mode === undefined) {
return undefined;
}
return twin.properties.desired[Constants.DISTRIBUTED_TWIN_NAME].sampling_mode === 1;
}
public static parseDesiredSamplingRate(twin: any): number {
return twin.properties.desired[Constants.DISTRIBUTED_TWIN_NAME].sampling_rate;
}
public static async getTwin(registry: Registry, deviceId: string): Promise<any> {
const result = await registry.getTwin(deviceId);
return result.responseBody;
}
public static getAzureAccountApi(): AzureAccount {
return vscode.extensions.getExtension<AzureAccount>("ms-vscode.azure-account")!.exports;
}
public static getMessageFromEventData(message: any): any {
const config = Utility.getConfiguration();
const showVerboseMessage = config.get<boolean>("showVerboseMessage");
let result;
const body = Utility.tryGetStringFromCharCode(message.body);
if (showVerboseMessage) {
result = {
body,
applicationProperties: message.applicationProperties,
annotations: message.annotations,
properties: message.properties,
};
} else if (message.applicationProperties && Object.keys(message.applicationProperties).length > 0) {
result = {
body,
applicationProperties: message.applicationProperties,
};
} else {
result = body;
}
return result;
}
public static getTimeMessageFromEventData(message: ReceivedEventData): string {
return message.enqueuedTimeUtc ? `[${message.enqueuedTimeUtc.toLocaleTimeString("en-US")}] ` : "";
}
public static async storeIoTHubInfo(subscriptionId: string, iotHubDescription: IotHubModels.IotHubDescription) {
await Constants.ExtensionContext.globalState.update(Constants.StateKeySubsID, subscriptionId);
await Constants.ExtensionContext.globalState.update(Constants.StateKeyIoTHubID, iotHubDescription.id);
}
public static async deleteIoTHubInfo() {
await Constants.ExtensionContext.globalState.update(Constants.StateKeySubsID, "");
await Constants.ExtensionContext.globalState.update(Constants.StateKeyIoTHubID, "");
}
public static async getFilteredDeviceList(iotHubConnectionString: string, onlyEdgeDevice: boolean): Promise<DeviceItem[]> {
if (onlyEdgeDevice) {
const [deviceList, edgeDeviceIdSet] = await Promise.all([Utility.getIoTDeviceList(iotHubConnectionString), Utility.getEdgeDeviceIdSet(iotHubConnectionString)]);
return deviceList.filter((device) => edgeDeviceIdSet.has(device.deviceId));
} else {
return Utility.getIoTDeviceList(iotHubConnectionString);
}
}
public static generateIoTHubAxiosRequestConfig(iotHubConnectionString: string, url: string, method: Method, data?: any): AxiosRequestConfig {
return {
url,
method,
baseURL: `https://${Utility.getHostName(iotHubConnectionString)}`,
headers: {
Authorization: Utility.generateSasTokenForService(iotHubConnectionString),
},
data,
};
}
public static getReportedInterfacesFromDigitalTwin(interfaces) {
return interfaces &&
interfaces.interfaces &&
interfaces.interfaces[Constants.modelDiscoveryInterfaceName] &&
interfaces.interfaces[Constants.modelDiscoveryInterfaceName].properties &&
interfaces.interfaces[Constants.modelDiscoveryInterfaceName].properties.modelInformation &&
interfaces.interfaces[Constants.modelDiscoveryInterfaceName].properties.modelInformation.reported &&
interfaces.interfaces[Constants.modelDiscoveryInterfaceName].properties.modelInformation.reported.value &&
interfaces.interfaces[Constants.modelDiscoveryInterfaceName].properties.modelInformation.reported.value.interfaces;
}
private static tryGetStringFromCharCode(source) {
if (source instanceof Uint8Array) {
try {
source = String.fromCharCode.apply(null, source);
} catch (e) {
}
}
return source;
}
private static async getIoTDeviceList(iotHubConnectionString: string): Promise<DeviceItem[]> {
if (!iotHubConnectionString) {
return null;
}
const registry: Registry = Registry.fromConnectionString(iotHubConnectionString);
const devices: DeviceItem[] = [];
const hostName: string = Utility.getHostName(iotHubConnectionString);
return new Promise<DeviceItem[]>((resolve, reject) => {
registry.list((err, deviceList) => {
if (err) {
reject(err);
} else {
deviceList.forEach((device, index) => {
let deviceConnectionString: string = "";
if (device.authentication.SymmetricKey.primaryKey != null) {
deviceConnectionString = DeviceConnectionString.createWithSharedAccessKey(hostName, device.deviceId,
device.authentication.SymmetricKey.primaryKey);
} else if (device.authentication.x509Thumbprint.primaryThumbprint != null) {
deviceConnectionString = DeviceConnectionString.createWithX509Certificate(hostName, device.deviceId);
}
devices.push(new DeviceItem(device.deviceId,
deviceConnectionString,
null,
device.connectionState.toString(),
null));
});
resolve(devices.sort((a: DeviceItem, b: DeviceItem) => { return a.deviceId.localeCompare(b.deviceId); }));
}
});
});
}
private static async getEdgeDeviceIdSet(iotHubConnectionString: string): Promise<Set<string>> {
const edgeDevices = await Utility.queryDeviceTwins(iotHubConnectionString, true);
const set = new Set<string>();
for (const edgeDevice of edgeDevices) {
set.add(edgeDevice.deviceId);
}
return set;
}
private static async queryDeviceTwins(iotHubConnectionString: string, isEdge: boolean): Promise<Twin[]> {
const registry: Registry = Registry.fromConnectionString(iotHubConnectionString);
const query = registry.createQuery("SELECT * FROM DEVICES where capabilities.iotEdge=" + isEdge);
return ((await query.nextAsTwin()) as ResultWithIncomingMessage<Twin[]>).result;
}
private static showIoTHubInformationMessage(): void {
const config = Utility.getConfiguration();
const showIoTHubInfo = config.get<boolean>(Constants.ShowIoTHubInfoKey);
if (showIoTHubInfo) {
const GoToAzureRegistrationPage = "Go to Azure registration page";
const GoToAzureIoTHubPage = "Go to Azure IoT Hub page";
const DoNotShowAgain = "Don't show again";
vscode.window.showInformationMessage("Don't have Azure IoT Hub? Register a free Azure account to get a free one.",
GoToAzureRegistrationPage, GoToAzureIoTHubPage, DoNotShowAgain).then((selection) => {
switch (selection) {
case GoToAzureRegistrationPage:
vscode.commands.executeCommand("vscode.open",
vscode.Uri.parse(`https://azure.microsoft.com/en-us/free/?WT.mc_id=${Constants.CampaignID}`));
TelemetryClient.sendEvent("General.Open.AzureRegistrationPage");
break;
case GoToAzureIoTHubPage:
vscode.commands.executeCommand("vscode.open",
vscode.Uri.parse(`https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-get-started?WT.mc_id=${Constants.CampaignID}`));
TelemetryClient.sendEvent("General.Open.AzureIoTHubPage");
break;
case DoNotShowAgain:
config.update(Constants.ShowIoTHubInfoKey, false, true);
TelemetryClient.sendEvent("General.IoTHubInfo.DoNotShowAgain");
break;
default:
}
});
}
}
private static isValidConnectionString(id: string, value: string): boolean {
if (!value) {
return false;
}
return Constants.ConnectionStringRegex[id].test(value);
}
private static getModuleRuntimeStatus(moduleId: string, modules): string {
if (modules && modules[moduleId]) {
return modules[moduleId].runtimeStatus;
} else {
return undefined;
}
}
}