(GH-96) Add auto refresh with configuration to enable it and set refresh interval (#184)
* (GH-96) Add auto refresh with configuration to enable it and set refresh interval * (GH-96) Apply PR comments
This commit is contained in:
Родитель
3861db2643
Коммит
c273f34979
14
README.md
14
README.md
|
@ -146,6 +146,20 @@ Whether to show IoT Hub info when IoT Hub Connection String is not set (default
|
|||
}
|
||||
```
|
||||
|
||||
Whether to enable auto refresh of tree view (default is `false`):
|
||||
```json
|
||||
{
|
||||
"azure-iot-toolkit.treeViewAutoRefreshEnable": false
|
||||
}
|
||||
```
|
||||
|
||||
Time interval in seconds for tree view auto refresh, auto refresh has to be enabled for it to work. (default is `60`):
|
||||
```json
|
||||
{
|
||||
"azure-iot-toolkit.treeViewAutoRefreshIntervalInSeconds": 60
|
||||
}
|
||||
```
|
||||
|
||||
## Resources
|
||||
- [Channel 9 video: Walkthrough of Azure IoT Toolkit extension](https://channel9.msdn.com/Shows/Internet-of-Things-Show/Azure-IoT-Toolkit-extension-for-Visual-Studio-Code)
|
||||
- [Channel 9 video: What's new in the IoT Toolkit extension for VS Code](https://channel9.msdn.com/Shows/Internet-of-Things-Show/Whats-new-in-the-IoT-Toolkit-extension-for-VS-Code)
|
||||
|
|
10
package.json
10
package.json
|
@ -576,6 +576,16 @@
|
|||
"type": "string",
|
||||
"default": "",
|
||||
"description": "(Windows Only) Replace the Windows style drive letter in the command with a Unix style root when using a custom shell as the terminal, like Bash on Windows, Git Bash or Cgywin. Example: For Bash on Windows, setting this to '/mnt/' will replace 'C:\\foo\\bar' with '/mnt/c/foo/bar'"
|
||||
},
|
||||
"azure-iot-toolkit.treeViewAutoRefreshEnable": {
|
||||
"type": "boolean",
|
||||
"default": false,
|
||||
"description": "Whether to enable auto refresh of tree view."
|
||||
},
|
||||
"azure-iot-toolkit.treeViewAutoRefreshIntervalInSeconds": {
|
||||
"type": "number",
|
||||
"default": 60,
|
||||
"description": "Time interval in seconds for tree view auto refresh, auto refresh has to be enabled for it to work."
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -39,6 +39,8 @@ export class Constants {
|
|||
public static IoTHubMessageLabel = "D2CMessage";
|
||||
public static IoTHubC2DMessageLabel = "C2DMessage";
|
||||
public static IoTHubC2DMessageMonitorLabel = "C2DMessageMonitor";
|
||||
public static TreeViewAutoRefreshEnableKey = "treeViewAutoRefreshEnable";
|
||||
public static TreeViewAutoRefreshIntervalInSecondsKey = "treeViewAutoRefreshIntervalInSeconds";
|
||||
|
||||
public static IoTHubDirectMethodLabel = "DirectMethod";
|
||||
public static IoTHubDeviceTwinLabel = "DeviceTwin";
|
||||
|
|
|
@ -10,6 +10,7 @@ import { Utility } from "./utility";
|
|||
export class DeviceTree implements vscode.TreeDataProvider<vscode.TreeItem> {
|
||||
public _onDidChangeTreeData: vscode.EventEmitter<vscode.TreeItem | undefined> = new vscode.EventEmitter<vscode.TreeItem | undefined>();
|
||||
public readonly onDidChangeTreeData: vscode.Event<vscode.TreeItem | undefined> = this._onDidChangeTreeData.event;
|
||||
private autoRefreshIntervalID: NodeJS.Timer;
|
||||
|
||||
constructor(private context: vscode.ExtensionContext) {
|
||||
}
|
||||
|
@ -62,6 +63,9 @@ export class DeviceTree implements vscode.TreeDataProvider<vscode.TreeItem> {
|
|||
return this.getErrorMessageTreeItems("modules", err.message);
|
||||
}
|
||||
} else {
|
||||
if (this.autoRefreshIntervalID) {
|
||||
clearInterval(this.autoRefreshIntervalID);
|
||||
}
|
||||
TelemetryClient.sendEvent(Constants.IoTHubAIStartLoadDeviceTreeEvent);
|
||||
try {
|
||||
const deviceList: vscode.TreeItem[] = await Utility.getDeviceList(iotHubConnectionString, this.context);
|
||||
|
@ -69,6 +73,7 @@ export class DeviceTree implements vscode.TreeDataProvider<vscode.TreeItem> {
|
|||
if (deviceList.length === 0) {
|
||||
deviceList.push(new vscode.TreeItem(`No devices in ${Utility.getHostName(iotHubConnectionString)}`));
|
||||
}
|
||||
this.autoRefreshIntervalID = this.generateAutoRefreshInterval();
|
||||
return deviceList;
|
||||
} catch (err) {
|
||||
TelemetryClient.sendEvent(Constants.IoTHubAILoadDeviceTreeEvent, { Result: "Fail", Message: err.message });
|
||||
|
@ -101,4 +106,15 @@ export class DeviceTree implements vscode.TreeDataProvider<vscode.TreeItem> {
|
|||
};
|
||||
return commandItem;
|
||||
}
|
||||
|
||||
private generateAutoRefreshInterval(): NodeJS.Timer {
|
||||
let treeViewAutoRefreshEnable = Utility.getConfig<boolean>(Constants.TreeViewAutoRefreshEnableKey);
|
||||
if (treeViewAutoRefreshEnable) {
|
||||
let treeViewAutoRefreshIntervalInSeconds = Utility.getConfig<number>(Constants.TreeViewAutoRefreshIntervalInSecondsKey);
|
||||
return setInterval(() => {
|
||||
this._onDidChangeTreeData.fire();
|
||||
}, treeViewAutoRefreshIntervalInSeconds * 1000);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,16 @@ suite("Utility Tests ", () => {
|
|||
assert.equal(iotHubD2CMessageStringify, false);
|
||||
});
|
||||
|
||||
test("should be able to get auto refresh enable flag", () => {
|
||||
let autoRefreshEnable = Utility.getConfig<boolean>(Constants.TreeViewAutoRefreshEnableKey);
|
||||
assert.equal(autoRefreshEnable, false);
|
||||
});
|
||||
|
||||
test("should be able to get auto refresh interval", () => {
|
||||
let autoRefreshIntervalInSeconds = Utility.getConfig<boolean>(Constants.TreeViewAutoRefreshIntervalInSecondsKey);
|
||||
assert.equal(autoRefreshIntervalInSeconds, 60);
|
||||
});
|
||||
|
||||
// tslint:disable-next-line:only-arrow-functions
|
||||
test("should be able to get IoT Hub Connection String", function (done) {
|
||||
this.timeout(5 * 1000);
|
||||
|
|
Загрузка…
Ссылка в новой задаче