Read connection string from Toolkit, rename 'tempSensor' to 'Simulate… (#477)

* Read connection string from Toolkit, rename 'tempSensor' to 'SimulatedTemperatureSensor'

* Resolve comments
This commit is contained in:
Jun Han 2019-07-11 00:18:38 -05:00 коммит произвёл GitHub
Родитель 522c55a90b
Коммит 3c4a159900
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
6 изменённых файлов: 26 добавлений и 15 удалений

Просмотреть файл

@ -1,5 +1,6 @@
"use strict";
import * as vscode from "vscode";
import { Utility } from "./utility";
export class Configuration {
public static getConfiguration(): vscode.WorkspaceConfiguration {
@ -18,8 +19,13 @@ export class Configuration {
await Configuration.getConfiguration().update(id, value, false);
}
public static getIotHubConnectionString(): string | undefined {
const toolkitConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("azure-iot-toolkit");
return toolkitConfig ? toolkitConfig.get("iotHubConnectionString") : undefined;
public static async getIotHubConnectionString(): Promise<string | undefined> {
const toolkit = Utility.getToolkit();
try {
return toolkit.exports.azureIoTExplorer.getIotHubConnectionString();
} catch (error) {
const toolkitConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("azure-iot-toolkit");
return toolkitConfig ? toolkitConfig.get("iotHubConnectionString") : undefined;
}
}
}

Просмотреть файл

@ -418,16 +418,21 @@ export class Utility {
return deviceItem;
}
const toolkit = vscode.extensions.getExtension("vsciot-vscode.azure-iot-toolkit");
if (toolkit === undefined) {
throw new Error("Error loading Azure IoT Toolkit extension");
}
const toolkit = Utility.getToolkit();
// TODO: only get Edge devices when Toolkit API supports this parameter
deviceItem = await toolkit.exports.azureIoTExplorer.getDevice(undefined, undefined, outputChannel);
return deviceItem;
}
public static getToolkit(): vscode.Extension<any> {
const toolkit = vscode.extensions.getExtension("vsciot-vscode.azure-iot-toolkit");
if (toolkit === undefined) {
throw new Error("Error loading Azure IoT Toolkit extension");
}
return toolkit;
}
public static async waitForAzLogin(azureAccount: AzureAccount): Promise<void> {
if (!(await azureAccount.waitForLogin())) {
await vscode.commands.executeCommand("azure-account.askForLogin");

Просмотреть файл

@ -415,10 +415,10 @@ export class EdgeManager {
createOptions: {},
},
};
modules.tempSensor = tempSensor;
modules.SimulatedTemperatureSensor = tempSensor;
const tempSensorToModule = `sensorTo${moduleInfo.moduleName}`;
routes[tempSensorToModule] =
`FROM /messages/modules/tempSensor/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/${moduleInfo.moduleName}/inputs/input1\")`;
`FROM /messages/modules/SimulatedTemperatureSensor/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/${moduleInfo.moduleName}/inputs/input1\")`;
}
await fse.writeFile(templateFile, JSON.stringify(templateJson, null, 2), { encoding: "utf8" });
return {

Просмотреть файл

@ -163,7 +163,7 @@ export class Simulator {
if (deviceItem) {
let commandStr = `iotedgehubdev setup -c "${deviceItem.connectionString}"`;
if (await this.isModuleTwinSupported()) {
const iotHubConnectionStr = Configuration.getIotHubConnectionString();
const iotHubConnectionStr = await Configuration.getIotHubConnectionString();
if (iotHubConnectionStr) {
commandStr = `${commandStr} -i "${iotHubConnectionStr}"`;
}

Просмотреть файл

@ -21,7 +21,7 @@ suite("utility tests", () => {
const generatedObj = JSON.parse(generated);
assert.equal(generatedObj.modulesContent
.$edgeAgent["properties.desired"]
.modules.tempSensor.settings.image, imageString);
.modules.SimulatedTemperatureSensor.settings.image, imageString);
}).timeout(60 * 1000);
test("expandModules", async () => {
@ -38,7 +38,7 @@ suite("utility tests", () => {
test("convertCreateOptions", async () => {
const input: string = await fse.readFile(path.resolve(__dirname, "../../testResources/deployment.template.json"), "utf8");
let deployment = JSON.parse(input);
const oldOptionObj = deployment.modulesContent.$edgeAgent["properties.desired"].modules.tempSensor.settings.createOptions;
const oldOptionObj = deployment.modulesContent.$edgeAgent["properties.desired"].modules.SimulatedTemperatureSensor.settings.createOptions;
deployment = Utility.convertCreateOptions(deployment);
const depStr = JSON.stringify(deployment, null, 2);
assert.equal(
@ -46,7 +46,7 @@ suite("utility tests", () => {
deployment.modulesContent.$edgeAgent["properties.desired"].systemModules.edgeHub.settings.createOptions,
);
const settings = deployment.modulesContent.$edgeAgent["properties.desired"].modules.tempSensor.settings;
const settings = deployment.modulesContent.$edgeAgent["properties.desired"].modules.SimulatedTemperatureSensor.settings;
assert.equal(settings.hasOwnProperty("createOptions"), true);
assert.equal(settings.hasOwnProperty("createOptions01"), true);
assert.equal(settings.hasOwnProperty("createOptions02"), true);

Просмотреть файл

@ -37,7 +37,7 @@
}
},
"modules": {
"tempSensor": {
"SimulatedTemperatureSensor": {
"version": "1.0",
"type": "docker",
"status": "running",
@ -137,7 +137,7 @@
"properties.desired": {
"schemaVersion": "1.0",
"routes": {
"sensorToFilter": "FROM /messages/modules/tempSensor/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/%MODULE%/inputs/input1\")",
"sensorToFilter": "FROM /messages/modules/SimulatedTemperatureSensor/outputs/temperatureOutput INTO BrokeredEndpoint(\"/modules/%MODULE%/inputs/input1\")",
"filterToIoTHub": "FROM /messages/modules/samplemodule/outputs/output1 INTO $upstream"
},
"storeAndForwardConfiguration": {