@@ -65,15 +65,15 @@ export default class ConnectionController {
65
65
66
66
private _statusView : StatusView ;
67
67
private _storageController : StorageController ;
68
- public _telemetryController ? : TelemetryController ;
68
+ private _telemetryController : TelemetryController ;
69
69
70
70
// Used by other parts of the extension that respond to changes in the connections.
71
71
private eventEmitter : EventEmitter = new EventEmitter ( ) ;
72
72
73
73
constructor (
74
74
_statusView : StatusView ,
75
75
storageController : StorageController ,
76
- telemetryController ? : TelemetryController
76
+ telemetryController : TelemetryController
77
77
) {
78
78
this . _statusView = _statusView ;
79
79
this . _storageController = storageController ;
@@ -102,6 +102,7 @@ export default class ConnectionController {
102
102
}
103
103
104
104
let loadedSavedConnection : LoadedConnection ;
105
+
105
106
try {
106
107
const unparsedConnectionInformation = await this . _keytar . getPassword (
107
108
this . _serviceName ,
@@ -134,6 +135,7 @@ export default class ConnectionController {
134
135
// connections have become corrupted.
135
136
return Promise . resolve ( ) ;
136
137
}
138
+
137
139
this . _connections [ connectionId ] = loadedSavedConnection ;
138
140
this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
139
141
@@ -167,6 +169,7 @@ export default class ConnectionController {
167
169
StorageVariables . WORKSPACE_SAVED_CONNECTIONS ,
168
170
StorageScope . WORKSPACE
169
171
) || { } ;
172
+
170
173
if ( Object . keys ( existingWorkspaceConnections ) . length > 0 ) {
171
174
// Try to pull in the connections previously saved on the workspace.
172
175
await Promise . all (
@@ -181,9 +184,10 @@ export default class ConnectionController {
181
184
} ;
182
185
183
186
public async connectWithURI ( ) : Promise < boolean > {
187
+ let connectionString : any ;
188
+
184
189
log . info ( 'connectWithURI command called' ) ;
185
190
186
- let connectionString ;
187
191
try {
188
192
connectionString = await vscode . window . showInputBox ( {
189
193
value : '' ,
@@ -268,7 +272,6 @@ export default class ConnectionController {
268
272
const { driverUrl, instanceId } = connectionModel . getAttributes ( {
269
273
derived : true
270
274
} ) ;
271
-
272
275
const connectionId = uuidv4 ( ) ;
273
276
const connectionInformation : SavedConnectionInformation = {
274
277
connectionModel,
@@ -285,6 +288,7 @@ export default class ConnectionController {
285
288
...savedConnection ,
286
289
...connectionInformation
287
290
} ;
291
+
288
292
this . _connections [ connectionId ] = newLoadedConnection ;
289
293
290
294
if ( this . _keytar ) {
@@ -312,7 +316,7 @@ export default class ConnectionController {
312
316
} ) ;
313
317
} ;
314
318
315
- public async getCloudInfoFromDataService ( firstServerHostname ) {
319
+ public async getCloudInfoFromDataService ( firstServerHostname : string ) {
316
320
const cloudInfo = await getCloudInfo ( firstServerHostname ) ;
317
321
let isPublicCloud = false ;
318
322
let publicCloudName : string | null = null ;
@@ -339,6 +343,7 @@ export default class ConnectionController {
339
343
if ( error ) {
340
344
log . error ( 'TELEMETRY data service error' , error ) ;
341
345
}
346
+
342
347
if ( data ) {
343
348
try {
344
349
const firstServerHostname = dataService . client . model . hosts [ 0 ] . host ;
@@ -369,7 +374,7 @@ export default class ConnectionController {
369
374
} ;
370
375
371
376
// Send metrics to Segment
372
- this . _telemetryController ? .track (
377
+ this . _telemetryController . track (
373
378
TelemetryEventTypes . NEW_CONNECTION ,
374
379
telemetryData
375
380
) ;
@@ -396,7 +401,9 @@ export default class ConnectionController {
396
401
return Promise . reject (
397
402
new Error ( 'Unable to connect: already connecting.' )
398
403
) ;
399
- } else if ( this . _disconnecting ) {
404
+ }
405
+
406
+ if ( this . _disconnecting ) {
400
407
return Promise . reject (
401
408
new Error ( 'Unable to connect: currently disconnecting.' )
402
409
) ;
@@ -427,6 +434,7 @@ export default class ConnectionController {
427
434
this . _connecting = false ;
428
435
log . info ( 'Failed to connect' ) ;
429
436
this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
437
+
430
438
return reject ( new Error ( `Failed to connect: ${ err . message } ` ) ) ;
431
439
}
432
440
@@ -441,7 +449,7 @@ export default class ConnectionController {
441
449
this . eventEmitter . emit ( DataServiceEventTypes . CONNECTIONS_DID_CHANGE ) ;
442
450
this . eventEmitter . emit ( DataServiceEventTypes . ACTIVE_CONNECTION_CHANGED ) ;
443
451
444
- if ( this . _telemetryController ) {
452
+ if ( this . _telemetryController . needTelemetry ( ) ) {
445
453
this . sendTelemetry ( newDataService , connectionType ) ;
446
454
}
447
455
@@ -452,11 +460,12 @@ export default class ConnectionController {
452
460
453
461
public connectWithConnectionId = ( connectionId : string ) : Promise < boolean > => {
454
462
if ( this . _connections [ connectionId ] ) {
455
- let connectionModel ;
463
+ let connectionModel : any ;
456
464
457
465
try {
458
466
const savedConnectionModel = this . _connections [ connectionId ]
459
467
. connectionModel ;
468
+
460
469
// Here we rebuild the connection model to ensure it's up to date and
461
470
// contains the connection model class methods (not just attributes).
462
471
connectionModel = new Connection (
@@ -466,15 +475,18 @@ export default class ConnectionController {
466
475
) ;
467
476
} catch ( error ) {
468
477
vscode . window . showErrorMessage ( `Unable to load connection: ${ error } ` ) ;
478
+
469
479
return Promise . resolve ( false ) ;
470
480
}
481
+
471
482
return new Promise ( ( resolve ) => {
472
483
this . connect (
473
484
connectionId ,
474
485
connectionModel ,
475
486
ConnectionTypes . CONNECTION_ID
476
487
) . then ( resolve , ( err : Error ) => {
477
488
vscode . window . showErrorMessage ( err . message ) ;
489
+
478
490
return resolve ( false ) ;
479
491
} ) ;
480
492
} ) ;
@@ -493,6 +505,7 @@ export default class ConnectionController {
493
505
vscode . window . showErrorMessage (
494
506
'Unable to disconnect: already disconnecting from an instance.'
495
507
) ;
508
+
496
509
return Promise . resolve ( false ) ;
497
510
}
498
511
@@ -501,6 +514,7 @@ export default class ConnectionController {
501
514
vscode . window . showErrorMessage (
502
515
'Unable to disconnect: currently connecting to an instance.'
503
516
) ;
517
+
504
518
return Promise . resolve ( false ) ;
505
519
}
506
520
@@ -510,6 +524,7 @@ export default class ConnectionController {
510
524
vscode . window . showErrorMessage (
511
525
'Unable to disconnect: no active connection.'
512
526
) ;
527
+
513
528
return resolve ( false ) ;
514
529
}
515
530
@@ -544,6 +559,7 @@ export default class ConnectionController {
544
559
connectionId : string
545
560
) : Promise < void > => {
546
561
delete this . _connections [ connectionId ] ;
562
+
547
563
if ( this . _keytar ) {
548
564
await this . _keytar . deletePassword ( this . _serviceName , connectionId ) ;
549
565
// We only remove the connection from the saved connections if we
@@ -563,19 +579,23 @@ export default class ConnectionController {
563
579
vscode . window . showErrorMessage (
564
580
'Unable to remove connection: currently connecting.'
565
581
) ;
582
+
566
583
return Promise . resolve ( false ) ;
567
584
}
585
+
568
586
// Ensure we aren't currently disconnecting.
569
587
if ( this . _disconnecting ) {
570
588
vscode . window . showErrorMessage (
571
589
'Unable to remove connection: currently disconnecting.'
572
590
) ;
591
+
573
592
return Promise . resolve ( false ) ;
574
593
}
575
594
576
595
if ( ! this . _connections [ connectionId ] ) {
577
596
// No active connection(s) to remove.
578
597
vscode . window . showErrorMessage ( 'Connection does not exist.' ) ;
598
+
579
599
return Promise . resolve ( false ) ;
580
600
}
581
601
@@ -596,6 +616,7 @@ export default class ConnectionController {
596
616
await this . removeSavedConnection ( connectionId ) ;
597
617
598
618
vscode . window . showInformationMessage ( 'MongoDB connection removed.' ) ;
619
+
599
620
return Promise . resolve ( true ) ;
600
621
}
601
622
@@ -607,13 +628,16 @@ export default class ConnectionController {
607
628
vscode . window . showErrorMessage (
608
629
'Unable to remove connection: currently connecting.'
609
630
) ;
631
+
610
632
return Promise . resolve ( false ) ;
611
633
}
634
+
612
635
// Ensure we aren't currently disconnecting.
613
636
if ( this . _disconnecting ) {
614
637
vscode . window . showErrorMessage (
615
638
'Unable to remove connection: currently disconnecting.'
616
639
) ;
640
+
617
641
return Promise . resolve ( false ) ;
618
642
}
619
643
@@ -622,6 +646,7 @@ export default class ConnectionController {
622
646
if ( connectionIds . length === 0 ) {
623
647
// No active connection(s) to remove.
624
648
vscode . window . showErrorMessage ( 'No connections to remove.' ) ;
649
+
625
650
return Promise . resolve ( false ) ;
626
651
}
627
652
@@ -655,7 +680,8 @@ export default class ConnectionController {
655
680
}
656
681
657
682
public async renameConnection ( connectionId : string ) : Promise < boolean > {
658
- let inputtedConnectionName ;
683
+ let inputtedConnectionName : any ;
684
+
659
685
try {
660
686
inputtedConnectionName = await vscode . window . showInputBox ( {
661
687
value : this . _connections [ connectionId ] . name ,
@@ -694,7 +720,9 @@ export default class ConnectionController {
694
720
return this . _storageController
695
721
. saveConnectionToGlobalStore ( this . _connections [ connectionId ] )
696
722
. then ( ( ) => resolve ( true ) , reject ) ;
697
- } else if (
723
+ }
724
+
725
+ if (
698
726
this . _connections [ connectionId ] . storageLocation ===
699
727
StorageScope . WORKSPACE
700
728
) {
@@ -806,15 +834,19 @@ export default class ConnectionController {
806
834
this . _disconnecting = false ;
807
835
this . _connectingConnectionId = '' ;
808
836
}
837
+
809
838
public setActiveConnection ( newActiveConnection : any ) : void {
810
839
this . _activeDataService = newActiveConnection ;
811
840
}
841
+
812
842
public setConnnecting ( connecting : boolean ) : void {
813
843
this . _connecting = connecting ;
814
844
}
845
+
815
846
public setConnnectingConnectionId ( connectingConnectionId : string ) : void {
816
847
this . _connectingConnectionId = connectingConnectionId ;
817
848
}
849
+
818
850
public setDisconnecting ( disconnecting : boolean ) : void {
819
851
this . _disconnecting = disconnecting ;
820
852
}
0 commit comments