mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-13 19:48:37 -05:00
Disconnect Object Explorer node when session is disconnected from SQL Tools Service (#3249)
* WIP * WIP * Send disconnect event to OE * Bump dataprotocol to 0.2.9 * Cleanupps * Address a couple feedback
This commit is contained in:
@@ -20,6 +20,7 @@ import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { warn, error } from 'sql/base/common/log';
|
||||
import { ServerTreeView } from 'sql/parts/objectExplorer/viewlet/serverTreeView';
|
||||
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
|
||||
import * as Utils from 'sql/parts/connection/common/utils';
|
||||
|
||||
export const SERVICE_ID = 'ObjectExplorerService';
|
||||
|
||||
@@ -42,6 +43,8 @@ export interface IObjectExplorerService {
|
||||
|
||||
onSessionCreated(handle: number, sessionResponse: sqlops.ObjectExplorerSession);
|
||||
|
||||
onSessionDisconnected(handle: number, sessionResponse: sqlops.ObjectExplorerSession);
|
||||
|
||||
onNodeExpanded(handle: number, sessionResponse: sqlops.ObjectExplorerExpandInfo);
|
||||
|
||||
/**
|
||||
@@ -205,6 +208,29 @@ export class ObjectExplorerService implements IObjectExplorerService {
|
||||
this.sendUpdateNodeEvent(connection, errorMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets called when session is disconnected
|
||||
*/
|
||||
public onSessionDisconnected(handle: number, session: sqlops.ObjectExplorerSession) {
|
||||
if (this._sessions[session.sessionId]) {
|
||||
let connection: ConnectionProfile = this._sessions[session.sessionId].connection;
|
||||
if (connection && this._connectionManagementService.isProfileConnected(connection)) {
|
||||
let uri: string = Utils.generateUri(connection);
|
||||
if (this._serverTreeView.isObjectExplorerConnectionUri(uri)) {
|
||||
this._serverTreeView.deleteObjectExplorerNodeAndRefreshTree(connection).then(() => {
|
||||
this.sendUpdateNodeEvent(connection, session.errorMessage);
|
||||
connection.isDisconnecting = true;
|
||||
this._connectionManagementService.disconnect(connection).then((value) => {
|
||||
connection.isDisconnecting = false;
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
warn(`Cannot find session ${session.sessionId}`);
|
||||
}
|
||||
}
|
||||
|
||||
private sendUpdateNodeEvent(connection: ConnectionProfile, errorMessage: string = undefined) {
|
||||
let eventArgs: ObjectExplorerNodeEventArgs = {
|
||||
connection: <IConnectionProfile>connection,
|
||||
|
||||
@@ -150,7 +150,7 @@ export class ServerTreeView {
|
||||
});
|
||||
}
|
||||
|
||||
private isObjectExplorerConnectionUri(uri: string): boolean {
|
||||
public isObjectExplorerConnectionUri(uri: string): boolean {
|
||||
let isBackupRestoreUri: boolean = uri.indexOf(ConnectionUtils.ConnectionUriBackupIdAttributeName) >= 0 ||
|
||||
uri.indexOf(ConnectionUtils.ConnectionUriRestoreIdAttributeName) >= 0;
|
||||
return uri && uri.startsWith(ConnectionUtils.uriPrefixes.default) && !isBackupRestoreUri;
|
||||
@@ -227,16 +227,17 @@ export class ServerTreeView {
|
||||
}
|
||||
}
|
||||
|
||||
public deleteObjectExplorerNodeAndRefreshTree(connection: IConnectionProfile): void {
|
||||
public deleteObjectExplorerNodeAndRefreshTree(connection: IConnectionProfile): Thenable<void> {
|
||||
if (connection) {
|
||||
var conn = this.getConnectionInTreeInput(connection.id);
|
||||
if (conn) {
|
||||
this._objectExplorerService.deleteObjectExplorerNode(conn).then(() => {
|
||||
return this._objectExplorerService.deleteObjectExplorerNode(conn).then(() => {
|
||||
this._tree.collapse(conn);
|
||||
this._tree.refresh(conn);
|
||||
});
|
||||
}
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
public refreshTree(): void {
|
||||
|
||||
Reference in New Issue
Block a user