in src/simulator.ts [129:192]
public async launch(deviceItem: DeviceItem): Promise<void> {
const deviceConnectionStrings = [];
if (this.isProcessing()) {
this.closeDuration = 3500;
await this.showWebview(false);
this.telemetry(Constants.SimulatorLaunchEvent, true);
await this.delay(this.closeDuration);
this.closeDuration = 0;
} else {
this.iotHubConnectionString = await Utility.getConnectionString(
Constants.IotHubConnectionStringKey,
Constants.IotHubConnectionStringTitle,
true,
);
if (deviceItem) {
const hostName = ConnectionString.parse(this.iotHubConnectionString)
.HostName;
const hostNamePersisted = this.persistedInputs.hostName;
deviceConnectionStrings.push(deviceItem.connectionString);
const deviceConnectionStringsPersisted = this.persistedInputs
.deviceConnectionStrings;
await this.showWebview(
hostName !== hostNamePersisted ||
deviceConnectionStrings !== deviceConnectionStringsPersisted,
hostName,
deviceConnectionStrings,
);
this.telemetry(Constants.SimulatorLaunchEvent, true);
} else {
// Exit when no connection string found or the connection string is invalid.
if (!this.iotHubConnectionString) {
const errorMessage = "Failed to launch Send D2C Messages webview: No IoT Hub Connection String Found.";
vscode.window.showErrorMessage(errorMessage);
this.telemetry(Constants.SimulatorLaunchEvent, false, {
error: errorMessage,
});
return;
}
try {
const deviceList: vscode.TreeItem[] = await Utility.getDeviceList(this.iotHubConnectionString, Constants.ExtensionContext);
deviceList.map((item) => new DeviceNode(item as DeviceItem));
} catch (err) {
vscode.window.showErrorMessage("Failed to launch Send D2C Messages webview: " + err.message);
this.telemetry(Constants.SimulatorLaunchEvent, false, {
error: "Failed to launch Send D2C Messages webview: " + err.message,
});
return;
}
const hostName = ConnectionString.parse(this.iotHubConnectionString)
.HostName;
const hostNamePersisted = this.persistedInputs.hostName;
const deviceConnectionStringsPersisted = this.persistedInputs
.deviceConnectionStrings;
await this.showWebview(
hostName !== hostNamePersisted ||
deviceConnectionStringsPersisted.length !== 0,
hostName,
deviceConnectionStrings,
);
this.telemetry(Constants.SimulatorLaunchEvent, true);
}
vscode.commands.executeCommand("azure-iot-toolkit.refresh");
}
}