Initial LiveShare extension scaffolding (#7170)

* LiveShare initial shared connection

* Various cleanups

* Fix type

* Fix hygiene
This commit is contained in:
Karl Burtram
2019-09-11 15:24:08 -07:00
committed by GitHub
parent 9765b0ed8e
commit 9df66deb81
33 changed files with 3126 additions and 36 deletions

View File

@@ -82,6 +82,31 @@ export class MainThreadConnectionManagement extends Disposable implements MainTh
return Promise.resolve(this._connectionManagementService.getConnections(activeConnectionsOnly).map(profile => this.convertToConnectionProfile(profile)));
}
public $getConnection(uri: string): Thenable<azdata.connection.ConnectionProfile> {
let profile = this._connectionManagementService.getConnection(uri);
if (!profile) {
return Promise.resolve(undefined);
}
let connection: azdata.connection.ConnectionProfile = {
providerId: profile.providerName,
connectionId: profile.id,
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.savePassword,
azureTenantId: profile.azureTenantId,
options: profile.options
};
return Promise.resolve(connection);
}
public $getActiveConnections(): Thenable<azdata.connection.Connection[]> {
return Promise.resolve(this._connectionManagementService.getActiveConnections().map(profile => this.convertConnection(profile)));
}

View File

@@ -13,6 +13,8 @@ import { Disposable } from 'vs/base/common/lifecycle';
import { IQueryModelService } from 'sql/platform/query/common/queryModel';
import * as azdata from 'azdata';
import { IQueryManagementService } from 'sql/platform/query/common/queryManagement';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
@extHostNamedCustomer(SqlMainContext.MainThreadQueryEditor)
export class MainThreadQueryEditor extends Disposable implements MainThreadQueryEditorShape {
@@ -62,6 +64,36 @@ export class MainThreadQueryEditor extends Disposable implements MainThreadQuery
});
}
private static connectionProfileToIConnectionProfile(connection: azdata.connection.ConnectionProfile): IConnectionProfile {
let profile: ConnectionProfile = new ConnectionProfile(undefined, undefined);
profile.options = connection.options;
profile.providerName = connection.options['providerName'];
return profile.toIConnectionProfile();
}
public $connectWithProfile(fileUri: string, connection: azdata.connection.ConnectionProfile): Thenable<void> {
return new Promise<void>(async (resolve, reject) => {
let editors = this._editorService.visibleControls.filter(resource => {
return !!resource && resource.input.getResource().toString() === fileUri;
});
let editor = editors && editors.length > 0 ? editors[0] : undefined;
let options: IConnectionCompletionOptions = {
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: editor ? editor.input as any : undefined },
saveTheConnection: false,
showDashboard: false,
showConnectionDialogOnError: false,
showFirewallRuleOnError: false,
};
let profile: IConnectionProfile = MainThreadQueryEditor.connectionProfileToIConnectionProfile(connection);
let connectionResult = await this._connectionManagementService.connect(profile, fileUri, options);
if (connectionResult && connectionResult.connected) {
console.log(`editor ${fileUri} connected`);
}
});
}
public $runQuery(fileUri: string, runCurrentQuery: boolean = true): void {
let filteredEditors = this._editorService.visibleControls.filter(editor => editor.input.getResource().toString() === fileUri);
if (filteredEditors && filteredEditors.length > 0) {