Mssql edition context (#1537)

* added sql server edition context

* formatting

* change context key to engine edition
This commit is contained in:
Anthony Dresser
2018-06-01 14:43:15 -07:00
committed by GitHub
parent 8a3509e006
commit 58036bb364
2 changed files with 41 additions and 4 deletions

View File

@@ -6,12 +6,15 @@
import * as vscode from 'vscode';
import * as sqlops from 'sqlops';
import * as types from './types';
export enum BuiltInCommands {
SetContext = 'setContext',
SetContext = 'setContext',
}
export enum ContextKeys {
ISCLOUD = 'mssql:iscloud'
ISCLOUD = 'mssql:iscloud',
EDITIONID = 'mssql:engineedition'
}
const isCloudEditions = [
@@ -20,7 +23,7 @@ const isCloudEditions = [
];
export function setCommandContext(key: ContextKeys | string, value: any) {
return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value);
return vscode.commands.executeCommand(BuiltInCommands.SetContext, key, value);
}
export default class ContextProvider {
@@ -33,17 +36,24 @@ export default class ContextProvider {
public onDashboardOpen(e: sqlops.DashboardDocument): void {
let iscloud: boolean;
if (e.profile.providerName.toLowerCase() === 'mssql' && e.serverInfo.engineEditionId) {
let edition: number;
if (e.profile.providerName.toLowerCase() === 'mssql' && !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 {

View File

@@ -0,0 +1,27 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
const _typeof = {
number: 'number',
string: 'string',
undefined: 'undefined',
object: 'object',
function: 'function'
};
/**
* @returns whether the provided parameter is undefined or null.
*/
export function isUndefinedOrNull(obj: any): boolean {
return isUndefined(obj) || obj === null;
}
/**
* @returns whether the provided parameter is undefined.
*/
export function isUndefined(obj: any): boolean {
return typeof (obj) === _typeof.undefined;
}