mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-02 01:25:39 -05:00
move code from parts to contrib (#8319)
This commit is contained in:
27
src/sql/workbench/contrib/connection/common/connection.ts
Normal file
27
src/sql/workbench/contrib/connection/common/connection.ts
Normal 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.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
// ------------------------------- < Cancel Connect Request > ---------------------------------------
|
||||
|
||||
/**
|
||||
* Cancel connect request message format
|
||||
*/
|
||||
export class CancelConnectParams {
|
||||
/**
|
||||
* URI identifying the owner of the connection
|
||||
*/
|
||||
public ownerUri: string;
|
||||
}
|
||||
|
||||
// ------------------------------- </ Cancel Connect Request > --------------------------------------
|
||||
|
||||
// ------------------------------- < Disconnect Request > -------------------------------------------
|
||||
|
||||
// Disconnect request message format
|
||||
export class DisconnectParams {
|
||||
// URI identifying the owner of the connection
|
||||
public ownerUri: string;
|
||||
}
|
||||
|
||||
// ------------------------------- </ Disconnect Request > ------------------------------------------
|
||||
@@ -0,0 +1,55 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { IConnectionProfile } from 'azdata';
|
||||
import { IQueryManagementService } from 'sql/platform/query/common/queryManagement';
|
||||
|
||||
export class ConnectionContextKey implements IContextKey<IConnectionProfile> {
|
||||
|
||||
static Provider = new RawContextKey<string>('connectionProvider', undefined);
|
||||
static Server = new RawContextKey<string>('serverName', undefined);
|
||||
static Database = new RawContextKey<string>('databaseName', undefined);
|
||||
static Connection = new RawContextKey<IConnectionProfile>('connection', undefined);
|
||||
static IsQueryProvider = new RawContextKey<boolean>('isQueryProvider', false);
|
||||
|
||||
private _providerKey: IContextKey<string>;
|
||||
private _serverKey: IContextKey<string>;
|
||||
private _databaseKey: IContextKey<string>;
|
||||
private _connectionKey: IContextKey<IConnectionProfile>;
|
||||
private _isQueryProviderKey: IContextKey<boolean>;
|
||||
|
||||
constructor(
|
||||
@IContextKeyService contextKeyService: IContextKeyService,
|
||||
@IQueryManagementService private queryManagementService: IQueryManagementService
|
||||
) {
|
||||
this._providerKey = ConnectionContextKey.Provider.bindTo(contextKeyService);
|
||||
this._serverKey = ConnectionContextKey.Server.bindTo(contextKeyService);
|
||||
this._databaseKey = ConnectionContextKey.Database.bindTo(contextKeyService);
|
||||
this._connectionKey = ConnectionContextKey.Connection.bindTo(contextKeyService);
|
||||
this._isQueryProviderKey = ConnectionContextKey.IsQueryProvider.bindTo(contextKeyService);
|
||||
}
|
||||
|
||||
set(value: IConnectionProfile) {
|
||||
let queryProviders = this.queryManagementService.getRegisteredProviders();
|
||||
this._connectionKey.set(value);
|
||||
this._providerKey.set(value && value.providerName);
|
||||
this._serverKey.set(value && value.serverName);
|
||||
this._databaseKey.set(value && value.databaseName);
|
||||
this._isQueryProviderKey.set(value && value.providerName && queryProviders.indexOf(value.providerName) !== -1);
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this._providerKey.reset();
|
||||
this._serverKey.reset();
|
||||
this._databaseKey.reset();
|
||||
this._connectionKey.reset();
|
||||
this._isQueryProviderKey.reset();
|
||||
}
|
||||
|
||||
public get(): IConnectionProfile {
|
||||
return this._connectionKey.get();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import { ConnectionSummary } from 'azdata';
|
||||
import * as LocalizedConstants from 'sql/workbench/contrib/connection/common/localizedConstants';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
|
||||
// Status when making connections from the viewlet
|
||||
export class ConnectionGlobalStatus {
|
||||
|
||||
private _displayTime: number = 5000; // (in ms)
|
||||
|
||||
constructor(
|
||||
@INotificationService private _notificationService: INotificationService
|
||||
) {
|
||||
}
|
||||
|
||||
public setStatusToConnected(connectionSummary: ConnectionSummary): void {
|
||||
if (this._notificationService) {
|
||||
let text: string;
|
||||
let connInfo: string = connectionSummary.serverName;
|
||||
if (connInfo) {
|
||||
if (connectionSummary.databaseName && connectionSummary.databaseName !== '') {
|
||||
connInfo = connInfo + ' : ' + connectionSummary.databaseName;
|
||||
} else {
|
||||
connInfo = connInfo + ' : ' + '<default>';
|
||||
}
|
||||
text = LocalizedConstants.onDidConnectMessage + ' ' + connInfo;
|
||||
}
|
||||
this._notificationService.status(text, { hideAfter: this._displayTime });
|
||||
}
|
||||
}
|
||||
|
||||
public setStatusToDisconnected(fileUri: string): void {
|
||||
if (this._notificationService) {
|
||||
this._notificationService.status(LocalizedConstants.onDidDisconnectMessage, { hideAfter: this._displayTime });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IExtensionPointUser, ExtensionsRegistry } from 'vs/workbench/services/extensions/common/extensionsRegistry';
|
||||
import { IJSONSchema } from 'vs/base/common/jsonSchema';
|
||||
import { localize } from 'vs/nls';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { deepClone } from 'vs/base/common/objects';
|
||||
|
||||
import * as resources from 'vs/base/common/resources';
|
||||
import { ConnectionProviderProperties } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
|
||||
export const Extensions = {
|
||||
ConnectionProviderContributions: 'connection.providers'
|
||||
};
|
||||
|
||||
export interface IConnectionProviderRegistry {
|
||||
registerConnectionProvider(id: string, properties: ConnectionProviderProperties): void;
|
||||
getProperties(id: string): ConnectionProviderProperties | undefined;
|
||||
readonly onNewProvider: Event<{ id: string, properties: ConnectionProviderProperties }>;
|
||||
readonly providers: { [id: string]: ConnectionProviderProperties };
|
||||
}
|
||||
|
||||
class ConnectionProviderRegistryImpl implements IConnectionProviderRegistry {
|
||||
private _providers = new Map<string, ConnectionProviderProperties>();
|
||||
private _onNewProvider = new Emitter<{ id: string, properties: ConnectionProviderProperties }>();
|
||||
public readonly onNewProvider: Event<{ id: string, properties: ConnectionProviderProperties }> = this._onNewProvider.event;
|
||||
|
||||
public registerConnectionProvider(id: string, properties: ConnectionProviderProperties): void {
|
||||
this._providers.set(id, properties);
|
||||
this._onNewProvider.fire({ id, properties });
|
||||
}
|
||||
|
||||
public getProperties(id: string): ConnectionProviderProperties | undefined {
|
||||
return this._providers.get(id);
|
||||
}
|
||||
|
||||
public get providers(): { [id: string]: ConnectionProviderProperties } {
|
||||
let rt: { [id: string]: ConnectionProviderProperties } = {};
|
||||
this._providers.forEach((v, k) => {
|
||||
rt[k] = deepClone(v);
|
||||
});
|
||||
return rt;
|
||||
}
|
||||
}
|
||||
|
||||
const connectionRegistry = new ConnectionProviderRegistryImpl();
|
||||
Registry.add(Extensions.ConnectionProviderContributions, connectionRegistry);
|
||||
|
||||
const ConnectionProviderContrib: IJSONSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
providerId: {
|
||||
type: 'string',
|
||||
description: localize('schema.providerId', "Common id for the provider")
|
||||
},
|
||||
displayName: {
|
||||
type: 'string',
|
||||
description: localize('schema.displayName', "Display Name for the provider")
|
||||
},
|
||||
iconPath: {
|
||||
description: localize('schema.iconPath', "Icon path for the server type"),
|
||||
oneOf: [
|
||||
{
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: {
|
||||
type: 'string',
|
||||
},
|
||||
path: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
light: {
|
||||
type: 'string',
|
||||
},
|
||||
dark: {
|
||||
type: 'string',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'object',
|
||||
properties: {
|
||||
light: {
|
||||
type: 'string',
|
||||
},
|
||||
dark: {
|
||||
type: 'string',
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
},
|
||||
connectionOptions: {
|
||||
type: 'array',
|
||||
description: localize('schema.connectionOptions', "Options for connection"),
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
specialValueType: {
|
||||
type: 'string'
|
||||
},
|
||||
isIdentity: {
|
||||
type: 'boolean'
|
||||
},
|
||||
name: {
|
||||
type: 'string'
|
||||
},
|
||||
displayName: {
|
||||
type: 'string'
|
||||
},
|
||||
description: {
|
||||
type: 'string'
|
||||
},
|
||||
groupName: {
|
||||
type: 'string'
|
||||
},
|
||||
valueType: {
|
||||
type: 'string'
|
||||
},
|
||||
defaultValue: {
|
||||
type: 'any'
|
||||
},
|
||||
objectType: {
|
||||
type: 'any'
|
||||
},
|
||||
categoryValues: {
|
||||
type: 'any'
|
||||
},
|
||||
isRequired: {
|
||||
type: 'boolean'
|
||||
},
|
||||
isArray: {
|
||||
type: 'bolean'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
required: ['providerId']
|
||||
};
|
||||
|
||||
ExtensionsRegistry.registerExtensionPoint<ConnectionProviderProperties | ConnectionProviderProperties[]>({ extensionPoint: 'connectionProvider', jsonSchema: ConnectionProviderContrib }).setHandler(extensions => {
|
||||
|
||||
function handleCommand(contrib: ConnectionProviderProperties, extension: IExtensionPointUser<any>) {
|
||||
connectionRegistry.registerConnectionProvider(contrib.providerId, contrib);
|
||||
}
|
||||
|
||||
for (let extension of extensions) {
|
||||
const { value } = extension;
|
||||
resolveIconPath(extension);
|
||||
if (Array.isArray<ConnectionProviderProperties>(value)) {
|
||||
for (let command of value) {
|
||||
handleCommand(command, extension);
|
||||
}
|
||||
} else {
|
||||
handleCommand(value, extension);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
function resolveIconPath(extension: IExtensionPointUser<any>): void {
|
||||
if (!extension || !extension.value) { return undefined; }
|
||||
|
||||
let toAbsolutePath = (iconPath: any) => {
|
||||
if (!iconPath || !baseDir) { return; }
|
||||
if (Array.isArray(iconPath)) {
|
||||
for (let e of iconPath) {
|
||||
e.path = {
|
||||
light: resources.joinPath(extension.description.extensionLocation, e.path.light.toString()),
|
||||
dark: resources.joinPath(extension.description.extensionLocation, e.path.dark.toString())
|
||||
};
|
||||
}
|
||||
} else if (typeof iconPath === 'string') {
|
||||
iconPath = {
|
||||
light: resources.joinPath(extension.description.extensionLocation, iconPath),
|
||||
dark: resources.joinPath(extension.description.extensionLocation, iconPath)
|
||||
};
|
||||
} else {
|
||||
iconPath = {
|
||||
light: resources.joinPath(extension.description.extensionLocation, iconPath.light.toString()),
|
||||
dark: resources.joinPath(extension.description.extensionLocation, iconPath.dark.toString())
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
let baseDir = extension.description.extensionLocation.fsPath;
|
||||
let properties: ConnectionProviderProperties = extension.value;
|
||||
if (Array.isArray<ConnectionProviderProperties>(properties)) {
|
||||
for (let p of properties) {
|
||||
toAbsolutePath(p['iconPath']);
|
||||
}
|
||||
} else {
|
||||
toAbsolutePath(properties['iconPath']);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { localize } from 'vs/nls';
|
||||
|
||||
export const onDidConnectMessage = localize('onDidConnectMessage', "Connected to");
|
||||
export const onDidDisconnectMessage = localize('onDidDisconnectMessage', "Disconnected");
|
||||
export const unsavedGroupLabel = localize('unsavedGroupLabel', "Unsaved Connections");
|
||||
@@ -0,0 +1,54 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { RawContextKey, IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
|
||||
import { ServerInfo } from 'azdata';
|
||||
import { DatabaseEngineEdition } from 'sql/workbench/api/common/sqlExtHostTypes';
|
||||
|
||||
export class ServerInfoContextKey implements IContextKey<ServerInfo> {
|
||||
|
||||
static ServerInfo = new RawContextKey<ServerInfo>('serverInfo', undefined);
|
||||
static ServerMajorVersion = new RawContextKey<string>('serverMajorVersion', undefined);
|
||||
static IsCloud = new RawContextKey<boolean>('isCloud', undefined);
|
||||
static IsBigDataCluster = new RawContextKey<boolean>('isBigDataCluster', undefined);
|
||||
static EngineEdition = new RawContextKey<number>('engineEdition', undefined);
|
||||
|
||||
private _serverInfo: IContextKey<ServerInfo>;
|
||||
private _serverMajorVersion: IContextKey<string>;
|
||||
private _isCloud: IContextKey<boolean>;
|
||||
private _isBigDataCluster: IContextKey<boolean>;
|
||||
private _engineEdition: IContextKey<number>;
|
||||
|
||||
constructor(
|
||||
@IContextKeyService contextKeyService: IContextKeyService
|
||||
) {
|
||||
this._serverInfo = ServerInfoContextKey.ServerInfo.bindTo(contextKeyService);
|
||||
this._serverMajorVersion = ServerInfoContextKey.ServerMajorVersion.bindTo(contextKeyService);
|
||||
this._isCloud = ServerInfoContextKey.IsCloud.bindTo(contextKeyService);
|
||||
this._isBigDataCluster = ServerInfoContextKey.IsBigDataCluster.bindTo(contextKeyService);
|
||||
this._engineEdition = ServerInfoContextKey.EngineEdition.bindTo(contextKeyService);
|
||||
}
|
||||
|
||||
set(value: ServerInfo) {
|
||||
this._serverInfo.set(value);
|
||||
let majorVersion = value && value.serverMajorVersion;
|
||||
this._serverMajorVersion.set(majorVersion && `${majorVersion}`);
|
||||
this._isCloud.set(value && value.isCloud);
|
||||
this._isBigDataCluster.set(value && value.options && value.options['isBigDataCluster']);
|
||||
let engineEditionId = value && value.engineEditionId;
|
||||
engineEditionId ? this._engineEdition.set(engineEditionId) : this._engineEdition.set(DatabaseEngineEdition.Unknown);
|
||||
}
|
||||
|
||||
reset(): void {
|
||||
this._serverMajorVersion.reset();
|
||||
this._isCloud.reset();
|
||||
this._isBigDataCluster.reset();
|
||||
this._engineEdition.reset();
|
||||
}
|
||||
|
||||
public get(): ServerInfo {
|
||||
return this._serverInfo.get();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user