Files
azuredatastudio/extensions/mssql/src/contextProvider.ts
Kevin Cunnane 472233d9a7 Providers without metadata service or serverInfo shouldn't break dashboard (#1761)
- Fix a number of issues that arose while testing a provider without a metadata service or serverInfo object returned via DMP calls. These should be optional services/features and we should be resilient to them not existing. In most places we already have these checks
- This does not cover a number of "improvement" scenarios, such as filtering extension tabs by provider, and defaulting any tabs that don't specify a provider to be MSSQL. This and some other features to ensure things make sense will be implemented in separate PRs but this unblocked the scenario
2018-06-27 13:40:37 -07:00

63 lines
1.8 KiB
TypeScript

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as vscode from 'vscode';
import * as sqlops from 'sqlops';
import * as types from './types';
export enum BuiltInCommands {
SetContext = 'setContext',
}
export enum ContextKeys {
ISCLOUD = 'mssql:iscloud',
EDITIONID = 'mssql:engineedition'
}
const isCloudEditions = [
5,
6
];
export function setCommandContext(key: ContextKeys | string, value: any) {
return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value);
}
export default class ContextProvider {
private _disposables = new Array<vscode.Disposable>();
constructor() {
this._disposables.push(sqlops.workspace.onDidOpenDashboard(this.onDashboardOpen, this));
this._disposables.push(sqlops.workspace.onDidChangeToDashboard(this.onDashboardOpen, this));
}
public onDashboardOpen(e: sqlops.DashboardDocument): void {
let iscloud: boolean;
let edition: number;
if (e.profile.providerName.toLowerCase() === 'mssql' && !types.isUndefinedOrNull(e.serverInfo) && !types.isUndefinedOrNull(e.serverInfo.engineEditionId)) {
if (isCloudEditions.some(i => i === e.serverInfo.engineEditionId)) {
iscloud = true;
} else {
iscloud = false;
}
edition = e.serverInfo.engineEditionId;
}
if (iscloud === true || iscloud === false) {
setCommandContext(ContextKeys.ISCLOUD, iscloud);
}
if (!types.isUndefinedOrNull(edition)) {
setCommandContext(ContextKeys.EDITIONID, edition);
}
}
dispose(): void {
this._disposables = this._disposables.map(i => i.dispose());
}
}