mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-15 02:48:30 -05:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
89
extensions-modules/src/configurations/config.ts
Normal file
89
extensions-modules/src/configurations/config.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 fs = require('fs');
|
||||
import * as path from 'path';
|
||||
import {IConfig} from '../languageservice/interfaces';
|
||||
import * as SharedConstants from '../models/constants';
|
||||
|
||||
/*
|
||||
* Config class handles getting values from config.json.
|
||||
*/
|
||||
export default class Config implements IConfig {
|
||||
private _configJsonContent: any = undefined;
|
||||
|
||||
private _extensionConfigSectionName: string = undefined;
|
||||
private _fromBuild: boolean = undefined;
|
||||
|
||||
constructor(extensionConfigSectionName: string, fromBuild?: boolean) {
|
||||
this._extensionConfigSectionName = extensionConfigSectionName;
|
||||
this._fromBuild = fromBuild;
|
||||
}
|
||||
|
||||
public get configJsonContent(): any {
|
||||
if (this._configJsonContent === undefined) {
|
||||
this._configJsonContent = this.loadConfig();
|
||||
}
|
||||
return this._configJsonContent;
|
||||
}
|
||||
|
||||
public getDownloadUrl(): string {
|
||||
return this.getConfigValue(SharedConstants.downloadUrlConfigKey);
|
||||
}
|
||||
|
||||
public getInstallDirectory(): string {
|
||||
return this.getConfigValue(SharedConstants.installDirConfigKey);
|
||||
}
|
||||
|
||||
public getExecutableFiles(): string[] {
|
||||
return this.getConfigValue(SharedConstants.executableFilesConfigKey);
|
||||
}
|
||||
|
||||
public getPackageVersion(): string {
|
||||
return this.getConfigValue(SharedConstants.versionConfigKey);
|
||||
}
|
||||
|
||||
public getConfigValue(configKey: string): any {
|
||||
let json = this.configJsonContent;
|
||||
let toolsConfig = json[SharedConstants.serviceConfigKey];
|
||||
let configValue: string = undefined;
|
||||
if (toolsConfig !== undefined) {
|
||||
configValue = toolsConfig[configKey];
|
||||
}
|
||||
return configValue;
|
||||
}
|
||||
|
||||
public getExtensionConfig(key: string, defaultValue?: any): any {
|
||||
let json = this.configJsonContent;
|
||||
let extensionConfig = json[this._extensionConfigSectionName];
|
||||
let configValue = extensionConfig[key];
|
||||
if (!configValue) {
|
||||
configValue = defaultValue;
|
||||
}
|
||||
return configValue;
|
||||
}
|
||||
|
||||
public getWorkspaceConfig(key: string, defaultValue?: any): any {
|
||||
let json = this.configJsonContent;
|
||||
let configValue = json[key];
|
||||
if (!configValue) {
|
||||
configValue = defaultValue;
|
||||
}
|
||||
return configValue;
|
||||
}
|
||||
|
||||
public loadConfig(): any {
|
||||
let configContent = undefined;
|
||||
if (this._fromBuild) {
|
||||
let remainingPath = '../../../../../extensions/' + this._extensionConfigSectionName + '/client/out/config.json';
|
||||
configContent = fs.readFileSync(path.join(__dirname, remainingPath));
|
||||
}
|
||||
else {
|
||||
configContent = fs.readFileSync(path.join(__dirname, '../../../../client/out/config.json'));
|
||||
}
|
||||
return JSON.parse(configContent);
|
||||
}
|
||||
}
|
||||
75
extensions-modules/src/configurations/extConfig.ts
Normal file
75
extensions-modules/src/configurations/extConfig.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 Config from './config';
|
||||
import { workspace, WorkspaceConfiguration } from 'vscode';
|
||||
import {IConfig} from '../languageservice/interfaces';
|
||||
import * as Constants from '../models/constants';
|
||||
|
||||
/*
|
||||
* ExtConfig class handles getting values from workspace config or config.json.
|
||||
*/
|
||||
export default class ExtConfig implements IConfig {
|
||||
|
||||
constructor(private _extensionConfigSectionName: string, private _config?: IConfig,
|
||||
private _extensionConfig?: WorkspaceConfiguration,
|
||||
private _workspaceConfig?: WorkspaceConfiguration) {
|
||||
if (this._config === undefined) {
|
||||
this._config = new Config(_extensionConfigSectionName);
|
||||
}
|
||||
if (this._extensionConfig === undefined) {
|
||||
this._extensionConfig = workspace.getConfiguration(_extensionConfigSectionName);
|
||||
}
|
||||
if (this._workspaceConfig === undefined) {
|
||||
this._workspaceConfig = workspace.getConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
public getDownloadUrl(): string {
|
||||
return this.getConfigValue(Constants.downloadUrlConfigKey);
|
||||
}
|
||||
|
||||
public getInstallDirectory(): string {
|
||||
return this.getConfigValue(Constants.installDirConfigKey);
|
||||
}
|
||||
|
||||
public getExecutableFiles(): string[] {
|
||||
return this.getConfigValue(Constants.executableFilesConfigKey);
|
||||
}
|
||||
|
||||
public getPackageVersion(): string {
|
||||
return this.getConfigValue(Constants.versionConfigKey);
|
||||
}
|
||||
|
||||
public getConfigValue(configKey: string): any {
|
||||
let configValue: string = <string>this.getExtensionConfig(`${Constants.serviceConfigKey}.${configKey}`);
|
||||
if (!configValue) {
|
||||
configValue = this._config.getConfigValue(configKey);
|
||||
}
|
||||
return configValue;
|
||||
}
|
||||
|
||||
public getExtensionConfig(key: string, defaultValue?: any): any {
|
||||
let configValue = this._extensionConfig.get(key);
|
||||
if (configValue === undefined) {
|
||||
configValue = defaultValue;
|
||||
}
|
||||
return configValue;
|
||||
}
|
||||
|
||||
public getWorkspaceConfig(key: string, defaultValue?: any): any {
|
||||
let configValue = this._workspaceConfig.get(key);
|
||||
if (configValue === undefined) {
|
||||
configValue = defaultValue;
|
||||
}
|
||||
return configValue;
|
||||
}
|
||||
|
||||
public updateWorkspaceConfig(configKey: string, configValue: any) {
|
||||
this._workspaceConfig.update(configKey, configValue, true);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user