mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-06 01:25:38 -05:00
Make connection for new Notebook (#4770)
* Make connection for new Notebook * Resolve merge issue * User connectionUri to track the connects need to be disconnected * Removed debugging log
This commit is contained in:
@@ -72,9 +72,9 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
private _onValidConnectionSelected = new Emitter<boolean>();
|
||||
private _oldKernel: nb.IKernel;
|
||||
private _clientSessionListeners: IDisposable[] = [];
|
||||
private _connectionsToDispose: ConnectionProfile[] = [];
|
||||
private _connectionUrisToDispose: string[] = [];
|
||||
|
||||
constructor(private _notebookOptions: INotebookModelOptions, startSessionImmediately?: boolean, private connectionProfile?: IConnectionProfile) {
|
||||
constructor(private _notebookOptions: INotebookModelOptions, startSessionImmediately?: boolean, public connectionProfile?: IConnectionProfile) {
|
||||
super();
|
||||
if (!_notebookOptions || !_notebookOptions.notebookUri || !_notebookOptions.notebookManagers) {
|
||||
throw new Error('path or notebook service not defined');
|
||||
@@ -490,7 +490,7 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
}
|
||||
|
||||
private isValidConnection(profile: IConnectionProfile | connection.Connection) {
|
||||
let standardKernels = this._notebookOptions.standardKernels.find(kernel => this._savedKernelInfo && kernel.displayName === this._savedKernelInfo.display_name);
|
||||
let standardKernels = this._notebookOptions.standardKernels.find(kernel => this._defaultKernel && kernel.displayName === this._defaultKernel.display_name);
|
||||
let connectionProviderIds = standardKernels ? standardKernels.connectionProviderIds : undefined;
|
||||
return profile && connectionProviderIds && connectionProviderIds.find(provider => provider === profile.providerName) !== undefined;
|
||||
}
|
||||
@@ -652,7 +652,6 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
if (newConnection) {
|
||||
this._activeConnection = newConnection;
|
||||
this.refreshConnections(newConnection);
|
||||
console.log(this._activeConnection);
|
||||
this._activeClientSession.updateConnection(newConnection.toIConnectionProfile()).then(
|
||||
result => {
|
||||
//Remove 'Select connection' from 'Attach to' drop-down since its a valid connection
|
||||
@@ -746,8 +745,8 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
return newKernelDisplayName;
|
||||
}
|
||||
|
||||
public addAttachToConnectionsToBeDisposed(conn: ConnectionProfile) {
|
||||
this._connectionsToDispose.push(conn);
|
||||
public addAttachToConnectionsToBeDisposed(connUri: string) {
|
||||
this._connectionUrisToDispose.push(connUri);
|
||||
}
|
||||
|
||||
private setErrorState(errMsg: string): void {
|
||||
@@ -896,16 +895,17 @@ export class NotebookModel extends Disposable implements INotebookModel {
|
||||
// let connectionUri = Utils.generateUri(connection, 'notebook');
|
||||
private async disconnectNotebookConnection(conn: ConnectionProfile): Promise<void> {
|
||||
if (this.notebookOptions.connectionService.getConnectionUri(conn).includes(uriPrefixes.notebook)) {
|
||||
await this.notebookOptions.connectionService.disconnect(conn).catch(e => console.log(e));
|
||||
let uri = this._notebookOptions.connectionService.getConnectionUri(conn);
|
||||
await this.notebookOptions.connectionService.disconnect(uri).catch(e => console.log(e));
|
||||
}
|
||||
}
|
||||
|
||||
// Disconnect any connections that were added through the "Add new connection" functionality in the Attach To dropdown
|
||||
private async disconnectAttachToConnections(): Promise<void> {
|
||||
this._connectionsToDispose.forEach(async conn => {
|
||||
notebookUtils.asyncForEach(this._connectionUrisToDispose, async conn => {
|
||||
await this.notebookOptions.connectionService.disconnect(conn).catch(e => console.log(e));
|
||||
});
|
||||
this._connectionsToDispose = [];
|
||||
this._connectionUrisToDispose = [];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -21,7 +21,7 @@ import { ConnectionProfile } from 'sql/platform/connection/common/connectionProf
|
||||
import { noKernel } from 'sql/workbench/services/notebook/common/sessionManager';
|
||||
import { IConnectionDialogService } from 'sql/workbench/services/connection/common/connectionDialogService';
|
||||
import { NotebookModel } from 'sql/parts/notebook/models/notebookModel';
|
||||
import { CellModel } from 'sql/parts/notebook/models/cell';
|
||||
import { generateUri } from 'sql/platform/connection/common/utils';
|
||||
|
||||
const msgLoading = localize('loading', "Loading kernels...");
|
||||
const msgChanging = localize('changing', "Changing kernel...");
|
||||
@@ -320,6 +320,19 @@ export class AttachToDropdown extends SelectBox {
|
||||
}
|
||||
|
||||
private updateAttachToDropdown(model: INotebookModel): void {
|
||||
if (this.model.connectionProfile && this.model.connectionProfile.serverName) {
|
||||
let connectionUri = generateUri(this.model.connectionProfile, 'notebook');
|
||||
this.model.notebookOptions.connectionService.connect(this.model.connectionProfile, connectionUri).then(result => {
|
||||
if (result.connected) {
|
||||
let connectionProfile = new ConnectionProfile(this._capabilitiesService, result.connectionProfile);
|
||||
this.model.addAttachToConnectionsToBeDisposed(connectionUri);
|
||||
this.doChangeContext(connectionProfile);
|
||||
} else {
|
||||
this.openConnectionDialog(true);
|
||||
}
|
||||
}).catch(err =>
|
||||
console.log(err));
|
||||
}
|
||||
model.onValidConnectionSelected(validConnection => {
|
||||
this.handleContextsChanged(!validConnection);
|
||||
});
|
||||
@@ -427,15 +440,16 @@ export class AttachToDropdown extends SelectBox {
|
||||
* Bind the server value to 'Attach To' drop down
|
||||
* Connected server is displayed at the top of drop down
|
||||
**/
|
||||
public async openConnectionDialog(): Promise<void> {
|
||||
public async openConnectionDialog(useProfile: boolean = false): Promise<void> {
|
||||
try {
|
||||
await this._connectionDialogService.openDialogAndWait(this._connectionManagementService, { connectionType: 1, providers: this.model.getApplicableConnectionProviderIds(this.model.clientSession.kernel.name) }).then(connection => {
|
||||
await this._connectionDialogService.openDialogAndWait(this._connectionManagementService, { connectionType: 1, providers: this.model.getApplicableConnectionProviderIds(this.model.clientSession.kernel.name) }, useProfile ? this.model.connectionProfile : undefined).then(connection => {
|
||||
let attachToConnections = this.values;
|
||||
if (!connection) {
|
||||
this.loadAttachToDropdown(this.model, this.getKernelDisplayName());
|
||||
this.doChangeContext(undefined, true);
|
||||
return;
|
||||
}
|
||||
let connectionUri = this._connectionManagementService.getConnectionUri(connection);
|
||||
let connectionProfile = new ConnectionProfile(this._capabilitiesService, connection);
|
||||
let connectedServer = connectionProfile.title? connectionProfile.title : connectionProfile.serverName;
|
||||
//Check to see if the same server is already there in dropdown. We only have server names in dropdown
|
||||
@@ -458,7 +472,7 @@ export class AttachToDropdown extends SelectBox {
|
||||
}
|
||||
this.select(index);
|
||||
|
||||
this.model.addAttachToConnectionsToBeDisposed(connectionProfile);
|
||||
this.model.addAttachToConnectionsToBeDisposed(connectionUri);
|
||||
// Call doChangeContext to set the newly chosen connection in the model
|
||||
this.doChangeContext(connectionProfile);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user