mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Add connection event listeners (#6540)
This commit is contained in:
18
src/sql/azdata.proposed.d.ts
vendored
18
src/sql/azdata.proposed.d.ts
vendored
@@ -8,4 +8,22 @@
|
|||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
declare module 'azdata' {
|
declare module 'azdata' {
|
||||||
|
/**
|
||||||
|
* Namespace for connection management
|
||||||
|
*/
|
||||||
|
export namespace connection {
|
||||||
|
export type ConnectionEventType =
|
||||||
|
| 'onConnect'
|
||||||
|
| 'onDisconnect'
|
||||||
|
| 'onConnectionChanged';
|
||||||
|
|
||||||
|
export interface ConnectionEventListener {
|
||||||
|
onConnectionEvent(type: ConnectionEventType, ownerUri: string, args: IConnectionProfile): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a connection event listener
|
||||||
|
*/
|
||||||
|
export function registerConnectionEventListener(listener: connection.ConnectionEventListener): void;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { SqlExtHostContext, SqlMainContext, ExtHostConnectionManagementShape, Ma
|
|||||||
import * as azdata from 'azdata';
|
import * as azdata from 'azdata';
|
||||||
import { IExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
|
import { IExtHostContext } from 'vs/workbench/api/common/extHost.protocol';
|
||||||
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
|
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 { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/common/objectExplorerService';
|
||||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||||
import * as TaskUtilities from 'sql/workbench/browser/taskUtilities';
|
import * as TaskUtilities from 'sql/workbench/browser/taskUtilities';
|
||||||
@@ -44,6 +44,45 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag
|
|||||||
this._toDispose = dispose(this._toDispose);
|
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[]> {
|
public $getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {
|
||||||
return Promise.resolve(this._connectionManagementService.getConnections(activeConnectionsOnly).map(profile => this.convertToConnectionProfile(profile)));
|
return Promise.resolve(this._connectionManagementService.getConnections(activeConnectionsOnly).map(profile => this.convertToConnectionProfile(profile)));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import * as azdata from 'azdata';
|
|||||||
export class ExtHostConnectionManagement extends ExtHostConnectionManagementShape {
|
export class ExtHostConnectionManagement extends ExtHostConnectionManagementShape {
|
||||||
|
|
||||||
private _proxy: MainThreadConnectionManagementShape;
|
private _proxy: MainThreadConnectionManagementShape;
|
||||||
|
private _nextListenerHandle: number = 0;
|
||||||
|
private _connectionListeners = new Map<number, azdata.connection.ConnectionEventListener>();
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
mainContext: IMainContext
|
mainContext: IMainContext
|
||||||
@@ -22,6 +24,19 @@ export class ExtHostConnectionManagement extends ExtHostConnectionManagementShap
|
|||||||
return this._proxy.$getCurrentConnectionProfile();
|
return this._proxy.$getCurrentConnectionProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public $onConnectionEvent(handle: number, type: azdata.connection.ConnectionEventType, ownerUri: string, profile: azdata.IConnectionProfile): void {
|
||||||
|
let listener = this._connectionListeners[handle];
|
||||||
|
if (listener) {
|
||||||
|
listener.onConnectionEvent(type, ownerUri, profile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public $registerConnectionEventListener(providerId: string, listener: azdata.connection.ConnectionEventListener): void {
|
||||||
|
this._connectionListeners[this._nextListenerHandle] = listener;
|
||||||
|
this._proxy.$registerConnectionEventListener(this._nextListenerHandle, providerId);
|
||||||
|
this._nextListenerHandle++;
|
||||||
|
}
|
||||||
|
|
||||||
public $getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {
|
public $getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {
|
||||||
return this._proxy.$getConnections(activeConnectionsOnly);
|
return this._proxy.$getConnections(activeConnectionsOnly);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export abstract class ExtHostAccountManagementShape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export abstract class ExtHostConnectionManagementShape {
|
export abstract class ExtHostConnectionManagementShape {
|
||||||
$onConnectionOpened(handleId: string, connection: azdata.connection.Connection): void { throw ni; }
|
$onConnectionEvent(handle: number, type: azdata.connection.ConnectionEventType, ownerUri: string, profile: azdata.IConnectionProfile): void { throw ni(); }
|
||||||
}
|
}
|
||||||
|
|
||||||
export abstract class ExtHostDataProtocolShape {
|
export abstract class ExtHostDataProtocolShape {
|
||||||
@@ -606,6 +606,7 @@ export interface MainThreadDataProtocolShape extends IDisposable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MainThreadConnectionManagementShape extends IDisposable {
|
export interface MainThreadConnectionManagementShape extends IDisposable {
|
||||||
|
$registerConnectionEventListener(handle: number, providerId: string): void;
|
||||||
$getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]>;
|
$getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]>;
|
||||||
$getActiveConnections(): Thenable<azdata.connection.Connection[]>;
|
$getActiveConnections(): Thenable<azdata.connection.Connection[]>;
|
||||||
$getCurrentConnection(): Thenable<azdata.connection.Connection>;
|
$getCurrentConnection(): Thenable<azdata.connection.Connection>;
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ export function createApiFactory(
|
|||||||
getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {
|
getConnections(activeConnectionsOnly?: boolean): Thenable<azdata.connection.ConnectionProfile[]> {
|
||||||
return extHostConnectionManagement.$getConnections(activeConnectionsOnly);
|
return extHostConnectionManagement.$getConnections(activeConnectionsOnly);
|
||||||
},
|
},
|
||||||
|
registerConnectionEventListener(listener: azdata.connection.ConnectionEventListener): void {
|
||||||
|
return extHostConnectionManagement.$registerConnectionEventListener(mssqlProviderName, listener);
|
||||||
|
},
|
||||||
|
|
||||||
// "sqlops" back-compat APIs
|
// "sqlops" back-compat APIs
|
||||||
getActiveConnections(): Thenable<azdata.connection.Connection[]> {
|
getActiveConnections(): Thenable<azdata.connection.Connection[]> {
|
||||||
|
|||||||
Reference in New Issue
Block a user