Enbale TSLint and fix code per TSLint

This commit is contained in:
formulahendry 2017-03-01 15:58:16 +08:00
Родитель f47dda4d64
Коммит e50eedbce1
14 изменённых файлов: 222 добавлений и 209 удалений

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

@ -18,4 +18,5 @@ install:
- npm run vscode:prepublish
script:
- npm run tslint
- npm test --silent

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

@ -263,14 +263,16 @@
"scripts": {
"vscode:prepublish": "tsc -p ./",
"compile": "tsc -watch -p ./",
"postinstall": "node ./node_modules/vscode/bin/install"
"postinstall": "node ./node_modules/vscode/bin/install",
"tslint": "tslint -t verbose src/**/*.ts"
},
"devDependencies": {
"typescript": "^2.0.3",
"vscode": "^1.0.0",
"mocha": "^2.3.3",
"@types/mocha": "^2.2.32",
"@types/node": "^6.0.40",
"@types/mocha": "^2.2.32"
"mocha": "^2.3.3",
"tslint": "^4.5.1",
"typescript": "^2.0.3",
"vscode": "^1.0.0"
},
"dependencies": {
"applicationinsights": "^0.16.0",

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

@ -1,17 +1,16 @@
'use strict';
import * as vscode from 'vscode';
import { Utility } from './utility';
const appInsights = require("applicationinsights");
"use strict";
import * as vscode from "vscode";
import { Utility } from "./utility";
import appInsights = require("applicationinsights");
export class AppInsightsClient {
private _client;
private _enableAppInsights;
constructor() {
this._client = appInsights.getClient('6ada6440-d926-4331-b914-d8f1ea3b012f');
this._client = appInsights.getClient("6ada6440-d926-4331-b914-d8f1ea3b012f");
let config = Utility.getConfiguration();
this._enableAppInsights = config.get<boolean>('enableAppInsights');
this._enableAppInsights = config.get<boolean>("enableAppInsights");
}
public sendEvent(eventName: string, properties?: { [key: string]: string; }): void {
@ -19,4 +18,4 @@ export class AppInsightsClient {
this._client.trackEvent(eventName, properties);
}
}
}
}

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

