minor code refactoring (#18227)

This commit is contained in:
Alan Ren
2022-02-04 21:31:15 -08:00
committed by GitHub
parent b7fe4c09e2
commit 33d9e05e00
2 changed files with 12 additions and 11 deletions

View File

@@ -6,16 +6,14 @@
import { AppContext } from '../appContext';
import * as azdata from 'azdata';
import * as vscode from 'vscode';
import { sqlProviderName } from '../constants';
import { sqlProviderName, TableType } from '../constants';
import { generateUuid } from 'vscode-languageclient/lib/utils/uuid';
import { ITelemetryEventProperties, Telemetry } from '../telemetry';
export function registerTableDesignerCommands(appContext: AppContext) {
appContext.extensionContext.subscriptions.push(vscode.commands.registerCommand('mssql.newTable', async (context: azdata.ObjectExplorerContext) => {
const connectionString = await azdata.connection.getConnectionString(context.connectionProfile.id, true);
const serverInfo = await azdata.connection.getServerInfo(context.connectionProfile.id);
let telemetryInfo: ITelemetryEventProperties = {};
telemetryInfo = Telemetry.fillServerInfo(telemetryInfo, serverInfo);
const telemetryInfo = await getTelemetryInfo(context, TableType.Basic);
await azdata.designers.openTableDesigner(sqlProviderName, {
server: context.connectionProfile.serverName,
database: context.connectionProfile.databaseName,
@@ -31,9 +29,7 @@ export function registerTableDesignerCommands(appContext: AppContext) {
const schema = context.nodeInfo.metadata.schema;
const name = context.nodeInfo.metadata.name;
const connectionString = await azdata.connection.getConnectionString(context.connectionProfile.id, true);
const serverInfo = await azdata.connection.getServerInfo(context.connectionProfile.id);
let telemetryInfo: ITelemetryEventProperties = {};
telemetryInfo = Telemetry.fillServerInfo(telemetryInfo, serverInfo);
const telemetryInfo = await getTelemetryInfo(context, TableType.Basic);
await azdata.designers.openTableDesigner(sqlProviderName, {
server: server,
database: database,
@@ -45,3 +41,11 @@ export function registerTableDesignerCommands(appContext: AppContext) {
}, telemetryInfo);
}));
}
async function getTelemetryInfo(context: azdata.ObjectExplorerContext, tableType: string): Promise<ITelemetryEventProperties> {
const serverInfo = await azdata.connection.getServerInfo(context.connectionProfile.id);
const telemetryInfo: ITelemetryEventProperties = {};
Telemetry.fillServerInfo(telemetryInfo, serverInfo);
telemetryInfo['tableType'] = tableType;
return telemetryInfo;
}

View File

@@ -114,21 +114,18 @@ export class Telemetry {
// If sending telemetry event fails ignore it so it won't break the extension
console.error('Failed to send telemetry event. error: ' + telemetryErr);
}
}
/**
* Collects server information from ServerInfo to put into a
* property bag
*/
public static fillServerInfo(telemetryInfo: { [key: string]: string }, serverInfo: ServerInfo): { [key: string]: string } {
public static fillServerInfo(telemetryInfo: { [key: string]: string }, serverInfo: ServerInfo): void {
telemetryInfo['serverEdition'] = serverInfo?.serverEdition;
telemetryInfo['serverLevel'] = serverInfo?.serverLevel;
telemetryInfo['serverMajorVersion'] = serverInfo?.serverMajorVersion.toString();
telemetryInfo['serverMinorVersion'] = serverInfo?.serverMinorVersion.toString();
telemetryInfo['isCloud'] = serverInfo?.isCloud.toString();
telemetryInfo['tableType'] = Constants.TableType.Basic;
return telemetryInfo;
}
}