Skip to content

Commit 9ee9ba9

Browse files
committed
Added IContexUI
1 parent 4bf8f1d commit 9ee9ba9

35 files changed

+211
-154
lines changed

src/Configuration/IotConfiguration.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {IotResult,StatusResult } from '../IotResult';
77
import {IotConfigurationFolder} from './IotConfigurationFolder';
88
import {IotTemplateCollection} from '../Templates/IotTemplateCollection';
99
import { IoTHelper } from '../Helper/IoTHelper';
10-
import {IoTUI} from '../ui/IoTUI';
10+
import {IContexUI} from '../ui/IContexUI';
1111

1212
export class IotConfiguration {
1313
public UsernameAccountDevice:string="";
@@ -20,7 +20,7 @@ export class IotConfiguration {
2020
public IsUpdateTemplates:boolean;
2121
public UpdateIntervalTemplatesHours:number;
2222
public LastUpdateTemplatesHours:number;
23-
private _contextUI:IoTUI;
23+
private _contextUI:IContexUI;
2424
private _extVersion:string;
2525
public get ExtVersion(): string {
2626
return this._extVersion;}
@@ -30,7 +30,7 @@ export class IotConfiguration {
3030

3131
constructor(
3232
context: vscode.ExtensionContext,
33-
contextUI:IoTUI
33+
contextUI:IContexUI
3434
){
3535
//Get info from context
3636
this._extVersion=`${context.extension.packageJSON.version}`;

src/Entity/EntityCollection.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import {EntityBase} from './EntityBase';
66
import {EntityBaseAttribute} from './EntityBaseAttribute';
77
import {EntityType} from './EntityType';
88
import {IotResult,StatusResult } from '../IotResult';
9-
import {IoTUI} from '../ui/IoTUI';
9+
import {IContexUI} from '../ui/IContexUI';
1010

1111
export abstract class EntityCollection <A extends EntityBaseAttribute, T extends EntityBase<A>> {
12-
protected ContextUI:IoTUI;
12+
protected ContextUI:IContexUI;
1313

1414
private _data:Map<string,T>;
1515
protected _pathFolderSchemas: string;
@@ -30,7 +30,7 @@ export abstract class EntityCollection <A extends EntityBaseAttribute, T extends
3030

3131
constructor(
3232
basePath: string, recoverySourcePath:string,versionExt:string,
33-
pathFolderSchemas: string,contextUI:IoTUI
33+
pathFolderSchemas: string,contextUI:IContexUI
3434
){
3535
this.ContextUI=contextUI;
3636
this._pathFolderSchemas=pathFolderSchemas;

src/IotDevice.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,56 +323,56 @@ export class IotDevice extends BaseTreeItem {
323323
//GetIp
324324
result=await networkHelper.GetIpAddress(sshconfig.host ?? "non");
325325
if(result.Status==StatusResult.Error) {
326-
result.Message=`${result.Message}\n`+
326+
result.AddMessage(
327327
`Checklist:\n`+
328328
`❌ IP-Address defined;\n`+
329329
`❌ Host availability. Command: "ping";\n`+
330330
`❌ Port 22 availability;\n`+
331331
`❌ Authorization via ssh protocol.\n`+
332-
`${trubleshootingText}`;
332+
`${trubleshootingText}`);
333333
return Promise.resolve(result);}
334334
const ipAddress = <string>result.returnObject;
335335
//Ping
336336
result=await networkHelper.PingHost(ipAddress);
337337
if(result.Status==StatusResult.Error) {
338-
result.Message=`${result.Message}\n`+
338+
result.AddMessage(
339339
`Checklist:\n`+
340340
`✔️ IP-Address defined;\n`+
341341
`❌ Host availability. Command: "ping";\n`+
342342
`❌ Port 22 availability;\n`+
343343
`❌ Authorization via ssh protocol.\n`+
344-
`${trubleshootingText}`;
344+
`${trubleshootingText}`);
345345
return Promise.resolve(result);}
346346
//Check port
347347
result=await networkHelper.CheckTcpPortUsed(ipAddress,sshconfig.port ?? 22);
348348
if(result.Status==StatusResult.Error) {
349-
result.Message=`${result.Message}\n`+
349+
result.AddMessage(
350350
`Checklist:\n`+
351351
`✔️ IP-Address defined;\n`+
352352
`✔️ Host availability. Command: "ping";\n`+
353353
`❌ Port 22 availability;\n`+
354354
`❌ Authorization via ssh protocol.\n`+
355-
`${trubleshootingText}`;
355+
`${trubleshootingText}`);
356356
return Promise.resolve(result);}
357357
//Check ssh connection
358358
result=await this.Client.GetSshConnection(sshconfig);
359359
if(result.Status==StatusResult.Error) {
360360
//Error
361-
result.Message=`${result.Message}\n`+
361+
result.AddMessage(
362362
`Checklist:\n`+
363363
`✔️ IP-Address defined;\n`+
364364
`✔️ Host availability. Command: "ping";\n`+
365365
`✔️ Port 22 availability;\n`+
366366
`❌ Authorization via ssh protocol.\n`+
367-
`${trubleshootingText}`;
367+
`${trubleshootingText}`);
368368
} else {
369369
//OK
370-
result.Message=`${result.Message}\n`+
370+
result.AddMessage(
371371
`Checklist:\n`+
372372
`✔️ IP-Address defined;\n`+
373373
`✔️ Host availability. Command: "ping";\n`+
374374
`✔️ Port 22 availability;\n`+
375-
`✔️ Authorization via ssh protocol.`;
375+
`✔️ Authorization via ssh protocol.`);
376376
}
377377
return Promise.resolve(result);
378378
}

src/IotResult.ts

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export class IotResult {
1212
private _message: string|undefined;
1313
public get Message(): string|undefined {
1414
return this._message;}
15-
public set Message(value:string|undefined) {
16-
this._message=value}
1715

1816
private _systemMessage: string|undefined;
1917
public get SystemMessage(): string|undefined {
@@ -30,27 +28,27 @@ export class IotResult {
3028
this._status=status;
3129
this._message=message;
3230
this._systemMessage=systemMessage;
33-
}
31+
}
32+
33+
public AddMessage = (value: string|undefined) =>
34+
{if(value) this._message=`${this._message}\n${value}`};
35+
36+
public AddSystemMessage= (value: string|undefined) =>
37+
{if(value) this._systemMessage=`${this._systemMessage}\n${value}`};
38+
39+
/*
3440
public AppendResult(value: IotResult): void{
3541
this._status=value.Status;
36-
this._message=value.Message;
37-
if(this._systemMessage) {
38-
this._systemMessage=`${this._systemMessage}\n${value.SystemMessage}`;
39-
} else {
40-
this._systemMessage=value.SystemMessage;
41-
}
42+
this.AddMessage(value.Message);
43+
this.AddSystemMessage(value.SystemMessage);
4244
}
45+
*/
4346

4447
public toString():string{
4548
//Status
4649
let msg=`[${this.Status.toString().toUpperCase()}]`;
4750
//Message
48-
if(this.Message&&this.Message.length>0) {
49-
//check dot
50-
if((this.Message.toString().substring(this.Message.length-1))==".")
51-
msg=`${msg} ${this.Message}`;
52-
else msg=`${msg} ${this.Message}.`;
53-
}
51+
if(this.Message) msg=`${msg} ${this.Message}.`;
5452
//SystemMessage
5553
if(this.SystemMessage) msg=`${msg} ${this.SystemMessage}`;
5654
return msg;
@@ -63,12 +61,7 @@ export class IotResult {
6361
//Status
6462
msg=`${msg}Status: ${this.Status.toString().toUpperCase()}`;
6563
//Message
66-
if(this.Message&&this.Message.length>0) {
67-
//check dot
68-
if((this.Message.toString().substring(this.Message.length-1))==".")
69-
msg=`${msg}\nMessage: ${this.Message}`;
70-
else msg=`${msg}\nMessage: ${this.Message}.`;
71-
}
64+
if(this.Message) msg=`${msg}\nMessage: ${this.Message}.`;
7265
//SystemMessage
7366
if(this.SystemMessage) msg=`${msg}\nSystem message: ${this.SystemMessage}`;
7467
//HEAD

src/SshClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ export class SshClient {
293293
} else {
294294
msg = `The login was "${sshConfig.username}" and the password was ******.`;
295295
}
296-
result.Message=`${result.Message}\n${msg}`;
296+
result.AddMessage(msg);
297297
//end processing
298298
return Promise.resolve(result);
299299
}

src/Templates/IotTemplateCollection.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ import {IoTHelper} from '../Helper/IoTHelper';
1010
import {IotTemplateRecovery} from './IotTemplateRecovery';
1111
import {IotTemplateDownloader} from './IotTemplateDownloader';
1212
import {EntityDownload} from '../Entity/EntityDownloader';
13-
import {IoTUI} from '../ui/IoTUI';
13+
import {IContexUI} from '../ui/IContexUI';
1414

1515
export class IotTemplateCollection extends EntityCollection<IotTemplateAttribute,IotTemplate> {
1616

1717
constructor(
1818
basePath: string, recoverySourcePath:string, versionExt:string,
19-
pathFolderSchemas: string,contextUI:IoTUI
19+
pathFolderSchemas: string,contextUI:IContexUI
2020
){
2121
super(basePath,recoverySourcePath,versionExt,pathFolderSchemas,contextUI);
2222
}

src/TreeDataDevicesProvider.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {IotDeviceDTO} from './IotDeviceDTO';
88
import {IoTHelper} from './Helper/IoTHelper';
99
import {IotResult,StatusResult} from './IotResult';
1010
import {IotConfiguration} from './Configuration/IotConfiguration';
11-
import {IoTUI} from './ui/IoTUI';
11+
import {IContexUI} from './ui/IContexUI';
1212

1313
export class TreeDataDevicesProvider implements vscode.TreeDataProvider<BaseTreeItem> {
1414
public RootItems:Array<IotDevice>=[];
@@ -33,14 +33,14 @@ export class TreeDataDevicesProvider implements vscode.TreeDataProvider<BaseTree
3333
public readonly onDidChangeTreeData: vscode.Event<BaseTreeItem| undefined | null | void> =
3434
this._onDidChangeTreeData.event;
3535

36-
private _contextUI:IoTUI;
36+
private _contextUI:IContexUI;
3737
public SaveDevicesCallback:(data:any) =>void;
3838

3939
constructor(
4040
saveDevicesCallback:(data:any) =>void,
4141
config:IotConfiguration,
4242
jsonDevices:any,
43-
contextUI:IoTUI
43+
contextUI:IContexUI
4444
) {
4545
this._contextUI=contextUI;
4646
//
@@ -159,15 +159,15 @@ export class TreeDataDevicesProvider implements vscode.TreeDataProvider<BaseTree
159159
public async AddDevice(hostName: string,port: number,userName: string,password: string,accountNameDebug:string): Promise<IotResult> {
160160
let device = new IotDevice(this.Config);
161161
//Connection test device
162-
this._contextUI.StatusBarBackground.showAnimation("Checking the network connection");
162+
this._contextUI.ShowBackgroundNotification("Checking the network connection");
163163
let result=await device.ConnectionTest(hostName,port,userName,password);
164-
this._contextUI.Output(result.toMultiLineString("head"));
164+
this._contextUI.Output(result.toMultiLineString());
165165
if(result.Status==StatusResult.Error) return Promise.resolve(result);
166-
this._contextUI.StatusBarBackground.showAnimation("Create a device");
166+
this._contextUI.ShowBackgroundNotification("Create a device");
167167
this._contextUI.Output("Create a device");
168168
//event subscription
169169
let handler=device.Client.OnChangedStateSubscribe(event => {
170-
if(event.status) this._contextUI.StatusBarBackground.showAnimation(event.status);
170+
if(event.status) this._contextUI.ShowBackgroundNotification(event.status);
171171
if(event.status) this._contextUI.Output(event.status);
172172
if(event.console) this._contextUI.Output(event.console);
173173
});

src/UI/IContexUI.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import * as vscode from 'vscode';
2+
import * as fs from 'fs';
3+
import * as path from 'path';
4+
import {IotResult,StatusResult} from '../IotResult';
5+
6+
export interface IContexUI {
7+
Output(value:string|IotResult): void;
8+
ShowBackgroundNotification(text:string, tooltip?:string | vscode.MarkdownString| undefined):void;
9+
HideBackgroundNotification():void;
10+
ShowNotification(value:IotResult):void;
11+
RunTask(value:IotResult,ifOK:() =>void,ifError:() =>void):void;
12+
}

src/UI/IoTUI.ts

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,74 @@
11
import * as vscode from 'vscode';
22
import * as fs from 'fs';
33
import * as path from 'path';
4-
import {StatusBarBackgroundItem} from './StatusBarBackgroundItem';
4+
import {StatusBarBackground} from './StatusBarBackground';
5+
import {IContexUI} from './IContexUI';
6+
import {IotResult,StatusResult} from '../IotResult';
57

6-
export class IoTUI {
8+
export class IoTUI implements IContexUI {
79
private _outputChannel:vscode.OutputChannel;
8-
public StatusBarBackground: StatusBarBackgroundItem;
10+
private _statusBarBackground: StatusBarBackground;
911

1012
constructor(
1113
outputChannel:vscode.OutputChannel,
12-
statusBarBackground: StatusBarBackgroundItem
14+
statusBarBackground: StatusBarBackground
1315
){
1416
this._outputChannel=outputChannel;
15-
this.StatusBarBackground=statusBarBackground;
17+
this._statusBarBackground=statusBarBackground;
1618
}
1719

18-
public Output(value:string) {
19-
this._outputChannel.appendLine(value);
20+
public Output(value:string|IotResult) {
21+
let msg="";
22+
if (typeof value === 'string') {
23+
msg=value;
24+
} else {
25+
msg=value.toMultiLineString("head");
26+
}
27+
this._outputChannel.appendLine(msg);
28+
}
29+
30+
public ShowBackgroundNotification(text:string, tooltip:string | vscode.MarkdownString| undefined=undefined) {
31+
this._statusBarBackground.showAnimation(text,tooltip);
32+
}
33+
34+
public HideBackgroundNotification = () => this._statusBarBackground.hide();
35+
36+
public ShowNotification(value:IotResult) {
37+
if (!value.Message) return;
38+
switch(value.Status) {
39+
case StatusResult.Ok: {
40+
vscode.window.showInformationMessage(value.Message);
41+
break;
42+
}
43+
case StatusResult.Error: {
44+
vscode.window.showErrorMessage(value.Message);
45+
break;
46+
}
47+
case StatusResult.No: {
48+
vscode.window.showWarningMessage(value.Message);
49+
break;
50+
}
51+
default: {
52+
vscode.window.showInformationMessage(value.Message);
53+
break;
54+
}
55+
}
56+
}
57+
58+
public RunTask(value:IotResult,ifOK:() =>void,ifError:() =>void) {
59+
switch(value.Status) {
60+
case StatusResult.Ok: {
61+
ifOK();
62+
break;
63+
}
64+
case StatusResult.Error: {
65+
ifError();
66+
break;
67+
}
68+
default: {
69+
//statements;
70+
break;
71+
}
72+
}
2073
}
2174
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import * as vscode from 'vscode';
22
import * as fs from 'fs';
33
import * as path from 'path';
44

5-
export class StatusBarBackgroundItem {
5+
export class StatusBarBackground {
66
private _statusBarItem: vscode.StatusBarItem;
7-
//private _isShow:boolean=false;
87
private _animationText: string;
98

109
public get text(): string {

0 commit comments

Comments
 (0)