From ba91140ea5ab1f9c143e180e4b43c559a0b24c7f Mon Sep 17 00:00:00 2001 From: Vincent Feng Date: Sat, 8 Sep 2018 01:08:18 +0800 Subject: [PATCH] Enable the support for post-connection behaviors for openConnectionDialog (#2455) * Enable the support for post-connection behaviors for openConnectionDialog. * Fixed bugs. * Make everything in IConnectionCompletionOptions optional except saveConnection. * showConnectionDialogOnError & showFirewallRuleOnError default to true. * Use types.isUndefinedOrNull to do value checking. * Minor changes. --- src/sql/sqlops.d.ts | 32 +++++++++++++++++++ src/sql/sqlops.proposed.d.ts | 2 +- .../api/node/extHostConnectionManagement.ts | 4 +-- .../node/mainThreadConnectionManagement.ts | 19 +++++++++-- .../workbench/api/node/sqlExtHost.api.impl.ts | 4 +-- .../workbench/api/node/sqlExtHost.protocol.ts | 2 +- 6 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/sql/sqlops.d.ts b/src/sql/sqlops.d.ts index e6c421b5b5..ee43c51c23 100644 --- a/src/sql/sqlops.d.ts +++ b/src/sql/sqlops.d.ts @@ -209,6 +209,38 @@ declare module 'sqlops' { id: string; } + /** + * Options for the actions that could happen after connecting is complete + */ + export interface IConnectionCompletionOptions { + /** + * Save the connection to MRU and settings (only save to setting if profile.saveProfile is set to true) + * Default is true. + */ + saveConnection: boolean; + + /** + * If true, open the dashboard after connection is complete. + * If undefined / false, dashboard won't be opened after connection completes. + * Default is false. + */ + showDashboard?: boolean; + + /** + * If undefined / true, open the connection dialog if connection fails. + * If false, connection dialog won't be opened even if connection fails. + * Default is true. + */ + showConnectionDialogOnError?: boolean; + + /** + * If undefined / true, open the connection firewall rule dialog if connection fails. + * If false, connection firewall rule dialog won't be opened even if connection fails. + * Default is true. + */ + showFirewallRuleOnError?: boolean; + } + export interface ConnectionInfoSummary { /** diff --git a/src/sql/sqlops.proposed.d.ts b/src/sql/sqlops.proposed.d.ts index e82c64408d..da2798ac99 100644 --- a/src/sql/sqlops.proposed.d.ts +++ b/src/sql/sqlops.proposed.d.ts @@ -1259,6 +1259,6 @@ declare module 'sqlops' { * returns the connection otherwise returns undefined * @param callback */ - export function openConnectionDialog(provider?: string[], initialConnectionProfile?: IConnectionProfile): Thenable; + export function openConnectionDialog(providers?: string[], initialConnectionProfile?: IConnectionProfile, connectionCompletionOptions?: IConnectionCompletionOptions): Thenable; } } diff --git a/src/sql/workbench/api/node/extHostConnectionManagement.ts b/src/sql/workbench/api/node/extHostConnectionManagement.ts index 6d73064365..35ff4c194c 100644 --- a/src/sql/workbench/api/node/extHostConnectionManagement.ts +++ b/src/sql/workbench/api/node/extHostConnectionManagement.ts @@ -32,8 +32,8 @@ export class ExtHostConnectionManagement extends ExtHostConnectionManagementShap return this._proxy.$getCredentials(connectionId); } - public $openConnectionDialog(providers?: string[], initialConnectionProfile?: sqlops.IConnectionProfile): Thenable { - return this._proxy.$openConnectionDialog(providers, initialConnectionProfile); + public $openConnectionDialog(providers?: string[], initialConnectionProfile?: sqlops.IConnectionProfile, connectionCompletionOptions?: sqlops.IConnectionCompletionOptions): Thenable { + return this._proxy.$openConnectionDialog(providers, initialConnectionProfile, connectionCompletionOptions); } public $listDatabases(connectionId: string): Thenable { diff --git a/src/sql/workbench/api/node/mainThreadConnectionManagement.ts b/src/sql/workbench/api/node/mainThreadConnectionManagement.ts index 9f20ae36c5..c08970a45c 100644 --- a/src/sql/workbench/api/node/mainThreadConnectionManagement.ts +++ b/src/sql/workbench/api/node/mainThreadConnectionManagement.ts @@ -14,6 +14,7 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic import * as TaskUtilities from 'sql/workbench/common/taskUtilities'; import { IConnectionProfile } from 'sql/parts/connection/common/interfaces'; import { dispose, IDisposable } from 'vs/base/common/lifecycle'; +import { isUndefinedOrNull } from 'vs/base/common/types'; @extHostNamedCustomer(SqlMainContext.MainThreadConnectionManagement) export class MainThreadConnectionManagement implements MainThreadConnectionManagementShape { @@ -51,13 +52,27 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag } - public async $openConnectionDialog(providers: string[], initialConnectionProfile?: IConnectionProfile): Promise { + public async $openConnectionDialog(providers: string[], initialConnectionProfile?: IConnectionProfile, connectionCompletionOptions?: sqlops.IConnectionCompletionOptions): Promise { let connectionProfile = await this._connectionDialogService.openDialogAndWait(this._connectionManagementService, { connectionType: 1, providers: providers }, initialConnectionProfile); - return connectionProfile ? { + const connection = connectionProfile ? { connectionId: connectionProfile.id, options: connectionProfile.options, providerName: connectionProfile.providerName } : undefined; + + if (connectionCompletionOptions) { + // Somehow, connectionProfile.saveProfile is false even if initialConnectionProfile.saveProfile is true, reset the flag here. + connectionProfile.saveProfile = initialConnectionProfile.saveProfile; + await this._connectionManagementService.connectAndSaveProfile(connectionProfile, undefined, { + saveTheConnection: isUndefinedOrNull(connectionCompletionOptions.saveConnection) ? true : connectionCompletionOptions.saveConnection, + showDashboard: isUndefinedOrNull(connectionCompletionOptions.showDashboard) ? false : connectionCompletionOptions.showDashboard, + params: undefined, + showConnectionDialogOnError: isUndefinedOrNull(connectionCompletionOptions.showConnectionDialogOnError) ? true : connectionCompletionOptions.showConnectionDialogOnError, + showFirewallRuleOnError: isUndefinedOrNull(connectionCompletionOptions.showFirewallRuleOnError) ? true : connectionCompletionOptions.showFirewallRuleOnError + }); + } + + return connection; } public async $listDatabases(connectionId: string): Promise { diff --git a/src/sql/workbench/api/node/sqlExtHost.api.impl.ts b/src/sql/workbench/api/node/sqlExtHost.api.impl.ts index 0c012b1853..efdd7e06a0 100644 --- a/src/sql/workbench/api/node/sqlExtHost.api.impl.ts +++ b/src/sql/workbench/api/node/sqlExtHost.api.impl.ts @@ -114,8 +114,8 @@ export function createApiFactory( getCredentials(connectionId: string): Thenable<{ [name: string]: string }> { return extHostConnectionManagement.$getCredentials(connectionId); }, - openConnectionDialog(providers?: string[], initialConnectionProfile?: sqlops.IConnectionProfile): Thenable { - return extHostConnectionManagement.$openConnectionDialog(providers, initialConnectionProfile); + openConnectionDialog(providers?: string[], initialConnectionProfile?: sqlops.IConnectionProfile, connectionCompletionOptions?: sqlops.IConnectionCompletionOptions): Thenable { + return extHostConnectionManagement.$openConnectionDialog(providers, initialConnectionProfile, connectionCompletionOptions); }, listDatabases(connectionId: string): Thenable { return extHostConnectionManagement.$listDatabases(connectionId); diff --git a/src/sql/workbench/api/node/sqlExtHost.protocol.ts b/src/sql/workbench/api/node/sqlExtHost.protocol.ts index 7c09025549..1ac756f739 100644 --- a/src/sql/workbench/api/node/sqlExtHost.protocol.ts +++ b/src/sql/workbench/api/node/sqlExtHost.protocol.ts @@ -503,7 +503,7 @@ export interface MainThreadConnectionManagementShape extends IDisposable { $getActiveConnections(): Thenable; $getCurrentConnection(): Thenable; $getCredentials(connectionId: string): Thenable<{ [name: string]: string }>; - $openConnectionDialog(providers: string[], initialConnectionProfile?: sqlops.IConnectionProfile): Thenable; + $openConnectionDialog(providers: string[], initialConnectionProfile?: sqlops.IConnectionProfile, connectionCompletionOptions?: sqlops.IConnectionCompletionOptions): Thenable; $listDatabases(connectionId: string): Thenable; $getConnectionString(connectionId: string, includePassword: boolean): Thenable; $getUriForConnection(connectionId: string): Thenable;