mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-30 09:35:39 -05:00
Remove sql/common (#4990)
* remove sql/common/ * formatting * fix cyclic dependency
This commit is contained in:
@@ -32,7 +32,7 @@ import { AddAccountAction } from 'sql/platform/accounts/common/accountActions';
|
||||
import { AccountListRenderer, AccountListDelegate } from 'sql/platform/accounts/browser/accountListRenderer';
|
||||
import { AccountProviderAddedEventParams, UpdateAccountListEventParams } from 'sql/platform/accounts/common/eventTypes';
|
||||
import { IClipboardService } from 'sql/platform/clipboard/common/clipboardService';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import * as TelemetryKeys from 'sql/platform/telemetry/telemetryKeys';
|
||||
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
|
||||
|
||||
class AccountPanel extends ViewletPanel {
|
||||
|
||||
@@ -19,7 +19,7 @@ import { Modal } from 'sql/workbench/browser/modal/modal';
|
||||
import { InputBox } from 'sql/base/browser/ui/inputBox/inputBox';
|
||||
import { attachModalDialogStyler, attachButtonStyler } from 'sql/platform/theme/common/styler';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import * as TelemetryKeys from 'sql/platform/telemetry/telemetryKeys';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/layoutService';
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import { FirewallRuleViewModel } from 'sql/platform/accounts/common/firewallRule
|
||||
import { attachModalDialogStyler, attachButtonStyler } from 'sql/platform/theme/common/styler';
|
||||
import { InputBox } from 'sql/base/browser/ui/inputBox/inputBox';
|
||||
import { IAccountPickerService } from 'sql/platform/accounts/common/accountPicker';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import * as TelemetryKeys from 'sql/platform/telemetry/telemetryKeys';
|
||||
|
||||
// TODO: Make the help link 1) extensible (01/08/2018, https://github.com/Microsoft/azuredatastudio/issues/450)
|
||||
// in case that other non-Azure sign in is to be used
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import * as azdata from 'azdata';
|
||||
import * as Constants from 'sql/common/constants';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import * as TelemetryUtils from 'sql/common/telemetryUtilities';
|
||||
import * as TelemetryKeys from 'sql/platform/telemetry/telemetryKeys';
|
||||
import * as TelemetryUtils from 'sql/platform/telemetry/telemetryUtilities';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IBackupService, TaskExecutionMode } from 'sql/platform/backup/common/backupService';
|
||||
import { invalidProvider } from 'sql/base/common/errors';
|
||||
|
||||
export class BackupService implements IBackupService {
|
||||
|
||||
@@ -42,7 +41,7 @@ export class BackupService implements IBackupService {
|
||||
*/
|
||||
public backup(connectionUri: string, backupInfo: { [key: string]: any }, taskExecutionMode: TaskExecutionMode): Thenable<azdata.BackupResponse> {
|
||||
return new Promise<azdata.BackupResponse>((resolve, reject) => {
|
||||
let providerResult = this.getProvider(connectionUri);
|
||||
const providerResult = this.getProvider(connectionUri);
|
||||
if (providerResult) {
|
||||
TelemetryUtils.addTelemetry(this._telemetryService, TelemetryKeys.BackupCreated, { provider: providerResult.providerName });
|
||||
providerResult.provider.backup(connectionUri, backupInfo, taskExecutionMode).then(result => {
|
||||
@@ -51,7 +50,7 @@ export class BackupService implements IBackupService {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(Constants.InvalidProvider);
|
||||
reject(invalidProvider());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,40 +3,19 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { ConnectionManagementInfo } from 'sql/platform/connection/common/connectionManagementInfo';
|
||||
import * as Constants from 'sql/common/constants';
|
||||
import { ConnectionProviderProperties, IConnectionProviderRegistry, Extensions as ConnectionExtensions } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
import { toObject } from 'sql/base/common/map';
|
||||
import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
|
||||
import * as azdata from 'sqlops';
|
||||
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import { IAction } from 'vs/base/common/actions';
|
||||
import { Memento } from 'vs/workbench/common/memento';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { entries } from 'sql/base/common/objects';
|
||||
|
||||
export const SERVICE_ID = 'capabilitiesService';
|
||||
export const HOST_NAME = 'azdata';
|
||||
export const HOST_VERSION = '1.0';
|
||||
|
||||
const connectionRegistry = Registry.as<IConnectionProviderRegistry>(ConnectionExtensions.ConnectionProviderContributions);
|
||||
|
||||
interface ConnectionCache {
|
||||
[id: string]: ConnectionProviderProperties;
|
||||
}
|
||||
|
||||
interface CapabilitiesMomento {
|
||||
connectionProviderCache: ConnectionCache;
|
||||
}
|
||||
|
||||
export const clientCapabilities = {
|
||||
hostName: HOST_NAME,
|
||||
hostVersion: HOST_VERSION
|
||||
@@ -86,161 +65,3 @@ export interface ICapabilitiesService {
|
||||
readonly providers: { [id: string]: ProviderFeatures };
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Capabilities service implementation class. This class provides the ability
|
||||
* to discover the DMP capabilties that a DMP provider offers.
|
||||
*/
|
||||
export class CapabilitiesService extends Disposable implements ICapabilitiesService {
|
||||
_serviceBrand: any;
|
||||
|
||||
private _momento: Memento;
|
||||
private _providers = new Map<string, ProviderFeatures>();
|
||||
private _featureUpdateEvents = new Map<string, Emitter<ProviderFeatures>>();
|
||||
private _legacyProviders = new Map<string, azdata.DataProtocolServerCapabilities>();
|
||||
|
||||
private _onCapabilitiesRegistered = this._register(new Emitter<ProviderFeatures>());
|
||||
public readonly onCapabilitiesRegistered = this._onCapabilitiesRegistered.event;
|
||||
|
||||
constructor(
|
||||
@IStorageService private _storageService: IStorageService,
|
||||
@IExtensionService extensionService: IExtensionService,
|
||||
@IExtensionManagementService extentionManagementService: IExtensionManagementService
|
||||
) {
|
||||
super();
|
||||
|
||||
this._momento = new Memento('capabilities', this._storageService);
|
||||
|
||||
if (!this.capabilities.connectionProviderCache) {
|
||||
this.capabilities.connectionProviderCache = {};
|
||||
}
|
||||
|
||||
// handle in case some extensions have already registered (unlikley)
|
||||
entries(connectionRegistry.providers).map(v => {
|
||||
this.handleConnectionProvider({ id: v[0], properties: v[1] });
|
||||
});
|
||||
// register for when new extensions are added
|
||||
this._register(connectionRegistry.onNewProvider(this.handleConnectionProvider, this));
|
||||
|
||||
// handle adding already known capabilities (could have caching problems)
|
||||
entries(this.capabilities.connectionProviderCache).map(v => {
|
||||
this.handleConnectionProvider({ id: v[0], properties: v[1] }, false);
|
||||
});
|
||||
|
||||
extensionService.whenInstalledExtensionsRegistered().then(() => {
|
||||
this.cleanupProviders();
|
||||
});
|
||||
|
||||
_storageService.onWillSaveState(() => this.shutdown());
|
||||
|
||||
this._register(extentionManagementService.onDidUninstallExtension(({ identifier }) => {
|
||||
const connectionProvider = 'connectionProvider';
|
||||
extensionService.getExtensions().then(i => {
|
||||
let extension = i.find(c => c.identifier.value.toLowerCase() === identifier.id.toLowerCase());
|
||||
if (extension && extension.contributes
|
||||
&& extension.contributes[connectionProvider]
|
||||
&& extension.contributes[connectionProvider].providerId) {
|
||||
let id = extension.contributes[connectionProvider].providerId;
|
||||
delete this.capabilities.connectionProviderCache[id];
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private cleanupProviders(): void {
|
||||
let knownProviders = Object.keys(connectionRegistry.providers);
|
||||
for (let key in this.capabilities.connectionProviderCache) {
|
||||
if (!knownProviders.includes(key)) {
|
||||
this._providers.delete(key);
|
||||
delete this.capabilities.connectionProviderCache[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private handleConnectionProvider(e: { id: string, properties: ConnectionProviderProperties }, isNew = true): void {
|
||||
|
||||
let provider = this._providers.get(e.id);
|
||||
if (provider) {
|
||||
provider.connection = e.properties;
|
||||
} else {
|
||||
provider = {
|
||||
connection: e.properties
|
||||
};
|
||||
this._providers.set(e.id, provider);
|
||||
}
|
||||
if (!this._featureUpdateEvents.has(e.id)) {
|
||||
this._featureUpdateEvents.set(e.id, new Emitter<ProviderFeatures>());
|
||||
}
|
||||
|
||||
if (isNew) {
|
||||
this.capabilities.connectionProviderCache[e.id] = e.properties;
|
||||
this._onCapabilitiesRegistered.fire(provider);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of registered server capabilities
|
||||
*/
|
||||
public getCapabilities(provider: string): ProviderFeatures {
|
||||
return this._providers.get(provider);
|
||||
}
|
||||
|
||||
public getLegacyCapabilities(provider: string): azdata.DataProtocolServerCapabilities {
|
||||
return this._legacyProviders.get(provider);
|
||||
}
|
||||
|
||||
public get providers(): { [id: string]: ProviderFeatures } {
|
||||
return toObject(this._providers);
|
||||
}
|
||||
|
||||
private get capabilities(): CapabilitiesMomento {
|
||||
return this._momento.getMemento(StorageScope.GLOBAL) as CapabilitiesMomento;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the capabilities provider and query the provider for its capabilities
|
||||
* @param provider
|
||||
*/
|
||||
public registerProvider(provider: azdata.CapabilitiesProvider): void {
|
||||
// request the capabilities from server
|
||||
provider.getServerCapabilities(clientCapabilities).then(serverCapabilities => {
|
||||
this._legacyProviders.set(serverCapabilities.providerName, serverCapabilities);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the feature is available for given connection
|
||||
* @param featureComponent a component which should have the feature name
|
||||
* @param connectionManagementInfo connectionManagementInfo
|
||||
*/
|
||||
public isFeatureAvailable(action: IAction, connectionManagementInfo: ConnectionManagementInfo): boolean {
|
||||
let isCloud = connectionManagementInfo && connectionManagementInfo.serverInfo && connectionManagementInfo.serverInfo.isCloud;
|
||||
let isMssql = connectionManagementInfo.connectionProfile.providerName === 'MSSQL';
|
||||
// TODO: The logic should from capabilities service.
|
||||
if (action) {
|
||||
let featureName: string = action.id;
|
||||
switch (featureName) {
|
||||
case Constants.BackupFeatureName:
|
||||
if (isMssql) {
|
||||
return connectionManagementInfo.connectionProfile.databaseName && !isCloud;
|
||||
} else {
|
||||
return !!connectionManagementInfo.connectionProfile.databaseName;
|
||||
}
|
||||
case Constants.RestoreFeatureName:
|
||||
if (isMssql) {
|
||||
return !isCloud;
|
||||
} else {
|
||||
return !!connectionManagementInfo.connectionProfile.databaseName;
|
||||
}
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private shutdown(): void {
|
||||
this._momento.saveMemento();
|
||||
}
|
||||
}
|
||||
|
||||
190
src/sql/platform/capabilities/common/capabilitiesServiceImpl.ts
Normal file
190
src/sql/platform/capabilities/common/capabilitiesServiceImpl.ts
Normal file
@@ -0,0 +1,190 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { IExtensionManagementService } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
|
||||
import { Memento } from 'vs/workbench/common/memento';
|
||||
import { Emitter } from 'vs/base/common/event';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { Registry } from 'vs/platform/registry/common/platform';
|
||||
import { IAction } from 'vs/base/common/actions';
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
|
||||
import { entries } from 'sql/base/common/objects';
|
||||
import { RestoreFeatureName, BackupFeatureName } from 'sql/workbench/common/actions';
|
||||
import { toObject } from 'sql/base/common/map';
|
||||
import { ConnectionProviderProperties, IConnectionProviderRegistry, Extensions as ConnectionExtensions } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
|
||||
import { ICapabilitiesService, ProviderFeatures, clientCapabilities } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { ConnectionManagementInfo } from 'sql/platform/connection/common/connectionManagementInfo';
|
||||
|
||||
const connectionRegistry = Registry.as<IConnectionProviderRegistry>(ConnectionExtensions.ConnectionProviderContributions);
|
||||
|
||||
interface ConnectionCache {
|
||||
[id: string]: ConnectionProviderProperties;
|
||||
}
|
||||
|
||||
interface CapabilitiesMomento {
|
||||
connectionProviderCache: ConnectionCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Capabilities service implementation class. This class provides the ability
|
||||
* to discover the DMP capabilties that a DMP provider offers.
|
||||
*/
|
||||
export class CapabilitiesService extends Disposable implements ICapabilitiesService {
|
||||
_serviceBrand: any;
|
||||
|
||||
private _momento: Memento;
|
||||
private _providers = new Map<string, ProviderFeatures>();
|
||||
private _featureUpdateEvents = new Map<string, Emitter<ProviderFeatures>>();
|
||||
private _legacyProviders = new Map<string, azdata.DataProtocolServerCapabilities>();
|
||||
|
||||
private _onCapabilitiesRegistered = this._register(new Emitter<ProviderFeatures>());
|
||||
public readonly onCapabilitiesRegistered = this._onCapabilitiesRegistered.event;
|
||||
|
||||
constructor(
|
||||
@IStorageService private _storageService: IStorageService,
|
||||
@IExtensionService extensionService: IExtensionService,
|
||||
@IExtensionManagementService extentionManagementService: IExtensionManagementService
|
||||
) {
|
||||
super();
|
||||
|
||||
this._momento = new Memento('capabilities', this._storageService);
|
||||
|
||||
if (!this.capabilities.connectionProviderCache) {
|
||||
this.capabilities.connectionProviderCache = {};
|
||||
}
|
||||
|
||||
// handle in case some extensions have already registered (unlikley)
|
||||
entries(connectionRegistry.providers).map(v => {
|
||||
this.handleConnectionProvider({ id: v[0], properties: v[1] });
|
||||
});
|
||||
// register for when new extensions are added
|
||||
this._register(connectionRegistry.onNewProvider(this.handleConnectionProvider, this));
|
||||
|
||||
// handle adding already known capabilities (could have caching problems)
|
||||
entries(this.capabilities.connectionProviderCache).map(v => {
|
||||
this.handleConnectionProvider({ id: v[0], properties: v[1] }, false);
|
||||
});
|
||||
|
||||
extensionService.whenInstalledExtensionsRegistered().then(() => {
|
||||
this.cleanupProviders();
|
||||
});
|
||||
|
||||
_storageService.onWillSaveState(() => this.shutdown());
|
||||
|
||||
this._register(extentionManagementService.onDidUninstallExtension(({ identifier }) => {
|
||||
const connectionProvider = 'connectionProvider';
|
||||
extensionService.getExtensions().then(i => {
|
||||
let extension = i.find(c => c.identifier.value.toLowerCase() === identifier.id.toLowerCase());
|
||||
if (extension && extension.contributes
|
||||
&& extension.contributes[connectionProvider]
|
||||
&& extension.contributes[connectionProvider].providerId) {
|
||||
let id = extension.contributes[connectionProvider].providerId;
|
||||
delete this.capabilities.connectionProviderCache[id];
|
||||
}
|
||||
});
|
||||
}));
|
||||
}
|
||||
|
||||
private cleanupProviders(): void {
|
||||
let knownProviders = Object.keys(connectionRegistry.providers);
|
||||
for (let key in this.capabilities.connectionProviderCache) {
|
||||
if (!knownProviders.includes(key)) {
|
||||
this._providers.delete(key);
|
||||
delete this.capabilities.connectionProviderCache[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private handleConnectionProvider(e: { id: string, properties: ConnectionProviderProperties }, isNew = true): void {
|
||||
|
||||
let provider = this._providers.get(e.id);
|
||||
if (provider) {
|
||||
provider.connection = e.properties;
|
||||
} else {
|
||||
provider = {
|
||||
connection: e.properties
|
||||
};
|
||||
this._providers.set(e.id, provider);
|
||||
}
|
||||
if (!this._featureUpdateEvents.has(e.id)) {
|
||||
this._featureUpdateEvents.set(e.id, new Emitter<ProviderFeatures>());
|
||||
}
|
||||
|
||||
if (isNew) {
|
||||
this.capabilities.connectionProviderCache[e.id] = e.properties;
|
||||
this._onCapabilitiesRegistered.fire(provider);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a list of registered server capabilities
|
||||
*/
|
||||
public getCapabilities(provider: string): ProviderFeatures {
|
||||
return this._providers.get(provider);
|
||||
}
|
||||
|
||||
public getLegacyCapabilities(provider: string): azdata.DataProtocolServerCapabilities {
|
||||
return this._legacyProviders.get(provider);
|
||||
}
|
||||
|
||||
public get providers(): { [id: string]: ProviderFeatures } {
|
||||
return toObject(this._providers);
|
||||
}
|
||||
|
||||
private get capabilities(): CapabilitiesMomento {
|
||||
return this._momento.getMemento(StorageScope.GLOBAL) as CapabilitiesMomento;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the capabilities provider and query the provider for its capabilities
|
||||
* @param provider
|
||||
*/
|
||||
public registerProvider(provider: azdata.CapabilitiesProvider): void {
|
||||
// request the capabilities from server
|
||||
provider.getServerCapabilities(clientCapabilities).then(serverCapabilities => {
|
||||
this._legacyProviders.set(serverCapabilities.providerName, serverCapabilities);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the feature is available for given connection
|
||||
* @param featureComponent a component which should have the feature name
|
||||
* @param connectionManagementInfo connectionManagementInfo
|
||||
*/
|
||||
public isFeatureAvailable(action: IAction, connectionManagementInfo: ConnectionManagementInfo): boolean {
|
||||
let isCloud = connectionManagementInfo && connectionManagementInfo.serverInfo && connectionManagementInfo.serverInfo.isCloud;
|
||||
let isMssql = connectionManagementInfo.connectionProfile.providerName === 'MSSQL';
|
||||
// TODO: The logic should from capabilities service.
|
||||
if (action) {
|
||||
let featureName: string = action.id;
|
||||
switch (featureName) {
|
||||
case BackupFeatureName:
|
||||
if (isMssql) {
|
||||
return connectionManagementInfo.connectionProfile.databaseName && !isCloud;
|
||||
} else {
|
||||
return !!connectionManagementInfo.connectionProfile.databaseName;
|
||||
}
|
||||
case RestoreFeatureName:
|
||||
if (isMssql) {
|
||||
return !isCloud;
|
||||
} else {
|
||||
return !!connectionManagementInfo.connectionProfile.databaseName;
|
||||
}
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private shutdown(): void {
|
||||
this._momento.saveMemento();
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,8 @@ import { ConnectionStatusManager } from 'sql/platform/connection/common/connecti
|
||||
import { DashboardInput } from 'sql/workbench/parts/dashboard/dashboardInput';
|
||||
import { ConnectionGlobalStatus } from 'sql/parts/connection/common/connectionGlobalStatus';
|
||||
import { ConnectionStatusbarItem } from 'sql/parts/connection/common/connectionStatus';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import * as TelemetryUtils from 'sql/common/telemetryUtilities';
|
||||
import * as TelemetryKeys from 'sql/platform/telemetry/telemetryKeys';
|
||||
import * as TelemetryUtils from 'sql/platform/telemetry/telemetryUtilities';
|
||||
import { warn } from 'sql/base/common/log';
|
||||
import { IResourceProviderService } from 'sql/workbench/services/resourceProvider/common/resourceProviderService';
|
||||
import { IAngularEventingService, AngularEventType } from 'sql/platform/angularEventing/common/angularEventingService';
|
||||
|
||||
@@ -3,20 +3,18 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import * as azdata from 'azdata';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { FileBrowserTree } from 'sql/workbench/services/fileBrowser/common/fileBrowserTree';
|
||||
import { FileNode } from 'sql/workbench/services/fileBrowser/common/fileNode';
|
||||
import { IFileBrowserService } from 'sql/platform/fileBrowser/common/interfaces';
|
||||
import * as Constants from 'sql/common/constants';
|
||||
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
|
||||
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import { localize } from 'vs/nls';
|
||||
import * as strings from 'vs/base/common/strings';
|
||||
import { invalidProvider } from 'sql/base/common/errors';
|
||||
|
||||
export class FileBrowserService implements IFileBrowserService {
|
||||
public _serviceBrand: any;
|
||||
@@ -28,7 +26,7 @@ export class FileBrowserService implements IFileBrowserService {
|
||||
private _expandResolveMap: { [key: string]: any } = {};
|
||||
static fileNodeId: number = 0;
|
||||
|
||||
constructor( @IConnectionManagementService private _connectionService: IConnectionManagementService,
|
||||
constructor(@IConnectionManagementService private _connectionService: IConnectionManagementService,
|
||||
@IErrorMessageService private _errorMessageService: IErrorMessageService) {
|
||||
}
|
||||
|
||||
@@ -50,7 +48,7 @@ export class FileBrowserService implements IFileBrowserService {
|
||||
|
||||
public openFileBrowser(ownerUri: string, expandPath: string, fileFilters: string[], changeFilter: boolean): Thenable<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
let provider = this.getProvider(ownerUri);
|
||||
const provider = this.getProvider(ownerUri);
|
||||
if (provider) {
|
||||
provider.openFileBrowser(ownerUri, expandPath, fileFilters, changeFilter).then(result => {
|
||||
resolve(result);
|
||||
@@ -58,7 +56,7 @@ export class FileBrowserService implements IFileBrowserService {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(Constants.InvalidProvider);
|
||||
reject(invalidProvider());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -83,7 +81,7 @@ export class FileBrowserService implements IFileBrowserService {
|
||||
this._pathToFileNodeMap[fileNode.fullPath] = fileNode;
|
||||
let self = this;
|
||||
return new Promise<FileNode[]>((resolve, reject) => {
|
||||
let provider = this.getProvider(fileNode.ownerUri);
|
||||
const provider = this.getProvider(fileNode.ownerUri);
|
||||
if (provider) {
|
||||
provider.expandFolderNode(fileNode.ownerUri, fileNode.fullPath).then(result => {
|
||||
var mapKey = self.generateResolveMapKey(fileNode.ownerUri, fileNode.fullPath);
|
||||
@@ -92,7 +90,7 @@ export class FileBrowserService implements IFileBrowserService {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(Constants.InvalidProvider);
|
||||
reject(invalidProvider());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -121,7 +119,7 @@ export class FileBrowserService implements IFileBrowserService {
|
||||
|
||||
public validateFilePaths(ownerUri: string, serviceType: string, selectedFiles: string[]): Thenable<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
let provider = this.getProvider(ownerUri);
|
||||
const provider = this.getProvider(ownerUri);
|
||||
if (provider) {
|
||||
provider.validateFilePaths(ownerUri, serviceType, selectedFiles).then(result => {
|
||||
resolve(result);
|
||||
@@ -129,7 +127,7 @@ export class FileBrowserService implements IFileBrowserService {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(Constants.InvalidProvider);
|
||||
reject(invalidProvider());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ import { OperatorsViewComponent } from 'sql/parts/jobManagement/views/operatorsV
|
||||
import { ProxiesViewComponent } from 'sql/parts/jobManagement/views/proxiesView.component';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import * as TelemetryKeys from 'sql/platform/telemetry/telemetryKeys';
|
||||
import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMessageService';
|
||||
import { JobManagementView } from 'sql/parts/jobManagement/views/jobManagementView';
|
||||
|
||||
@@ -104,7 +104,7 @@ export class RunJobAction extends Action {
|
||||
this.jobManagementService.jobAction(ownerUri, jobName, JobActions.Run).then(result => {
|
||||
if (result.success) {
|
||||
var startMsg = nls.localize('jobSuccessfullyStarted', ': The job was successfully started.');
|
||||
this.notificationService.info(jobName+startMsg);
|
||||
this.notificationService.info(jobName + startMsg);
|
||||
refreshAction.run(context);
|
||||
resolve(true);
|
||||
} else {
|
||||
@@ -140,7 +140,7 @@ export class StopJobAction extends Action {
|
||||
if (result.success) {
|
||||
refreshAction.run(context);
|
||||
var stopMsg = nls.localize('jobSuccessfullyStopped', ': The job was successfully stopped.');
|
||||
this.notificationService.info(jobName+stopMsg);
|
||||
this.notificationService.info(jobName + stopMsg);
|
||||
resolve(true);
|
||||
} else {
|
||||
this.errorMessageService.showDialog(Severity.Error, 'Error', result.errorMessage);
|
||||
@@ -532,7 +532,7 @@ export class DeleteProxyAction extends Action {
|
||||
if (!result || !result.success) {
|
||||
let errorMessage = nls.localize("jobaction.failedToDeleteProxy", "Could not delete proxy '{0}'.\nError: {1}",
|
||||
proxy.accountName, result.errorMessage ? result.errorMessage : 'Unknown error');
|
||||
self._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
|
||||
self._errorMessageService.showDialog(Severity.Error, errorLabel, errorMessage);
|
||||
} else {
|
||||
let successMessage = nls.localize('jobaction.deletedProxy', 'The proxy was deleted successfully');
|
||||
self._notificationService.info(successMessage);
|
||||
@@ -546,4 +546,4 @@ export class DeleteProxyAction extends Action {
|
||||
);
|
||||
return Promise.resolve(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import { IConnectionManagementService } from 'sql/platform/connection/common/con
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import * as azdata from 'azdata';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import * as TelemetryUtils from 'sql/common/telemetryUtilities';
|
||||
import * as TelemetryKeys from 'sql/platform/telemetry/telemetryKeys';
|
||||
import * as TelemetryUtils from 'sql/platform/telemetry/telemetryUtilities';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { Event, Emitter } from 'vs/base/common/event';
|
||||
import { keys } from 'vs/base/common/map';
|
||||
@@ -335,4 +335,4 @@ export class QueryManagementService implements IQueryManagementService {
|
||||
return runner.getEditRows(rowData);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import * as types from 'vs/base/common/types';
|
||||
@@ -22,10 +21,10 @@ import * as Utils from 'sql/platform/connection/common/utils';
|
||||
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/common/objectExplorerService';
|
||||
import { ITaskService } from 'sql/platform/taskHistory/common/taskService';
|
||||
import { TaskStatus, TaskNode } from 'sql/parts/taskHistory/common/taskNode';
|
||||
import * as Constants from 'sql/common/constants';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import * as TelemetryUtils from 'sql/common/telemetryUtilities';
|
||||
import * as TelemetryKeys from 'sql/platform/telemetry/telemetryKeys';
|
||||
import * as TelemetryUtils from 'sql/platform/telemetry/telemetryUtilities';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { invalidProvider } from 'sql/base/common/errors';
|
||||
|
||||
export class RestoreService implements IRestoreService {
|
||||
|
||||
@@ -43,7 +42,7 @@ export class RestoreService implements IRestoreService {
|
||||
*/
|
||||
getRestoreConfigInfo(connectionUri: string): Thenable<azdata.RestoreConfigInfo> {
|
||||
return new Promise<azdata.RestoreConfigInfo>((resolve, reject) => {
|
||||
let providerResult = this.getProvider(connectionUri);
|
||||
const providerResult = this.getProvider(connectionUri);
|
||||
if (providerResult) {
|
||||
providerResult.provider.getRestoreConfigInfo(connectionUri).then(result => {
|
||||
resolve(result);
|
||||
@@ -51,7 +50,7 @@ export class RestoreService implements IRestoreService {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(Constants.InvalidProvider);
|
||||
reject(invalidProvider());
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -61,7 +60,7 @@ export class RestoreService implements IRestoreService {
|
||||
*/
|
||||
restore(connectionUri: string, restoreInfo: azdata.RestoreInfo): Thenable<azdata.RestoreResponse> {
|
||||
return new Promise<azdata.RestoreResponse>((resolve, reject) => {
|
||||
let providerResult = this.getProvider(connectionUri);
|
||||
const providerResult = this.getProvider(connectionUri);
|
||||
if (providerResult) {
|
||||
TelemetryUtils.addTelemetry(this._telemetryService, TelemetryKeys.RestoreRequested, { provider: providerResult.providerName });
|
||||
providerResult.provider.restore(connectionUri, restoreInfo).then(result => {
|
||||
@@ -70,7 +69,7 @@ export class RestoreService implements IRestoreService {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(Constants.InvalidProvider);
|
||||
reject(invalidProvider);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -89,7 +88,7 @@ export class RestoreService implements IRestoreService {
|
||||
*/
|
||||
getRestorePlan(connectionUri: string, restoreInfo: azdata.RestoreInfo): Thenable<azdata.RestorePlanResponse> {
|
||||
return new Promise<azdata.RestorePlanResponse>((resolve, reject) => {
|
||||
let providerResult = this.getProvider(connectionUri);
|
||||
const providerResult = this.getProvider(connectionUri);
|
||||
if (providerResult) {
|
||||
providerResult.provider.getRestorePlan(connectionUri, restoreInfo).then(result => {
|
||||
resolve(result);
|
||||
@@ -97,7 +96,7 @@ export class RestoreService implements IRestoreService {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(Constants.InvalidProvider);
|
||||
reject(invalidProvider);
|
||||
|
||||
}
|
||||
});
|
||||
@@ -108,7 +107,7 @@ export class RestoreService implements IRestoreService {
|
||||
*/
|
||||
cancelRestorePlan(connectionUri: string, restoreInfo: azdata.RestoreInfo): Thenable<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
let providerResult = this.getProvider(connectionUri);
|
||||
const providerResult = this.getProvider(connectionUri);
|
||||
if (providerResult) {
|
||||
providerResult.provider.cancelRestorePlan(connectionUri, restoreInfo).then(result => {
|
||||
resolve(result);
|
||||
@@ -116,7 +115,7 @@ export class RestoreService implements IRestoreService {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(Constants.InvalidProvider);
|
||||
reject(invalidProvider);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
62
src/sql/platform/telemetry/telemetryKeys.ts
Normal file
62
src/sql/platform/telemetry/telemetryKeys.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
// Telemetry Event Names
|
||||
|
||||
export const DatabaseConnected = 'DatabaseConnected';
|
||||
export const DatabaseDisconnected = 'DatabaseDisconnected';
|
||||
export const DeleteConnection = 'DeleteConnection';
|
||||
export const AddServerGroup = 'AddServerGroup';
|
||||
export const MoveServerGroup = 'MoveServerGroup';
|
||||
export const MoveServerConnection = 'MoveServerConnection';
|
||||
export const DeleteServerGroup = 'DeleteServerGroup';
|
||||
export const ModalDialogClosed = 'ModalDialogClosed';
|
||||
export const ModalDialogOpened = 'ModalDialogOpened';
|
||||
export const BackupCreated = 'BackupCreated';
|
||||
export const RestoreRequested = 'RestoreRequested';
|
||||
export const ChartCreated = 'ChartCreated';
|
||||
export const ObjectExplorerExpand = 'ObjectExplorerExpand';
|
||||
export const RunQuery = 'RunQuery';
|
||||
export const RunQueryStatement = 'RunQueryStatement';
|
||||
export const CancelQuery = 'CancelQuery';
|
||||
export const NewQuery = 'NewQuery';
|
||||
export const FirewallRuleRequested = 'FirewallRuleCreated';
|
||||
export const DashboardNavigated = 'DashboardNavigated';
|
||||
|
||||
// Telemetry Properties
|
||||
|
||||
// Modal Dialogs:
|
||||
export const ErrorMessage = 'ErrorMessage';
|
||||
export const WebView = 'WebView';
|
||||
export const ConnectionAdvancedProperties = 'ConnectionAdvancedProperties';
|
||||
export const Connection = 'Connection';
|
||||
export const Backup = 'Backup';
|
||||
export const Restore = 'Restore';
|
||||
export const Insights = 'Insights';
|
||||
export const Profiler = 'Profiler';
|
||||
export const ServerGroups = 'ServerGroups';
|
||||
export const Accounts = 'Accounts';
|
||||
export const FireWallRule = 'FirewallRule';
|
||||
export const AutoOAuth = 'AutoOAuth';
|
||||
export const AddNewDashboardTab = 'AddNewDashboardTab';
|
||||
export const ProfilerFilter = 'ProfilerFilter';
|
||||
|
||||
// SQL Agent Events:
|
||||
|
||||
// Views
|
||||
export const JobsView = 'JobsViewOpened';
|
||||
export const JobHistoryView = 'JobHistoryViewOpened';
|
||||
export const JobStepsView = 'JobStepsViewOpened';
|
||||
|
||||
// Actions
|
||||
export const RunAgentJob = 'RunAgentJob';
|
||||
export const StopAgentJob = 'StopAgentJob';
|
||||
export const DeleteAgentJob = 'DeleteAgentJob';
|
||||
export const DeleteAgentJobStep = 'DeleteAgentJobStep';
|
||||
export const DeleteAgentAlert = 'DeleteAgentAlert';
|
||||
export const DeleteAgentOperator = 'DeleteAgentOperator';
|
||||
export const DeleteAgentProxy = 'DeleteAgentProxy';
|
||||
|
||||
|
||||
57
src/sql/platform/telemetry/telemetryUtilities.ts
Normal file
57
src/sql/platform/telemetry/telemetryUtilities.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { ITelemetryService, ITelemetryData } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { warn } from 'sql/base/common/log';
|
||||
|
||||
export interface IConnectionTelemetryData extends ITelemetryData {
|
||||
provider?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call the given telemetry service to log the telemetry event.
|
||||
* If the provider is not in the data, tries to get it from connection inside the data.
|
||||
* The connection in the data won't be included in the telemetry data
|
||||
* Note: userId is added to all telemetry events so no need to add it here
|
||||
* @param telemetryService Telemetry Service
|
||||
* @param telemetryEventName Telemetry event name
|
||||
* @param data Telemetry data
|
||||
*/
|
||||
export function addTelemetry(
|
||||
telemetryService: ITelemetryService,
|
||||
telemetryEventName: string,
|
||||
data?: IConnectionTelemetryData,
|
||||
connection?: IConnectionProfile): Promise<void> {
|
||||
return new Promise<void>(resolve => {
|
||||
try {
|
||||
let telData: ITelemetryData = data === undefined ? {} : data;
|
||||
|
||||
if (telData && telData.provider === undefined) {
|
||||
|
||||
let provider: string = '';
|
||||
if (connection) {
|
||||
provider = connection.providerName;
|
||||
}
|
||||
telData.provider = provider;
|
||||
}
|
||||
delete telData['connection'];
|
||||
if (telemetryService) {
|
||||
telemetryService.publicLog(telemetryEventName, telData).then(() => {
|
||||
resolve();
|
||||
}, telemetryServiceError => {
|
||||
warn(`Failed to add telemetry. error: ${telemetryServiceError}`);
|
||||
resolve();
|
||||
});
|
||||
} else {
|
||||
resolve();
|
||||
}
|
||||
} catch (error) {
|
||||
warn(`Failed to add telemetry. error: ${error}`);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user