diff --git a/extensions/profiler/client/src/dialogs/profilerCreateSessionDialog.ts b/extensions/profiler/client/src/dialogs/profilerCreateSessionDialog.ts index 4906a48b21..3d92a0fcfc 100644 --- a/extensions/profiler/client/src/dialogs/profilerCreateSessionDialog.ts +++ b/extensions/profiler/client/src/dialogs/profilerCreateSessionDialog.ts @@ -12,6 +12,7 @@ import { CreateSessionData } from '../data/createSessionData'; const localize = nls.loadMessageBundle(); export class CreateSessionDialog { + private readonly _providerType: string; // Top level private readonly DialogTitle: string = localize('createSessionDialog.newSession', 'New Session'); @@ -30,13 +31,17 @@ export class CreateSessionDialog { public readonly onSuccess: vscode.Event = this._onSuccess.event; - constructor(ownerUri: string, templates: Array) { + constructor(ownerUri: string, providerType: string, templates: Array) { if (typeof (templates) === 'undefined' || templates === null) { throw new Error(localize('createSessionDialog.templatesInvalid', "Invalid templates list, cannot open dialog")); } if (typeof (ownerUri) === 'undefined' || ownerUri === null) { throw new Error(localize('createSessionDialog.dialogOwnerInvalid', "Invalid dialog owner, cannot open dialog")); } + if (typeof (providerType) === 'undefined' || providerType === null) { + throw new Error(localize('createSessionDialog.invalidProviderType', "Invalid provider type, cannot open dialog")); + } + this._providerType = providerType; this.model = new CreateSessionData(ownerUri, templates); } @@ -97,8 +102,7 @@ export class CreateSessionDialog { } private async execute(): Promise { - let currentConnection = await sqlops.connection.getCurrentConnection(); - let profilerService = sqlops.dataprotocol.getProvider(currentConnection.providerName, sqlops.DataProviderType.ProfilerProvider); + let profilerService = sqlops.dataprotocol.getProvider(this._providerType, sqlops.DataProviderType.ProfilerProvider); let name = this.sessionNameBox.value; let selected = this.templatesBox.value.toString(); diff --git a/extensions/profiler/client/src/mainController.ts b/extensions/profiler/client/src/mainController.ts index 8b95404b9a..b4e57b8376 100644 --- a/extensions/profiler/client/src/mainController.ts +++ b/extensions/profiler/client/src/mainController.ts @@ -29,8 +29,8 @@ export class MainController { } public activate(): void { - vscode.commands.registerCommand('profiler.openCreateSessionDialog', (ownerUri: string, templates: Array) => { - let dialog = new CreateSessionDialog(ownerUri, templates); + vscode.commands.registerCommand('profiler.openCreateSessionDialog', (ownerUri: string, providerType: string, templates: Array) => { + let dialog = new CreateSessionDialog(ownerUri, providerType, templates); dialog.showDialog(); }); } diff --git a/extensions/profiler/package.json b/extensions/profiler/package.json index f2cdd86357..2f2b2bf87e 100644 --- a/extensions/profiler/package.json +++ b/extensions/profiler/package.json @@ -26,7 +26,6 @@ "Microsoft.mssql" ], "contributes": { - "commands": [ { "command": "profiler.newProfiler", @@ -49,6 +48,15 @@ "category": "Profiler" } ], + "menus": { + "objectExplorer/item/context": [ + { + "command": "profiler.newProfiler", + "when": "connectionProvider == MSSQL && nodeType && nodeType == Server", + "group": "profiler" + } + ] + }, "outputChannels": [ "sqlprofiler" ] @@ -59,4 +67,4 @@ "devDependencies": { "vscode": "1.0.1" } -} +} \ No newline at end of file diff --git a/src/sql/parts/objectExplorer/viewlet/serverTreeActionProvider.ts b/src/sql/parts/objectExplorer/viewlet/serverTreeActionProvider.ts index 258a4b0aa5..cceb97003f 100644 --- a/src/sql/parts/objectExplorer/viewlet/serverTreeActionProvider.ts +++ b/src/sql/parts/objectExplorer/viewlet/serverTreeActionProvider.ts @@ -90,9 +90,11 @@ export class ServerTreeActionProvider extends ContributableActionProvider { * Return actions for connection elements */ public getConnectionActions(tree: ITree, profile: ConnectionProfile): IAction[] { + let node = new TreeNode(NodeType.Server, '', false, '', '', '', undefined, undefined, undefined, undefined); return this.getAllActions({ tree: tree, - profile: profile + profile: profile, + treeNode: node }, (context) => this.getBuiltinConnectionActions(context)); } @@ -125,10 +127,6 @@ export class ServerTreeActionProvider extends ContributableActionProvider { actions.push(this._instantiationService.createInstance(DeleteConnectionAction, DeleteConnectionAction.ID, DeleteConnectionAction.DELETE_CONNECTION_LABEL, context.profile)); actions.push(this._instantiationService.createInstance(RefreshAction, RefreshAction.ID, RefreshAction.LABEL, context.tree, context.profile)); - if (process.env['VSCODE_DEV'] && constants.MssqlProviderId === context.profile.providerName) { - actions.push(this._instantiationService.createInstance(OEAction, NewProfilerAction.ID, NewProfilerAction.LABEL)); - } - return actions; } diff --git a/src/sql/parts/profiler/contrib/profilerActions.contribution.ts b/src/sql/parts/profiler/contrib/profilerActions.contribution.ts index 8b0ba03c17..a9c33b59c6 100644 --- a/src/sql/parts/profiler/contrib/profilerActions.contribution.ts +++ b/src/sql/parts/profiler/contrib/profilerActions.contribution.ts @@ -9,7 +9,7 @@ import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiati import * as nls from 'vs/nls'; import { IJSONSchema } from 'vs/base/common/jsonSchema'; import { IEditorService, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService'; -import { IConnectionManagementService } from 'sql/parts/connection/common/connectionManagement'; +import { IConnectionManagementService, IConnectionDialogService} from 'sql/parts/connection/common/connectionManagement'; import { IObjectExplorerService } from '../../objectExplorer/common/objectExplorerService'; import { ProfilerInput } from 'sql/parts/profiler/editor/profilerInput'; import { TPromise } from 'vs/base/common/winjs.base'; @@ -18,6 +18,10 @@ import { IProfilerService } from '../service/interfaces'; import { KeybindingsRegistry, KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry'; import { KeyCode, KeyMod } from 'vs/editor/editor.api'; import { ProfilerEditor } from '../editor/profilerEditor'; +import { ObjectExplorerActionsContext } from 'sql/parts/objectExplorer/viewlet/objectExplorerActions'; +import { ConnectionProfile } from 'sql/parts/connection/common/connectionProfile'; +import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService'; +import { mssqlProviderName } from 'sql/parts/connection/common/constants'; // Contribute Global Actions const category = nls.localize('profilerCategory', "Profiler"); @@ -30,15 +34,45 @@ const newProfilerSchema: IJSONSchema = { CommandsRegistry.registerCommand({ id: 'profiler.newProfiler', - handler: (accessor: ServicesAccessor) => { - let editorService: IEditorService = accessor.get(IEditorService); + handler: (accessor: ServicesAccessor, ...args: any[]) => { + let connectionProfile: ConnectionProfile = undefined; let instantiationService: IInstantiationService = accessor.get(IInstantiationService); + let editorService: IEditorService = accessor.get(IEditorService); let connectionService: IConnectionManagementService = accessor.get(IConnectionManagementService); let objectExplorerService: IObjectExplorerService = accessor.get(IObjectExplorerService); + let connectionDialogService: IConnectionDialogService = accessor.get(IConnectionDialogService); + let capabilitiesService: ICapabilitiesService = accessor.get(ICapabilitiesService); - let connectionProfile = TaskUtilities.getCurrentGlobalConnection(objectExplorerService, connectionService, editorService); - let profilerInput = instantiationService.createInstance(ProfilerInput, connectionProfile); - return editorService.openEditor(profilerInput, { pinned: true }, ACTIVE_GROUP).then(() => TPromise.as(true)); + // If a context is available if invoked from the context menu, we will use the connection profiler of the server node + if (args && args.length === 1 && args[0] && args[0] instanceof ObjectExplorerActionsContext) { + let context = args[0] as ObjectExplorerActionsContext; + connectionProfile = ConnectionProfile.fromIConnectionProfile(capabilitiesService, context.connectionProfile); + } + else { + // No context available, we will try to get the current global active connection + connectionProfile = TaskUtilities.getCurrentGlobalConnection(objectExplorerService, connectionService, editorService) as ConnectionProfile; + } + + let promise; + if (connectionProfile) { + promise = connectionService.connectIfNotConnected(connectionProfile); + } else { + // if still no luck, we will open the Connection dialog and let user connect to a server + promise = connectionDialogService.openDialogAndWait(connectionService, { connectionType: 1, providers: [mssqlProviderName] }).then((profile) => { + connectionProfile = profile as ConnectionProfile; + }); + } + + return promise.then(() => { + if (!connectionProfile) { + connectionProfile = TaskUtilities.getCurrentGlobalConnection(objectExplorerService, connectionService, editorService) as ConnectionProfile; + } + + if (connectionProfile && connectionProfile.providerName === mssqlProviderName) { + let profilerInput = instantiationService.createInstance(ProfilerInput, connectionProfile); + editorService.openEditor(profilerInput, { pinned: true }, ACTIVE_GROUP).then(() => TPromise.as(true)); + } + }); } }); diff --git a/src/sql/parts/profiler/editor/profilerInput.ts b/src/sql/parts/profiler/editor/profilerInput.ts index 08f8002971..29b1884167 100644 --- a/src/sql/parts/profiler/editor/profilerInput.ts +++ b/src/sql/parts/profiler/editor/profilerInput.ts @@ -91,6 +91,10 @@ export class ProfilerInput extends EditorInput implements IProfilerSession { }); } + public get providerType(): string { + return this._connection ? this._connection.providerName : undefined; + } + public set viewTemplate(template: IProfilerViewTemplate) { this._data.clear(); this._viewTemplate = template; diff --git a/src/sql/parts/profiler/service/profilerService.ts b/src/sql/parts/profiler/service/profilerService.ts index 6fd36b7ae8..e43938aa5e 100644 --- a/src/sql/parts/profiler/service/profilerService.ts +++ b/src/sql/parts/profiler/service/profilerService.ts @@ -228,6 +228,6 @@ export class ProfilerService implements IProfilerService { } public launchCreateSessionDialog(input?: ProfilerInput): Thenable { - return this._commandService.executeCommand('profiler.openCreateSessionDialog', input.id, this.getSessionTemplates()); + return this._commandService.executeCommand('profiler.openCreateSessionDialog', input.id, input.providerType, this.getSessionTemplates()); } }