getConnections API (#5651)

* getConnections

* update

* fix the condition check

* pr feedback

* fix test cases

* add test for the new method

* address comments
This commit is contained in:
Alan Ren
2019-06-19 22:51:53 -07:00
committed by GitHub
parent 47cf496c36
commit b9a0c9ce7e
12 changed files with 201 additions and 9 deletions

View File

@@ -26,6 +26,10 @@ export class ExtHostConnectionManagement extends ExtHostConnectionManagementShap
return connection;
}
public $getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {
return this._proxy.$getConnections(activeConnectionsOnly);
}
// "sqlops" back-compat connection APIs
public $getActiveConnections(): Thenable<azdata.connection.Connection[]> {
return this._proxy.$getActiveConnections();

View File

@@ -18,6 +18,7 @@ import { generateUuid } from 'vs/base/common/uuid';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { IConnectionDialogService } from 'sql/workbench/services/connection/common/connectionDialogService';
import { deepClone } from 'vs/base/common/objects';
@extHostNamedCustomer(SqlMainContext.MainThreadConnectionManagement)
export class MainThreadConnectionManagement implements MainThreadConnectionManagementShape {
@@ -43,6 +44,10 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag
this._toDispose = dispose(this._toDispose);
}
public $getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {
return Promise.resolve(this._connectionManagementService.getConnections(activeConnectionsOnly).map(profile => this.convertToConnectionProfile(profile)));
}
public $getActiveConnections(): Thenable<azdata.connection.Connection[]> {
return Promise.resolve(this._connectionManagementService.getActiveConnections().map(profile => this.convertConnection(profile)));
}
@@ -117,6 +122,30 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag
return connection;
}
private convertToConnectionProfile(profile: IConnectionProfile): azdata.connection.ConnectionProfile {
if (!profile) {
return undefined;
}
profile = this._connectionManagementService.removeConnectionProfileCredentials(profile);
let connection: azdata.connection.ConnectionProfile = {
providerId: profile.providerName,
connectionId: profile.id,
options: deepClone(profile.options),
connectionName: profile.connectionName,
serverName: profile.serverName,
databaseName: profile.databaseName,
userName: profile.userName,
password: profile.password,
authenticationType: profile.authenticationType,
savePassword: profile.savePassword,
groupFullName: profile.groupFullName,
groupId: profile.groupId,
saveProfile: profile.saveProfile
};
return connection;
}
public $connect(connectionProfile: IConnectionProfile, saveConnection: boolean = true, showDashboard: boolean = true): Thenable<azdata.ConnectionResult> {
let profile = new ConnectionProfile(this._capabilitiesService, connectionProfile);
profile.id = generateUuid();

View File

@@ -99,9 +99,13 @@ export function createApiFactory(
getCurrentConnection(): Thenable<azdata.connection.ConnectionProfile> {
return extHostConnectionManagement.$getCurrentConnection();
},
getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {
return extHostConnectionManagement.$getConnections(activeConnectionsOnly);
},
// "sqlops" back-compat APIs
getActiveConnections(): Thenable<azdata.connection.Connection[]> {
console.warn('the method azdata.connection.getActiveConnections has been deprecated, replace it with azdata.connection.getConnections');
return extHostConnectionManagement.$getActiveConnections();
},
getCredentials(connectionId: string): Thenable<{ [name: string]: string }> {

View File

@@ -589,6 +589,7 @@ export interface MainThreadDataProtocolShape extends IDisposable {
}
export interface MainThreadConnectionManagementShape extends IDisposable {
$getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]>;
$getActiveConnections(): Thenable<azdata.connection.Connection[]>;
$getCurrentConnection(): Thenable<azdata.connection.Connection>;
$getCredentials(connectionId: string): Thenable<{ [name: string]: string }>;