@ -1,11 +1,11 @@
'use strict';
import * as vscode from 'vscode';
import { IoTHubMessageExplorer } from './iotHubMessageExplorer';
import { EventHubMessageExplorer } from './eventHubMessageExplorer';
import { DeviceExplorer } from './deviceExplorer';
import { DeviceDiscoverer } from './deviceDiscoverer';
import { DeviceController } from './deviceController';
import { AppInsightsClient } from './appInsightsClient';
"use strict";
import * as vscode from "vscode";
import { AppInsightsClient } from "./appInsightsClient";
import { DeviceController } from "./deviceController";
import { DeviceDiscoverer } from "./deviceDiscoverer";
import { DeviceExplorer } from "./deviceExplorer";
import { EventHubMessageExplorer } from "./eventHubMessageExplorer";
import { IoTHubMessageExplorer } from "./iotHubMessageExplorer";
export class AzureIoTExplorer {
private _iotHubMessageExplorer: IoTHubMessageExplorer;
@ -15,7 +15,7 @@ export class AzureIoTExplorer {
private _deviceController: DeviceController;
constructor(context: vscode.ExtensionContext) {
let outputChannel = vscode.window.createOutputChannel('Azure IoT Toolkit');
let outputChannel = vscode.window.createOutputChannel("Azure IoT Toolkit");
let appInsightsClient = new AppInsightsClient();
this._iotHubMessageExplorer = new IoTHubMessageExplorer(outputChannel, appInsightsClient);
this._eventHubMessageExplorer = new EventHubMessageExplorer(outputChannel, appInsightsClient);
@ -71,4 +71,4 @@ export class AzureIoTExplorer {
public run(): void {
this._deviceController.run();
}
}
}

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

@ -1,8 +1,8 @@
'use strict';
import * as vscode from 'vscode';
import { Utility } from './utility';
import { AppInsightsClient } from './appInsightsClient';
import { Client as EventHubClient } from 'azure-event-hubs';
"use strict";
import { Client as EventHubClient } from "azure-event-hubs";
import * as vscode from "vscode";
import { AppInsightsClient } from "./appInsightsClient";
import { Utility } from "./utility";
export class BaseExplorer {
protected _outputChannel: vscode.OutputChannel;
@ -13,15 +13,15 @@ export class BaseExplorer {
this._appInsightsClient = appInsightsClient;
}
output(label: string, message: string): void {
protected output(label: string, message: string): void {
this._outputChannel.append(`[${label}] ${message}`);
}
outputLine(label: string, message: string): void {
protected outputLine(label: string, message: string): void {
this._outputChannel.appendLine(`[${label}] ${message}`);
}
printError(outputChannel: vscode.OutputChannel, label: string, eventHubClient: EventHubClient) {
protected printError(outputChannel: vscode.OutputChannel, label: string, eventHubClient: EventHubClient) {
return (err) => {
this.outputLine(label, err.message);
if (eventHubClient) {
@ -30,65 +30,64 @@ export class BaseExplorer {
};
};
printMessage(outputChannel: vscode.OutputChannel, label: string, prefix: string) {
protected printMessage(outputChannel: vscode.OutputChannel, label: string, prefix: string) {
return (message) => {
let config = Utility.getConfiguration();
let showVerboseMessage = config.get<boolean>('showVerboseMessage');
let showVerboseMessage = config.get<boolean>("showVerboseMessage");
let result;
if (showVerboseMessage) {
result = {
'partitionKey': message.partitionKey,
'body': message.body,
'enqueuedTimeUtc': message.enqueuedTimeUtc,
'offset': message.offset,
'properties': message.properties,
'sequenceNumber': message.sequenceNumber,
'systemProperties': message.systemProperties
body: message.body,
enqueuedTimeUtc: message.enqueuedTimeUtc,
offset: message.offset,
partitionKey: message.partitionKey,
properties: message.properties,
sequenceNumber: message.sequenceNumber,
systemProperties: message.systemProperties,
};
result.body = this.tryGetStringFromCharCode(message.body);
} else {
result = this.tryGetStringFromCharCode(message.body);
}
this.outputLine(label, prefix + ':');
this.outputLine(label, prefix + ":");
this._outputChannel.appendLine(JSON.stringify(result, null, 2));
};
};
tryGetStringFromCharCode(source) {
if (source instanceof Uint8Array) {
try {
source = String.fromCharCode.apply(null, source)
}
catch (e) {
}
}
return source;
}
startMonitor(eventHubClient: EventHubClient, label: string, consumerGroup: string) {
protected startMonitor(eventHubClient: EventHubClient, label: string, consumerGroup: string) {
if (eventHubClient) {
eventHubClient.open()
.then(eventHubClient.getPartitionIds.bind(eventHubClient))
.then((partitionIds) => {
return partitionIds.map((partitionId) => {
return eventHubClient.createReceiver(consumerGroup, partitionId, { 'startAfterTime': Date.now() }).then((receiver) => {
this.outputLine(label, `Created partition receiver [${partitionId}] for consumerGroup [${consumerGroup}]`);
receiver.on('errorReceived', this.printError(this._outputChannel, label, eventHubClient));
receiver.on('message', this.printMessage(this._outputChannel, label, 'Message Received'));
});
return eventHubClient.createReceiver(consumerGroup, partitionId, { startAfterTime: Date.now() })
.then((receiver) => {
this.outputLine(label, `Created partition receiver [${partitionId}] for consumerGroup [${consumerGroup}]`);
receiver.on("errorReceived", this.printError(this._outputChannel, label, eventHubClient));
receiver.on("message", this.printMessage(this._outputChannel, label, "Message Received"));
});
});
});
}
}
stopMonoitor(eventHubClient: EventHubClient, label: string, aiEvent: string) {
protected stopMonoitor(eventHubClient: EventHubClient, label: string, aiEvent: string) {
if (eventHubClient) {
this.outputLine(label, 'Stop monitoring ...');
this.outputLine(label, "Stop monitoring ...");
this._appInsightsClient.sendEvent(aiEvent);
eventHubClient.close();
}
else {
this.outputLine(label, 'No monitor job running.')
} else {
this.outputLine(label, "No monitor job running.");
}
}
}
private tryGetStringFromCharCode(source) {
if (source instanceof Uint8Array) {
try {
source = String.fromCharCode.apply(null, source);
} catch (e) {
}
}
return source;
}
}

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

@ -1,4 +1,4 @@
'user strict';
"user strict";
export class Constants {
public static IoTHub = "IoT Hub";
@ -10,22 +10,22 @@ export class Constants {
public static IotHubConnectionStringTitle = "Iot Hub Connection String";
public static IoTHubConsumerGroup = "iotHubConsumerGroup";
public static EventHubConnectionstringKey = "eventHubConnectionString";
public static EventHubConnectionstringKey = "eventHubConnectionString";
public static EventHubConnectionStringTitle = "Event Hub Connection String";
public static EventHubPathKey = "eventHubPath";
public static EventHubPathTitle = "Event Hub Path";
public static EventHubConsumerGroup = "eventHubConsumerGroup";
public static EventHubMonitorLabel = "EventHubMonitor";
public static EventHubMessageLabel = 'EventHubMessage';
public static EventHubMessageLabel = "EventHubMessage";
public static IoTHubMonitorLabel = "IoTHubMonitor";
public static IoTHubMessageLabel = "D2CMessage";
public static IoTHubAIStartMonitorEvent = 'D2C.startMonitoring';
public static IoTHubAIStopMonitorEvent = 'D2C.stopMonitoring';
public static IoTHubAIMessageEvent = 'D2C.Send';
public static IoTHubAIStartMonitorEvent = "D2C.startMonitoring";
public static IoTHubAIStopMonitorEvent = "D2C.stopMonitoring";
public static IoTHubAIMessageEvent = "D2C.Send";
public static EventHubAIStartMonitorEvent = 'EventHub.startMonitoring';
public static EventHubAIStopMonitorEvent = 'EventHub.stopMonitoring';
public static EventHubAIMessageEvent = 'EventHub.Send';
}
public static EventHubAIStartMonitorEvent = "EventHub.startMonitoring";
public static EventHubAIStopMonitorEvent = "EventHub.stopMonitoring";
public static EventHubAIMessageEvent = "EventHub.Send";
}

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

@ -1,10 +1,10 @@
'use strict';
import * as vscode from 'vscode';
const scp2 = require('scp2');
const SSH = require('simple-ssh');
import { Utility } from './utility';
import { AppInsightsClient } from './appInsightsClient';
import { BaseExplorer } from './baseExplorer';
"use strict";
import * as vscode from "vscode";
import scp2 = require("scp2");
import SSH = require("simple-ssh");
import { AppInsightsClient } from "./appInsightsClient";
import { BaseExplorer } from "./baseExplorer";
import { Utility } from "./utility";
export class DeviceController extends BaseExplorer {
private _localFolder: string;
@ -13,11 +13,10 @@ export class DeviceController extends BaseExplorer {
private _username: string;
private _password: string;
private _command: string;
private _label = 'Remote';
private _label = "Remote";
constructor(outputChannel: vscode.OutputChannel, appInsightsClient: AppInsightsClient) {
super(outputChannel, appInsightsClient);
}
public deploy(run = false): void {
@ -25,14 +24,14 @@ export class DeviceController extends BaseExplorer {
this._outputChannel.show();
this.outputLine(this._label, `Deploying from '${this._localFolder}' to '${this._remoteFolder}'`);
let options = this.getScpOptions();
scp2.scp(this._localFolder, options, err => {
scp2.scp(this._localFolder, options, (err) => {
if (err) {
this.outputLine(this._label, 'Deployment failed');
this.outputLine(this._label, "Deployment failed");
this.outputLine(this._label, err);
this._appInsightsClient.sendEvent(`${this._label}.deploy`, { Result: 'Fail' });
this._appInsightsClient.sendEvent(`${this._label}.deploy`, { Result: "Fail" });
} else {
this.outputLine(this._label, 'Deployment done');
this._appInsightsClient.sendEvent(`${this._label}.deploy`, { Result: 'Success' });
this.outputLine(this._label, "Deployment done");
this._appInsightsClient.sendEvent(`${this._label}.deploy`, { Result: "Success" });
if (run) {
this.run();
}
@ -52,30 +51,30 @@ export class DeviceController extends BaseExplorer {
ssh.exec(cmd, {
pty: true,
out: stdout => {
out: (stdout) => {
this.outputLine(this._label, stdout);
},
err: stderr => {
err: (stderr) => {
this.outputLine(this._label, stderr);
},
exit: code => {
exit: (code) => {
this.outputLine(this._label, `Exited with code=${code}`);
this._appInsightsClient.sendEvent(`${this._label}.run`, { Code: code.toString() });
if (code == 0 && callback) {
callback()
if (code === 0 && callback) {
callback();
}
}
},
}).start();
}
private getConfiguration(): void {
let config = Utility.getConfiguration();
this._localFolder = config.get<string>('localFolder');
this._remoteFolder = config.get<string>('remoteFolder');
this._host = config.get<string>('host');
this._username = config.get<string>('username');
this._password = config.get<string>('password');
this._command = config.get<string>('command');
this._localFolder = config.get<string>("localFolder");
this._remoteFolder = config.get<string>("remoteFolder");
this._host = config.get<string>("host");
this._username = config.get<string>("username");
this._password = config.get<string>("password");
this._command = config.get<string>("command");
}
private getScpOptions(): any {
@ -83,7 +82,7 @@ export class DeviceController extends BaseExplorer {
host: this._host,
username: this._username,
password: this._password,
path: this._remoteFolder
path: this._remoteFolder,
};
}
@ -93,7 +92,7 @@ export class DeviceController extends BaseExplorer {
user: this._username,
pass: this._password,
baseDir: this._remoteFolder,
timeout: 30000
timeout: 30000,
};
}
}
}

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

@ -1,12 +1,12 @@
'use strict';
import * as vscode from 'vscode';
import * as path from 'path';
import { exec } from 'child_process';
import { Utility } from './utility';
import { AppInsightsClient } from './appInsightsClient';
import { BaseExplorer } from './baseExplorer';
const types = ['eth', 'usb', 'wifi'];
const devdisco = 'devdisco';
"use strict";
import { exec } from "child_process";
import * as path from "path";
import * as vscode from "vscode";
import { AppInsightsClient } from "./appInsightsClient";
import { BaseExplorer } from "./baseExplorer";
import { Utility } from "./utility";
const types = ["eth", "usb", "wifi"];
const devdisco = "devdisco";
export class DeviceDiscoverer extends BaseExplorer {
private _deviceStatus = {};
@ -18,7 +18,7 @@ export class DeviceDiscoverer extends BaseExplorer {
}
public discoverDevice(): void {
let label = 'Discovery';
let label = "Discovery";
vscode.window.showQuickPick(types, { placeHolder: "Enter device type to discover" }).then((type) => {
if (type !== undefined) {
this._outputChannel.show();
@ -29,37 +29,37 @@ export class DeviceDiscoverer extends BaseExplorer {
}
private deviceDiscovery(label: string, type: string): void {
let devdiscoDir = this._context.asAbsolutePath(path.join('node_modules', 'device-discovery-cli'));
let devdiscoDir = this._context.asAbsolutePath(path.join("node_modules", "device-discovery-cli"));
let process = exec(`${devdisco} list --${type}`, { cwd: devdiscoDir });
let startTime = new Date();
let devdiscoNotFound = false;
let nodeNotFound = false;
process.stdout.on('data', (data) => {
process.stdout.on("data", (data) => {
this._outputChannel.append(data.toString());
});
process.stderr.on('data', (data) => {
process.stderr.on("data", (data) => {
data = data.toString();
this._outputChannel.append(data);
if (data.indexOf(devdisco) >= 0) {
devdiscoNotFound = true;
} else if (data.indexOf('node') >= 0) {
} else if (data.indexOf("node") >= 0) {
nodeNotFound = true;
}
}
});
process.on('close', (code) => {
process.on("close", (code) => {
let endTime = new Date();
let elapsedTime = (endTime.getTime() - startTime.getTime()) / 1000;
this._appInsightsClient.sendEvent(`${label}.${type}`, { Code: code.toString() });
this.outputLine(label, 'Finished with exit code=' + code + ' in ' + elapsedTime + ' seconds');
this.outputLine(label, "Finished with exit code=" + code + " in " + elapsedTime + " seconds");
if (devdiscoNotFound && code >= 1) {
this.outputLine(label, '[Note!!!] Please install device-discovery-cli with below command if not yet:');
this.outputLine(label, 'npm install --global device-discovery-cli');
this.outputLine(label, "[Note!!!] Please install device-discovery-cli with below command if not yet:");
this.outputLine(label, "npm install --global device-discovery-cli");
} else if (nodeNotFound && code >= 1) {
this.outputLine(label, '[Note!!!] Please install Node.js if not yet');
this.outputLine(label, "[Note!!!] Please install Node.js if not yet");
}
});
}
}
}

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

@ -1,9 +1,9 @@
'use strict';
import * as vscode from 'vscode';
import { Utility } from './utility';
import { AppInsightsClient } from './appInsightsClient';
import { BaseExplorer } from './baseExplorer';
let iothub = require('azure-iothub');
"use strict";
import * as vscode from "vscode";
import { AppInsightsClient } from "./appInsightsClient";
import { BaseExplorer } from "./baseExplorer";
import { Utility } from "./utility";
import iothub = require("azure-iothub");
export class DeviceExplorer extends BaseExplorer {
constructor(outputChannel: vscode.OutputChannel, appInsightsClient: AppInsightsClient) {
@ -11,57 +11,57 @@ export class DeviceExplorer extends BaseExplorer {
}
public listDevice(): void {
let label = 'Device';
let iotHubConnectionString = Utility.getConfig('iotHubConnectionString', 'IoT Hub Connection String');
let label = "Device";
let iotHubConnectionString = Utility.getConfig("iotHubConnectionString", "IoT Hub Connection String");
if (!iotHubConnectionString) {
return;
}
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
this._outputChannel.show();
this.outputLine(label, 'Querying devices...')
this.outputLine(label, "Querying devices...");
this._appInsightsClient.sendEvent(`${label}.List`);
registry.list((err, deviceList) => {
this.outputLine(label, `${deviceList.length} device(s) found`)
this.outputLine(label, `${deviceList.length} device(s) found`);
deviceList.forEach((device, index) => {
this.outputLine(`${label}#${index + 1}`, JSON.stringify(device, null, 2))
this.outputLine(`${label}#${index + 1}`, JSON.stringify(device, null, 2));
});
});
}
public createDevice(): void {
let label = 'Device';
let iotHubConnectionString = Utility.getConfig('iotHubConnectionString', 'IoT Hub Connection String');
let label = "Device";
let iotHubConnectionString = Utility.getConfig("iotHubConnectionString", "IoT Hub Connection String");
if (!iotHubConnectionString) {
return;
}
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
vscode.window.showInputBox({ prompt: 'Enter device id to create' }).then((deviceId: string) => {
vscode.window.showInputBox({ prompt: "Enter device id to create" }).then((deviceId: string) => {
if (deviceId !== undefined) {
var device = {
deviceId: deviceId
let device = {
deviceId,
};
this._outputChannel.show();
this.outputLine(label, `Creating device '${device.deviceId}'`);
registry.create(device, this.done('Create', label));
registry.create(device, this.done("Create", label));
}
});
}
public deleteDevice(): void {
let label = 'Device';
let iotHubConnectionString = Utility.getConfig('iotHubConnectionString', 'IoT Hub Connection String');
let label = "Device";
let iotHubConnectionString = Utility.getConfig("iotHubConnectionString", "IoT Hub Connection String");
if (!iotHubConnectionString) {
return;
}
let registry = iothub.Registry.fromConnectionString(iotHubConnectionString);
vscode.window.showInputBox({ prompt: 'Enter device id to delete' }).then((deviceId: string) => {
vscode.window.showInputBox({ prompt: "Enter device id to delete" }).then((deviceId: string) => {
if (deviceId !== undefined) {
this._outputChannel.show();
this.outputLine(label, `Deleting device ${deviceId}`);
registry.delete(deviceId, this.done('Delete', label));
registry.delete(deviceId, this.done("Delete", label));
}
});
}
@ -69,15 +69,15 @@ export class DeviceExplorer extends BaseExplorer {
private done(op: string, label: string) {
return (err, deviceInfo, res) => {
if (err) {
this._appInsightsClient.sendEvent(`${label}.${op}`, { Result: 'Fail' })
this._appInsightsClient.sendEvent(`${label}.${op}`, { Result: "Fail" });
this.outputLine(label, `[${op}] error: ${err.toString()}`);
}
if (res) {
let result = 'Fail';
let result = "Fail";
if (res.statusCode < 300) {
result = 'Success';
result = "Success";
}
this._appInsightsClient.sendEvent(`${label}.${op}`, { Result: result })
this._appInsightsClient.sendEvent(`${label}.${op}`, { Result: result });
this.outputLine(label, `[${op}][${result}] status: ${res.statusCode} ${res.statusMessage}`);
}
if (deviceInfo) {
@ -85,4 +85,4 @@ export class DeviceExplorer extends BaseExplorer {
}
};
}
}
}

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

@ -1,11 +1,11 @@
'use strict';
import * as vscode from 'vscode';
import { AppInsightsClient } from './appInsightsClient';
import { BaseExplorer } from './baseExplorer';
import { Client as EventHubClient, Sender as EventHubSender } from 'azure-event-hubs';
import { Constants } from './constants';
import { Message, Client } from 'azure-iot-device';
import { Utility } from './utility';
"use strict";
import { Client as EventHubClient, Sender as EventHubSender } from "azure-event-hubs";
import { Client, Message } from "azure-iot-device";
import * as vscode from "vscode";
import { AppInsightsClient } from "./appInsightsClient";
import { BaseExplorer } from "./baseExplorer";
import { Constants } from "./constants";
import { Utility } from "./utility";
export class EventHubMessageExplorer extends BaseExplorer {
private _eventHubClient;
@ -30,10 +30,9 @@ export class EventHubMessageExplorer extends BaseExplorer {
client.open()
.then(client.getPartitionIds.bind(client))
.then(() => client.createSender())
.then((sender: EventHubSender) => { return sender.send(message) })
.then((sender: EventHubSender) => { return sender.send(message); })
.then(this.sendToEventHubDone(client));
}
catch (e) {
} catch (e) {
this.sendToEventHubFail(client, e);
}
}
@ -55,10 +54,9 @@ export class EventHubMessageExplorer extends BaseExplorer {
this.outputLine(Constants.EventHubMonitorLabel, `Start monitoring ${Constants.EventHub} ...`);
this._appInsightsClient.sendEvent(Constants.EventHubAIStartMonitorEvent);
this.startMonitor(this._eventHubClient, Constants.EventHubMonitorLabel, consumerGroup);
}
catch (e) {
} catch (e) {
this.outputLine(Constants.EventHubMonitorLabel, e);
this._appInsightsClient.sendEvent(Constants.EventHubAIStartMonitorEvent, { Result: 'Exception', Message: e })
this._appInsightsClient.sendEvent(Constants.EventHubAIStartMonitorEvent, { Result: "Exception", Message: e });
}
}
@ -70,15 +68,15 @@ export class EventHubMessageExplorer extends BaseExplorer {
private sendToEventHubFail(client: EventHubClient, err) {
this.outputLine(Constants.EventHubMessageLabel, `Failed to send message to ${Constants.EventHub}`);
this.outputLine(Constants.EventHubMessageLabel, err.toString());
this._appInsightsClient.sendEvent(Constants.EventHubAIMessageEvent, { Result: 'Fail' });
this._appInsightsClient.sendEvent(Constants.EventHubAIMessageEvent, { Result: "Fail" });
client.close();
}
private sendToEventHubDone(client: EventHubClient) {
return () => {
this.outputLine(Constants.EventHubMessageLabel, `[Success] Message sent to ${Constants.EventHub}`);
this._appInsightsClient.sendEvent(Constants.EventHubAIMessageEvent, { Result: 'Success' });
this._appInsightsClient.sendEvent(Constants.EventHubAIMessageEvent, { Result: "Success" });
client.close();
};
}
}
}

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

@ -1,55 +1,55 @@
'use strict';
import * as vscode from 'vscode';
import { AzureIoTExplorer } from './azureIoTExplorer';
"use strict";
import * as vscode from "vscode";
import { AzureIoTExplorer } from "./azureIoTExplorer";
export function activate(context: vscode.ExtensionContext) {
let azureIoTExplorer = new AzureIoTExplorer(context);
let sendD2CMessage = vscode.commands.registerCommand('azure-iot-toolkit.sendD2CMessage', () => {
let sendD2CMessage = vscode.commands.registerCommand("azure-iot-toolkit.sendD2CMessage", () => {
azureIoTExplorer.sendD2CMessage();
});
let startMonitorIoTHubMessage = vscode.commands.registerCommand('azure-iot-toolkit.startMonitorIoTHubMessage', () => {
let startMonitorIoTHubMessage = vscode.commands.registerCommand("azure-iot-toolkit.startMonitorIoTHubMessage", () => {
azureIoTExplorer.startMonitorIoTHubMessage();
});
let stopMonitorIoTHubMessage = vscode.commands.registerCommand('azure-iot-toolkit.stopMonitorIoTHubMessage', () => {
let stopMonitorIoTHubMessage = vscode.commands.registerCommand("azure-iot-toolkit.stopMonitorIoTHubMessage", () => {
azureIoTExplorer.stopMonitorIoTHubMessage();
});
let sendMessageToEventHub = vscode.commands.registerCommand('azure-iot-toolkit.sendMessageToEventHub', () => {
let sendMessageToEventHub = vscode.commands.registerCommand("azure-iot-toolkit.sendMessageToEventHub", () => {
azureIoTExplorer.sendMessageToEventHub();
});
let startMonitorEventHubMessage = vscode.commands.registerCommand('azure-iot-toolkit.startMonitorEventHubMessage', () => {
let startMonitorEventHubMessage = vscode.commands.registerCommand("azure-iot-toolkit.startMonitorEventHubMessage", () => {
azureIoTExplorer.startMonitorEventHubMessage();
});
let stopMonitorEventHubMessage = vscode.commands.registerCommand('azure-iot-toolkit.stopMonitorEventHubMessage', () => {
let stopMonitorEventHubMessage = vscode.commands.registerCommand("azure-iot-toolkit.stopMonitorEventHubMessage", () => {
azureIoTExplorer.stopMonitorEventHubMessage();
});
let listDevice = vscode.commands.registerCommand('azure-iot-toolkit.listDevice', () => {
let listDevice = vscode.commands.registerCommand("azure-iot-toolkit.listDevice", () => {
azureIoTExplorer.listDevice();
});
let createDevice = vscode.commands.registerCommand('azure-iot-toolkit.createDevice', () => {
let createDevice = vscode.commands.registerCommand("azure-iot-toolkit.createDevice", () => {
azureIoTExplorer.createDevice();
});
let deleteDevice = vscode.commands.registerCommand('azure-iot-toolkit.deleteDevice', () => {
let deleteDevice = vscode.commands.registerCommand("azure-iot-toolkit.deleteDevice", () => {
azureIoTExplorer.deleteDevice();
});
let discoverDevice = vscode.commands.registerCommand('azure-iot-toolkit.discoverDevice', () => {
let discoverDevice = vscode.commands.registerCommand("azure-iot-toolkit.discoverDevice", () => {
azureIoTExplorer.discoverDevice();
});
let deploy = vscode.commands.registerCommand('azure-iot-toolkit.deploy', () => {
let deploy = vscode.commands.registerCommand("azure-iot-toolkit.deploy", () => {
azureIoTExplorer.deploy();
});
let run = vscode.commands.registerCommand('azure-iot-toolkit.run', () => {
let run = vscode.commands.registerCommand("azure-iot-toolkit.run", () => {
azureIoTExplorer.run();
});
@ -68,4 +68,4 @@ export function activate(context: vscode.ExtensionContext) {
}
export function deactivate() {
}
}

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

@ -1,12 +1,12 @@
'use strict';
import * as vscode from 'vscode';
import { AppInsightsClient } from './appInsightsClient';
import { BaseExplorer } from './baseExplorer';
import { Client as EventHubClient } from 'azure-event-hubs';
import { clientFromConnectionString } from 'azure-iot-device-http';
import { Constants } from './constants';
import { Message, Client } from 'azure-iot-device';
import { Utility } from './utility';
"use strict";
import { Client as EventHubClient } from "azure-event-hubs";
import { Client, Message } from "azure-iot-device";
import { clientFromConnectionString } from "azure-iot-device-http";
import * as vscode from "vscode";
import { AppInsightsClient } from "./appInsightsClient";
import { BaseExplorer } from "./baseExplorer";
import { Constants } from "./constants";
import { Utility } from "./utility";
export class IoTHubMessageExplorer extends BaseExplorer {
private _eventHubClient;
@ -26,15 +26,13 @@ export class IoTHubMessageExplorer extends BaseExplorer {
try {
let client = clientFromConnectionString(deviceConnectionString);
client.sendEvent(new Message(JSON.stringify(message)), this.sendEventDone(client, Constants.IoTHubMessageLabel));
}
catch (e) {
} catch (e) {
this.outputLine(Constants.IoTHubMessageLabel, e);
}
}
});
}
public startMonitorIoTHubMessage(): void {
let iotHubConnectionString = Utility.getConfig(Constants.IotHubConnectionStringKey, Constants.IotHubConnectionStringTitle);
if (!iotHubConnectionString) {
@ -49,10 +47,9 @@ export class IoTHubMessageExplorer extends BaseExplorer {
this.outputLine(Constants.IoTHubMonitorLabel, `Start monitoring ${Constants.IoTHub} ...`);
this._appInsightsClient.sendEvent(Constants.IoTHubAIStartMonitorEvent);
this.startMonitor(this._eventHubClient, Constants.IoTHubMonitorLabel, consumerGroup);
}
catch (e) {
} catch (e) {
this.outputLine(Constants.IoTHubMonitorLabel, e);
this._appInsightsClient.sendEvent(Constants.IoTHubAIStartMonitorEvent, { Result: 'Exception', Message: e })
this._appInsightsClient.sendEvent(Constants.IoTHubAIStartMonitorEvent, { Result: "Exception", Message: e });
}
}
@ -69,13 +66,13 @@ export class IoTHubMessageExplorer extends BaseExplorer {
if (err) {
this.outputLine(label, `Failed to send message to ${Constants.IoTHub}`);
this.outputLine(label, err.toString());
this._appInsightsClient.sendEvent(Constants.IoTHubAIMessageEvent, { Result: 'Fail' })
this._appInsightsClient.sendEvent(Constants.IoTHubAIMessageEvent, { Result: "Fail" });
}
if (result) {
this.outputLine(label, `[Success] Message sent to ${Constants.IoTHub}`);
this._appInsightsClient.sendEvent(Constants.IoTHubAIMessageEvent, { Result: 'Success' })
this._appInsightsClient.sendEvent(Constants.IoTHubAIMessageEvent, { Result: "Success" });
}
client.close((err, result) => { console.log('client close') });
client.close(() => { return; });
};
}
}
}

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

@ -1,18 +1,18 @@
'use strict';
import * as vscode from 'vscode';
"use strict";
import * as vscode from "vscode";
export class Utility {
static getConfiguration(): vscode.WorkspaceConfiguration {
return vscode.workspace.getConfiguration('azure-iot-toolkit');
public static getConfiguration(): vscode.WorkspaceConfiguration {
return vscode.workspace.getConfiguration("azure-iot-toolkit");
}
static getConfig(id: string, name: string): string {
public static getConfig(id: string, name: string): string {
let config = Utility.getConfiguration();
let value = config.get<string>(id);
if (!value || value.startsWith('<<insert')) {
if (!value || value.startsWith("<<insert")) {
vscode.window.showErrorMessage(`Please set your ${name} in settings.json`);
return null;
}
return value;
}
}
}

18
tslint.json Normal file
Просмотреть файл

@ -0,0 +1,18 @@
{
"extends": "tslint:recommended",
"rules": {
"variable-name": [
true,
"ban-keywords",
"check-format",
"allow-pascal-case",
"allow-leading-underscore"
],
"max-line-length": [
true,
150
],
"no-empty": false,
"object-literal-sort-keys": false
}
}