-
Notifications
You must be signed in to change notification settings - Fork 899
/
connectionContextKey.ts
70 lines (60 loc) · 3.1 KB
/
connectionContextKey.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. 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/workbench/services/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);
static CanOpenInAzurePortal = new RawContextKey<boolean>('canOpenInAzurePortal', false);
private _providerKey: IContextKey<string>;
private _serverKey: IContextKey<string>;
private _databaseKey: IContextKey<string | undefined>;
private _connectionKey: IContextKey<IConnectionProfile>;
private _isQueryProviderKey: IContextKey<boolean>;
private _canOpenInAzurePortal: 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);
this._canOpenInAzurePortal = ConnectionContextKey.CanOpenInAzurePortal.bindTo(contextKeyService);
}
set(value: IConnectionProfile) {
this.setCanOpenInPortal(value);
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);
}
private setCanOpenInPortal(connectionProfile: IConnectionProfile): void {
if (connectionProfile &&
connectionProfile.azureResourceId &&
connectionProfile.azureTenantId &&
connectionProfile.azurePortalEndpoint) {
this._canOpenInAzurePortal.set(true);
}
}
reset(): void {
this._providerKey.reset();
this._serverKey.reset();
this._databaseKey.reset();
this._connectionKey.reset();
this._isQueryProviderKey.reset();
this._canOpenInAzurePortal.reset();
}
public get(): IConnectionProfile | undefined {
return this._connectionKey.get();
}
}