@@ -9,71 +9,65 @@ import { IotDevice } from '../IotDevice';
99import { BaseTreeItem } from '../BaseTreeItem' ;
1010import { ItemQuickPick } from '../Helper/actionHelper' ;
1111import { IoTHelper } from '../Helper/IoTHelper' ;
12- import { IContexUI } from '../ui/IContexUI' ;
12+ import { IContexUI } from '../ui/IContexUI' ;
1313
14- export async function addDevice ( treeData : TreeDataDevicesProvider , treeView :vscode . TreeView < BaseTreeItem > , contextUI :IContexUI ) : Promise < void > {
15-
16- let hostName = await vscode . window . showInputBox ( {
17- prompt : 'prompt' ,
18- title : 'Add Device (1/5). Enter the host of the developer board' ,
19- value :'192.168.50.75' ,
20- } ) ;
21-
22- if ( hostName == undefined ) return ;
23- hostName = IoTHelper . StringTrim ( hostName ) ;
24-
25- let portAnswer = await vscode . window . showInputBox ( {
26- prompt : 'prompt' ,
27- title : 'Add Device (2/5). Enter a number port ssh' ,
28- value :'22'
29- } ) ;
30- if ( portAnswer == undefined ) return ;
31- portAnswer = IoTHelper . StringTrim ( portAnswer ) ;
32- const port = + portAnswer ;
33- let userName = await vscode . window . showInputBox ( {
34- prompt : 'prompt' ,
35- title : 'Add Device (3/5). Enter username with sudo rights (usually root)' ,
36- value :'root'
37- } ) ;
38- if ( userName == undefined ) return ;
39- userName = IoTHelper . StringTrim ( userName ) ;
40-
41- const password = await vscode . window . showInputBox ( {
42- placeHolder : `Add Device (4/5). Enter user password ${ userName } ` ,
43- password : true
44- } ) ;
45- if ( password == undefined ) return ;
46-
47- //select account: debugvscode or root
48- let itemAccounts :Array < ItemQuickPick > = [ ] ;
49- let item = new ItemQuickPick ( treeData . Config . UsernameAccountDevice , "(default)" , treeData . Config . UsernameAccountDevice ) ;
50- itemAccounts . push ( item ) ;
51- item = new ItemQuickPick ( "root" , "Select if you have problems accessing /dev/* and /sys/* devices" , "root" ) ;
52- itemAccounts . push ( item ) ;
53- const SELECTED_ITEM = await vscode . window . showQuickPick
54- ( itemAccounts , { title : 'Add Device (5/5). Select an account to debugging .NET applications:' , } ) ;
55- if ( ! SELECTED_ITEM ) return ;
56- //Info
57- vscode . window . showInformationMessage ( 'It may take 2 to 7 minutes to initialize and configure the device.' ) ;
58- contextUI . Output ( "Action: adding a device" ) ;
59- //Adding a device is the main process
60- contextUI . ShowBackgroundNotification ( "Adding a device" ) ;
61- const result = await treeData . AddDevice ( hostName , port , userName , password , SELECTED_ITEM . value ) ;
62- contextUI . HideBackgroundNotification ( ) ;
63- //Output
64- contextUI . Output ( result . toStringWithHead ( ) ) ;
65- //Message
66- if ( result . Status == StatusResult . Ok )
67- {
68- vscode . window . showInformationMessage ( 'Device added successfully' ) ;
69- //Set focus
70- const device = < IotDevice > result . returnObject ;
71- treeView . reveal ( device , { focus : true } ) ;
72- //Connection test
73- const newDevice = treeData . RootItems [ treeData . RootItems . length - 1 ] ;
74- connectionTestDevice ( treeData , newDevice , contextUI ) ;
75- } else
76- {
77- vscode . window . showErrorMessage ( `Error. Device not added! \n${ result . Message } ` ) ;
78- }
14+ export async function addDevice ( treeData : TreeDataDevicesProvider , treeView :vscode . TreeView < BaseTreeItem > , contextUI :IContexUI ) : Promise < void > {
15+
16+ let hostName = await vscode . window . showInputBox ( {
17+ prompt : 'prompt' ,
18+ title : 'Add Device (1/5). Enter the host of the developer board' ,
19+ value :'192.168.50.75' ,
20+ } ) ;
21+ if ( ! hostName ) return ;
22+ hostName = IoTHelper . StringTrim ( hostName ) ;
23+ let portAnswer = await vscode . window . showInputBox ( {
24+ prompt : 'prompt' ,
25+ title : 'Add Device (2/5). Enter a number port ssh' ,
26+ value :'22'
27+ } ) ;
28+ if ( ! portAnswer ) return ;
29+ portAnswer = IoTHelper . StringTrim ( portAnswer ) ;
30+ const port = + portAnswer ;
31+ let userName = await vscode . window . showInputBox ( {
32+ prompt : 'prompt' ,
33+ title : 'Add Device (3/5). Enter username with sudo rights (usually root)' ,
34+ value :'root'
35+ } ) ;
36+ if ( ! userName ) return ;
37+ userName = IoTHelper . StringTrim ( userName ) ;
38+ const password = await vscode . window . showInputBox ( {
39+ placeHolder : `Add Device (4/5). Enter user password ${ userName } ` ,
40+ password : true
41+ } ) ;
42+ if ( ! password ) return ;
43+ //select account: debugvscode or root
44+ let itemAccounts :Array < ItemQuickPick > = [ ] ;
45+ let item = new ItemQuickPick ( treeData . Config . UsernameAccountDevice , "(default)" , treeData . Config . UsernameAccountDevice ) ;
46+ itemAccounts . push ( item ) ;
47+ item = new ItemQuickPick ( "root" , "Select if you have problems accessing /dev/* and /sys/* devices" , "root" ) ;
48+ itemAccounts . push ( item ) ;
49+ const SELECTED_ITEM = await vscode . window . showQuickPick (
50+ itemAccounts , { title : 'Add Device (5/5). Select an account to debugging .NET applications:' , } ) ;
51+ if ( ! SELECTED_ITEM ) return ;
52+ const accountNameDebug = SELECTED_ITEM . value ;
53+ //Info
54+ vscode . window . showInformationMessage ( 'It may take 2 to 7 minutes to initialize and configure the device.' ) ;
55+ //Main process
56+ contextUI . Output ( "Action: adding a device" ) ;
57+ //Adding a device is the main process
58+ contextUI . ShowBackgroundNotification ( "Adding a device" ) ;
59+ const result = await treeData . AddDevice ( hostName , port , userName , password , accountNameDebug ) ;
60+ contextUI . HideBackgroundNotification ( ) ;
61+ //Output
62+ contextUI . Output ( result . toStringWithHead ( ) ) ;
63+ //Message
64+ contextUI . ShowNotification ( result ) ;
65+ if ( result . Status == StatusResult . Ok ) {
66+ //get device
67+ const newDevice = < IotDevice > result . returnObject ;
68+ //Connection test
69+ connectionTestDevice ( treeData , newDevice , contextUI ) ;
70+ //Set focus
71+ treeView . reveal ( newDevice , { focus : true } ) ;
72+ }
7973}
0 commit comments