Skip to content

Commit

Permalink
integrate module twin support (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
adashen authored Apr 8, 2019
1 parent f9e1f69 commit e60c007
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/common/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,9 @@ export class Configuration {
public static async setWorkspaceConfigurationProperty(id: string, value: any): Promise<void> {
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;
}
}
8 changes: 4 additions & 4 deletions src/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@ export class Constants {
public static amlApiVersion: string = "2018-03-01-preview";

public static needSimulatorInstalledMsg = "You must have the 'iotedgehubdev' tool installed for IoT Edge Simulator.";
public static updateSimulatorMsg = "Update your 'iotedgehubdev' tool to the latest for the best experience.";
public static updateSimulatorMsg = "Update your 'iotedgehubdev' tool to the latest for the best experience for IoT Edge Simulator.";
public static failedInstallSimulator = "Failed to install 'iotedgehubdev' tool because of error:";
public static outputNoSimulatorMsg = "Cannot execute command since 'iotedgehubdev' is not installed. Please install it first.";
public static pipNotFoundMsg = "'pip' not found. Cannot install 'iotedgehubdev' tool. Please install it manually.";
public static installFailedMsg = "'iotedgehubdev' tool installation has failed. Please install it manually.";
public static outputNoSimulatorMsg = "Cannot execute command since 'iotedgehubdev' is not installed. Please install it first for IoT Edge Simulator.";
public static pipNotFoundMsg = "'pip' not found. Cannot install 'iotedgehubdev' tool. Please install it manually for IoT Edge Simulator.";
public static installFailedMsg = "'iotedgehubdev' tool installation has failed. Please install it manually for IoT Edge Simulator.";
public static installManuallyMsg = "Please install 'iotedgehubdev' tool first for IoT Edge Simulator.";
public static skipForNow = "Skip for Now";
public static learnMore = "Learn More";
Expand Down
21 changes: 20 additions & 1 deletion src/edge/simulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,14 @@ export class Simulator {
return await this.callWithInstallationCheck(outputChannel, async () => {
deviceItem = await Utility.getInputDevice(deviceItem, outputChannel);
if (deviceItem) {
Executor.runInTerminal(Utility.adjustTerminalCommand(`iotedgehubdev setup -c "${deviceItem.connectionString}"`));
let commandStr = `iotedgehubdev setup -c "${deviceItem.connectionString}"`;
if (await this.isModuleTwinSupported()) {
const iotHubConnectionStr = Configuration.getIotHubConnectionString();
if (iotHubConnectionStr) {
commandStr = `${commandStr} -i "${iotHubConnectionStr}"`;
}
}
Executor.runInTerminal(Utility.adjustTerminalCommand(commandStr));
}
});
}
Expand Down Expand Up @@ -216,6 +223,18 @@ export class Simulator {
});
}

private async isModuleTwinSupported(): Promise<boolean> {
let isSupported = false;
try {
const output = await Executor.executeCMD(undefined, "iotedgehubdev", { shell: true }, "--version");
const version: string | null = Simulator.extractVersion(output);
if (version && semver.valid(version)) {
isSupported = semver.gte(version, "0.8.0");
}
} catch (err) {}
return isSupported;
}

private constructRunCmd(deployFile: string): string {
return Utility.adjustTerminalCommand(`iotedgehubdev start -d "${deployFile}" -v`);
}
Expand Down

0 comments on commit e60c007

Please sign in to comment.