Add connection event listeners (#6540)

This commit is contained in:
Karl Burtram
2019-07-31 11:52:58 -07:00
committed by GitHub
parent 2c79d49487
commit bc4b527de0
5 changed files with 78 additions and 2 deletions

View File

@@ -7,7 +7,7 @@ import { SqlExtHostContext, SqlMainContext, ExtHostConnectionManagementShape, Ma
import * as azdata from 'azdata';
import { IExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { IConnectionManagementService, ConnectionType } from 'sql/platform/connection/common/connectionManagement';
import { IConnectionManagementService, ConnectionType, IConnectionParams } from 'sql/platform/connection/common/connectionManagement';
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/common/objectExplorerService';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import * as TaskUtilities from 'sql/workbench/browser/taskUtilities';
@@ -44,6 +44,45 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag
this._toDispose = dispose(this._toDispose);
}
public $registerConnectionEventListener(handle: number, providerId: string): void {
let stripProfile = (inputProfile: azdata.IConnectionProfile) => {
if (!inputProfile) {
return inputProfile;
}
let outputProfile: azdata.IConnectionProfile = {
connectionName: inputProfile.connectionName,
serverName: inputProfile.serverName,
databaseName: inputProfile.databaseName,
userName: inputProfile.userName,
password: inputProfile.password,
authenticationType: inputProfile.authenticationType,
savePassword: inputProfile.savePassword,
groupFullName: inputProfile.groupFullName,
groupId: inputProfile.groupId,
providerName: inputProfile.providerName,
saveProfile: inputProfile.saveProfile,
id: inputProfile.id,
azureTenantId: inputProfile.azureTenantId,
options: inputProfile.options
};
return outputProfile;
};
this._connectionManagementService.onConnect((params: IConnectionParams) => {
this._proxy.$onConnectionEvent(handle, 'onConnect', params.connectionUri, stripProfile(params.connectionProfile));
});
this._connectionManagementService.onConnectionChanged((params: IConnectionParams) => {
this._proxy.$onConnectionEvent(handle, 'onConnectionChanged', params.connectionUri, stripProfile(params.connectionProfile));
});
this._connectionManagementService.onDisconnect((params: IConnectionParams) => {
this._proxy.$onConnectionEvent(handle, 'onDisconnect', params.connectionUri, stripProfile(params.connectionProfile));
});
}
public $getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {
return Promise.resolve(this._connectionManagementService.getConnections(activeConnectionsOnly).map(profile => this.convertToConnectionProfile(profile)));
}