Add GetConnectionString command (without build break) (#2120)

* Revert "Revert "Adds "Get Connection String" command (#2108)" (#2116)"

This reverts commit c6d1fa2b7d.

* Fix build breaks
This commit is contained in:
Karl Burtram
2018-08-01 20:15:14 -04:00
committed by GitHub
parent c6d1fa2b7d
commit f4fa18ec05
16 changed files with 130 additions and 9 deletions

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { IExtensionGalleryService, IExtensionTipsService } from 'vs/platform/extensionManagement/common/extensionManagement';
import { IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
import { EditorDescriptor, IEditorRegistry, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
import { IExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/common/extensions';
import { IConfigurationRegistry, Extensions as ConfigExtensions } from 'vs/platform/configuration/common/configurationRegistry';
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
@@ -13,10 +13,9 @@ import { Registry } from 'vs/platform/registry/common/platform';
import { DashboardEditor } from 'sql/parts/dashboard/dashboardEditor';
import { DashboardInput } from 'sql/parts/dashboard/dashboardInput';
import { AddServerGroupAction, AddServerAction } from 'sql/parts/objectExplorer/viewlet/connectionTreeAction';
import { ClearRecentConnectionsAction } from 'sql/parts/connection/common/connectionActions';
import { ClearRecentConnectionsAction, GetCurrentConnectionStringAction } from 'sql/parts/connection/common/connectionActions';
import { ExtensionGalleryService } from 'vs/platform/extensionManagement/node/extensionGalleryService';
import { EditorDescriptor } from 'vs/workbench/browser/editor';
import { ExtensionTipsService } from 'vs/workbench/parts/extensions/electron-browser/extensionTipsService';
import { ExtensionsWorkbenchService } from 'vs/workbench/parts/extensions/node/extensionsWorkbenchService';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actions';
@@ -49,6 +48,7 @@ actionRegistry.registerWorkbenchAction(
),
ClearRecentConnectionsAction.LABEL
);
actionRegistry.registerWorkbenchAction(
new SyncActionDescriptor(
AddServerGroupAction,
@@ -67,6 +67,15 @@ actionRegistry.registerWorkbenchAction(
AddServerAction.LABEL
);
actionRegistry.registerWorkbenchAction(
new SyncActionDescriptor(
GetCurrentConnectionStringAction,
GetCurrentConnectionStringAction.ID,
GetCurrentConnectionStringAction.LABEL
),
GetCurrentConnectionStringAction.LABEL
);
let configurationRegistry = <IConfigurationRegistry>Registry.as(ConfigExtensions.Configuration);
configurationRegistry.registerConfiguration({
'id': 'connection',

View File

@@ -13,6 +13,11 @@ import { IConnectionManagementService } from 'sql/parts/connection/common/connec
import { INotificationService, INotificationActions } from 'vs/platform/notification/common/notification';
import Severity from 'vs/base/common/severity';
import { IDialogService, IConfirmation, IConfirmationResult } from 'vs/platform/dialogs/common/dialogs';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IObjectExplorerService } from '../../objectExplorer/common/objectExplorerService';
import { QueryInput } from 'sql/parts/query/common/queryInput';
import { EditDataInput } from 'sql/parts/editData/common/editDataInput';
import { DashboardInput } from 'sql/parts/dashboard/dashboardInput';
/**
* Workbench action to clear the recent connnections list
@@ -126,4 +131,44 @@ export class ClearSingleRecentConnectionAction extends Action {
this._onRecentConnectionRemoved.fire();
});
}
}
}
/**
* Action to retrieve the current connection string
*/
export class GetCurrentConnectionStringAction extends Action {
public static ID = 'getCurrentConnectionStringAction';
public static LABEL = nls.localize('connectionAction.GetCurrentConnectionString', "Get Current Connection String");
constructor(
id: string,
label: string,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IWorkbenchEditorService private _editorService: IWorkbenchEditorService,
@IObjectExplorerService private _objectExplorerService: IObjectExplorerService,
@INotificationService private readonly _notificationService: INotificationService
) {
super(GetCurrentConnectionStringAction.ID, GetCurrentConnectionStringAction.LABEL);
this.enabled = true;
}
public run(): TPromise<void> {
return new TPromise<void>((resolve, reject) => {
let activeInput = this._editorService.getActiveEditorInput();
if (activeInput && (activeInput instanceof QueryInput || activeInput instanceof EditDataInput || activeInput instanceof DashboardInput)
&& this._connectionManagementService.isConnected(activeInput.uri)) {
let includePassword = false;
this._connectionManagementService.getConnectionString(activeInput.uri, includePassword).then(result => {
let message = result
? result
: nls.localize('connectionAction.connectionString', "Connection string not available");
this._notificationService.info(message);
});
} else {
let message = nls.localize('connectionAction.noConnection', "No active connection available");
this._notificationService.info(message);
}
});
}
}

View File

@@ -260,6 +260,11 @@ export interface IConnectionManagementService {
* in the connection profile's options dictionary, or undefined if the profile is not connected
*/
getActiveConnectionCredentials(profileId: string): { [name: string]: string };
/**
* Get the connection string for the provided connection profile
*/
getConnectionString(ownerUri: string, includePassword: boolean): Thenable<string>;
}
export const IConnectionDialogService = createDecorator<IConnectionDialogService>('connectionDialogService');

View File

@@ -1345,4 +1345,24 @@ export class ConnectionManagementService extends Disposable implements IConnecti
credentials[passwordOption.name] = profile.options[passwordOption.name];
return credentials;
}
/**
* Get the connection string for the provided connection profile
*/
public getConnectionString(ownerUri: string, includePassword: boolean = false): Thenable<string> {
if (!ownerUri) {
return Promise.resolve(undefined);
}
let providerId = this.getProviderIdFromUri(ownerUri);
if (!providerId) {
return Promise.resolve(undefined);
}
return this._providers.get(providerId).onReady.then(provider => {
return provider.getConnectionString(ownerUri, includePassword).then(connectionString => {
return connectionString;
});
});
}
}

7
src/sql/sqlops.d.ts vendored
View File

@@ -87,6 +87,11 @@ declare module 'sqlops' {
*/
export function getActiveConnections(): Thenable<Connection[]>;
/**
* Get connection string
*/
export function getConnectionString(connectionId: string, includePassword: boolean): Thenable<string>;
/**
* Get the credentials for an active connection
* @param {string} connectionId The id of the connection
@@ -322,6 +327,8 @@ declare module 'sqlops' {
rebuildIntelliSenseCache(connectionUri: string): Thenable<void>;
getConnectionString(connectionUri: string, includePassword: boolean): Thenable<string> ;
registerOnConnectionComplete(handler: (connSummary: ConnectionInfoSummary) => any): void;
registerOnIntelliSenseCacheComplete(handler: (connectionUri: string) => any): void;

View File

@@ -35,6 +35,10 @@ export class ExtHostConnectionManagement extends ExtHostConnectionManagementShap
return this._proxy.$listDatabases(connectionId);
}
public $getConnectionString(connectionId: string, includePassword: boolean): Thenable<string> {
return this._proxy.$getConnectionString(connectionId, includePassword);
}
public $getUriForConnection(connectionId: string): Thenable<string> {
return this._proxy.$getUriForConnection(connectionId);
}

View File

@@ -181,6 +181,10 @@ export class ExtHostDataProtocol extends ExtHostDataProtocolShape {
return this._resolveProvider<sqlops.ConnectionProvider>(handle).listDatabases(connectionUri);
}
$getConnectionString(handle: number, connectionUri: string, includePassword: boolean): Thenable<string> {
return this._resolveProvider<sqlops.ConnectionProvider>(handle).getConnectionString(connectionUri, includePassword);
}
$rebuildIntelliSenseCache(handle: number, connectionUri: string): Thenable<void> {
return this._resolveProvider<sqlops.ConnectionProvider>(handle).rebuildIntelliSenseCache(connectionUri);
}

View File

@@ -56,6 +56,11 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag
return result.databaseNames;
}
public async $getConnectionString(connectionId: string, includePassword: boolean): Promise<string> {
let connection = this._connectionManagementService.getActiveConnections().find(profile => profile.id === connectionId);
return await this._connectionManagementService.getConnectionString(connectionId, includePassword);
}
public $getUriForConnection(connectionId: string): Thenable<string> {
return Promise.resolve(this._connectionManagementService.getConnectionUriFromId(connectionId));
}

View File

@@ -88,6 +88,9 @@ export class MainThreadDataProtocol implements MainThreadDataProtocolShape {
listDatabases(connectionUri: string): Thenable<sqlops.ListDatabasesResult> {
return self._proxy.$listDatabases(handle, connectionUri);
},
getConnectionString(connectionUri: string, includePassword: boolean): Thenable<string> {
return self._proxy.$getConnectionString(handle, connectionUri, includePassword);
},
rebuildIntelliSenseCache(connectionUri: string): Thenable<void> {
return self._proxy.$rebuildIntelliSenseCache(handle, connectionUri);
}

View File

@@ -105,6 +105,9 @@ export function createApiFactory(
listDatabases(connectionId: string): Thenable<string[]> {
return extHostConnectionManagement.$listDatabases(connectionId);
},
getConnectionString(connectionId: string, includePassword: boolean): Thenable<string> {
return extHostConnectionManagement.$getConnectionString(connectionId, includePassword);
},
getUriForConnection(connectionId: string): Thenable<string> {
return extHostConnectionManagement.$getUriForConnection(connectionId);
}

View File

@@ -63,6 +63,13 @@ export abstract class ExtHostDataProtocolShape {
*/
$listDatabases(handle: number, connectionUri: string): Thenable<sqlops.ListDatabasesResult> { throw ni(); }
/**
* Get the connection string for the connection specified by connectionUri
* @param handle the handle to use when looking up a provider
* @param connectionUri URI identifying a connected resource
*/
$getConnectionString(handle: number, connectionUri: string, includePassword: boolean): Thenable<string> { throw ni(); }
/**
* Notifies all listeners on the Extension Host side that a language change occurred
* for a dataprotocol language. The sub-flavor is the specific implementation used for query
@@ -474,6 +481,7 @@ export interface MainThreadConnectionManagementShape extends IDisposable {
$getCurrentConnection(): Thenable<sqlops.connection.Connection>;
$getCredentials(connectionId: string): Thenable<{ [name: string]: string }>;
$listDatabases(connectionId: string): Thenable<string[]>;
$getConnectionString(connectionId: string, includePassword: boolean): Thenable<string>;
$getUriForConnection(connectionId: string): Thenable<string>;
}