Angular Individual Service Injection - Decouple bootstrap service (#1457)

* change services to be individually injected into angular

* messing around with injection

* change angular bootstrapping to factory style

* formatting

* formatting

* fix imports

* fix build errors

* fix testsw

* fix tests

* fix compile errors
This commit is contained in:
Anthony Dresser
2018-05-23 16:51:02 -07:00
committed by GitHub
parent cd0f9b71c5
commit 1359354387
68 changed files with 1011 additions and 1116 deletions

View File

@@ -7,32 +7,30 @@ import { DataService } from 'sql/parts/grid/services/dataService';
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
import { IContextKeyService, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { ConnectionContextkey } from 'sql/parts/connection/common/connectionContextKey';
import { IBootstrapParams } from './bootstrapService';
export interface BootstrapParams {
}
export interface QueryComponentParams extends BootstrapParams {
export interface IQueryComponentParams extends IBootstrapParams {
dataService: DataService;
}
export interface EditDataComponentParams extends BootstrapParams {
export interface IEditDataComponentParams extends IBootstrapParams {
dataService: DataService;
}
export interface DefaultComponentParams extends BootstrapParams {
export interface IDefaultComponentParams extends IBootstrapParams {
connection: IConnectionProfile;
ownerUri: string;
scopedContextService: IContextKeyService;
connectionContextKey: ConnectionContextkey;
}
export interface DashboardComponentParams extends DefaultComponentParams {
export interface IDashboardComponentParams extends IDefaultComponentParams {
}
export interface TaskDialogComponentParams extends BootstrapParams {
export interface ITaskDialogComponentParams extends IBootstrapParams {
ownerUri: string;
}
export interface QueryPlanParams extends BootstrapParams {
export interface IQueryPlanParams extends IBootstrapParams {
planXml: string;
}

View File

@@ -3,20 +3,21 @@
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { NgModuleRef, InjectionToken } from '@angular/core';
import { BootstrapParams } from 'sql/services/bootstrap/bootstrapParams';
import { NgModuleRef, enableProdMode, InjectionToken, ReflectiveInjector, Type, PlatformRef } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { IConnectionManagementService, IConnectionDialogService, IErrorMessageService }
from 'sql/parts/connection/common/connectionManagement';
import { IMetadataService } from 'sql/services/metadata/metadataService';
import { IObjectExplorerService } from 'sql/parts/objectExplorer/common/objectExplorerService';
import { IQueryEditorService } from 'sql/parts/query/common/queryEditorService';
import { IAngularEventingService } from 'sql/services/angularEventing/angularEventingService';
import { IScriptingService } from 'sql/services/scripting/scriptingService';
import { IQueryModelService } from 'sql/parts/query/execution/queryModel';
import { IQueryManagementService } from 'sql/parts/query/common/queryManagement';
import { IQueryModelService } from 'sql/parts/query/execution/queryModel';
import { IAdminService } from 'sql/parts/admin/common/adminService';
import { IRestoreDialogController, IRestoreService } from 'sql/parts/disasterRecovery/restore/common/restoreService';
import { IBackupService, IBackupUiService } from 'sql/parts/disasterRecovery/backup/common/backupService';
import { IAngularEventingService } from 'sql/services/angularEventing/angularEventingService';
import { IInsightsDialogService } from 'sql/parts/insights/common/interfaces';
import { ISqlOAuthService } from 'sql/common/sqlOAuthService';
import { IFileBrowserService, IFileBrowserDialogController } from 'sql/parts/fileBrowser/common/interfaces';
@@ -24,105 +25,122 @@ import { IClipboardService } from 'sql/platform/clipboard/common/clipboardServic
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
import { IDashboardViewService } from 'sql/services/dashboard/common/dashboardViewService';
import { IModelViewService } from 'sql/services/modelComponents/modelViewService';
import { IJobManagementService } from 'sql/parts/jobManagement/common/interfaces';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IEditorInput } from 'vs/platform/editor/common/editor';
import { createDecorator, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { IEditorInput } from 'vs/platform/editor/common/editor';
import { IInstantiationService, ServicesAccessor, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IAccountManagementService } from 'sql/services/accountManagement/interfaces';
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ConfigurationEditingService } from 'vs/workbench/services/configuration/node/configurationEditingService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IJobManagementService } from 'sql/parts/jobManagement/common/interfaces';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IClipboardService as vsIClipboardService } from 'vs/platform/clipboard/common/clipboardService';
export const BOOTSTRAP_SERVICE_ID = 'bootstrapService';
export const IBootstrapService = createDecorator<IBootstrapService>(BOOTSTRAP_SERVICE_ID);
const selectorCounter = new Map<string, number>();
/*
* Handles logic for bootstrapping and passing singleton services to Angular components.
*/
export interface IBootstrapService {
_serviceBrand: any;
connectionManagementService: IConnectionManagementService;
metadataService: IMetadataService;
objectExplorerService: IObjectExplorerService;
scriptingService: IScriptingService;
queryEditorService: IQueryEditorService;
connectionDialogService: IConnectionDialogService;
queryModelService: IQueryModelService;
adminService: IAdminService;
backupService: IBackupService;
backupUiService: IBackupUiService;
restoreService: IRestoreService;
keybindingService: IKeybindingService;
contextKeyService: IContextKeyService;
contextMenuService: IContextMenuService;
themeService: IWorkbenchThemeService;
editorService: IWorkbenchEditorService;
errorMessageService: IErrorMessageService;
partService: IPartService;
queryManagementService: IQueryManagementService;
instantiationService: IInstantiationService;
angularEventingService: IAngularEventingService;
configurationService: IConfigurationService;
insightsDialogService: IInsightsDialogService;
contextViewService: IContextViewService;
restoreDialogService: IRestoreDialogController;
notificationService: INotificationService;
workspaceContextService: IWorkspaceContextService;
accountManagementService: IAccountManagementService;
windowsService: IWindowsService;
sqlOAuthService: ISqlOAuthService;
windowService: IWindowService;
fileBrowserService: IFileBrowserService;
fileBrowserDialogService: IFileBrowserDialogController;
telemetryService: ITelemetryService;
storageService: IStorageService;
clipboardService: IClipboardService;
capabilitiesService: ICapabilitiesService;
configurationEditorService: ConfigurationEditingService;
commandService: ICommandService;
dashboardViewService: IDashboardViewService;
modelViewService: IModelViewService;
jobManagementService: IJobManagementService;
environmentService: IEnvironmentService;
/*
* Bootstraps the Angular module described. Components that need singleton services should inject the
* 'BootstrapService' dependency to obtain a reference to this class. Components that need dynamic parameters
* should wrap them in an object and pass them in through the "params" parameter.
*
* moduleType: The TypeScript type of the module to bootstrap
* container: The HTML container to append the selector HTMLElement
* selectorString: The tag name and class used to create the element, e.g. 'tagName.cssClassName'
* params: The parameters to be associated with the given id
* input: Optional editor input. If specified, will listen to its onDispose event and destroy the module when this happens
* callbackSetModule:Optional. If specified, will be used to set the moduleRef
* Returns the unique selector string that this module will bootstrap with.
*/
bootstrap(moduleType: any, container: HTMLElement, selectorString: string, params: BootstrapParams, input?: IEditorInput, callbackSetModule?: (value: NgModuleRef<{}>) => void): string;
/*
* Gets the "params" entry associated with the given id and unassociates the id/entry pair.
* Returns undefined if no entry is found.
*/
getBootstrapParams<T extends BootstrapParams>(id: string): T;
/*
* Gets the next unique selector given the baseSelectorString. A unique selector is the baseSelectorString with a
* number appended. E.g. if baseSelectorString='query', valid unique selectors could be query0, query1, query2, etc.
*/
getUniqueSelector(baseSelectorString: string): string;
export const IBootstrapParams = new InjectionToken('bootstrap_params');
export interface IBootstrapParams {
}
export type IModuleFactory<T> = (params: IBootstrapParams, selector: string) => Type<T>;
function createUniqueSelector(selector: string): string {
let num: number;
if (selectorCounter.has(selector)) {
num = selectorCounter.get(selector);
} else {
num = 0;
}
selectorCounter.set(selector, num + 1);
return `${selector}_${num}`;
}
let platform: PlatformRef;
export function bootstrapAngular<T>(collection: ServicesAccessor, moduleType: IModuleFactory<T>, container: HTMLElement, selectorString: string, params: IBootstrapParams, input?: IEditorInput, callbackSetModule?: (value: NgModuleRef<T>) => void): string {
// Create the uniqueSelectorString
let uniqueSelectorString = createUniqueSelector(selectorString);
let selector = document.createElement(uniqueSelectorString);
container.appendChild(selector);
if (!platform) {
// Perform the bootsrap
const providers: { provide: ServiceIdentifier<any> | InjectionToken<any>, useValue: any }[] = [
// sql services
{ provide: IConnectionManagementService, useValue: collection.get(IConnectionManagementService) },
{ provide: IConnectionDialogService, useValue: collection.get(IConnectionDialogService) },
{ provide: IErrorMessageService, useValue: collection.get(IErrorMessageService) },
{ provide: IMetadataService, useValue: collection.get(IMetadataService) },
{ provide: IObjectExplorerService, useValue: collection.get(IObjectExplorerService) },
{ provide: IQueryEditorService, useValue: collection.get(IQueryEditorService) },
{ provide: IScriptingService, useValue: collection.get(IScriptingService) },
{ provide: IQueryManagementService, useValue: collection.get(IQueryManagementService) },
{ provide: IQueryModelService, useValue: collection.get(IQueryModelService) },
{ provide: IAdminService, useValue: collection.get(IAdminService) },
{ provide: IRestoreDialogController, useValue: collection.get(IRestoreDialogController) },
{ provide: IRestoreService, useValue: collection.get(IRestoreService) },
{ provide: IBackupService, useValue: collection.get(IBackupService) },
{ provide: IBackupUiService, useValue: collection.get(IBackupUiService) },
{ provide: IAngularEventingService, useValue: collection.get(IAngularEventingService) },
{ provide: IInsightsDialogService, useValue: collection.get(IInsightsDialogService) },
{ provide: ISqlOAuthService, useValue: collection.get(ISqlOAuthService) },
{ provide: IFileBrowserService, useValue: collection.get(IFileBrowserService) },
{ provide: IFileBrowserDialogController, useValue: collection.get(IFileBrowserDialogController) },
{ provide: IClipboardService, useValue: collection.get(IClipboardService) },
{ provide: ICapabilitiesService, useValue: collection.get(ICapabilitiesService) },
{ provide: IDashboardViewService, useValue: collection.get(IDashboardViewService) },
{ provide: IModelViewService, useValue: collection.get(IModelViewService) },
// vscode services
{ provide: vsIClipboardService, useValue: collection.get(vsIClipboardService) },
{ provide: IKeybindingService, useValue: collection.get(IKeybindingService) },
{ provide: IContextKeyService, useValue: collection.get(IContextKeyService) },
{ provide: IContextMenuService, useValue: collection.get(IContextMenuService) },
{ provide: IContextViewService, useValue: collection.get(IContextViewService) },
{ provide: IWorkbenchEditorService, useValue: collection.get(IWorkbenchEditorService) },
{ provide: IPartService, useValue: collection.get(IPartService) },
{ provide: IInstantiationService, useValue: collection.get(IInstantiationService) },
{ provide: IConfigurationService, useValue: collection.get(IConfigurationService) },
{ provide: IWorkspaceContextService, useValue: collection.get(IWorkspaceContextService) },
{ provide: IAccountManagementService, useValue: collection.get(IAccountManagementService) },
{ provide: IWindowsService, useValue: collection.get(IWindowsService) },
{ provide: IWindowService, useValue: collection.get(IWindowService) },
{ provide: ITelemetryService, useValue: collection.get(ITelemetryService) },
{ provide: IStorageService, useValue: collection.get(IStorageService) },
{ provide: ICommandService, useValue: collection.get(ICommandService) },
{ provide: IJobManagementService, useValue: collection.get(IJobManagementService) },
{ provide: IEnvironmentService, useValue: collection.get(IEnvironmentService) },
{ provide: INotificationService, useValue: collection.get(INotificationService) },
{ provide: IWorkbenchThemeService, useValue: collection.get(IWorkbenchThemeService) }
];
platform = platformBrowserDynamic(providers);
}
platform.bootstrapModule(moduleType(params, uniqueSelectorString)).then(moduleRef => {
if (input) {
input.onDispose(() => {
moduleRef.destroy();
});
}
if (callbackSetModule) {
callbackSetModule(moduleRef);
}
});
return uniqueSelectorString;
}
if (!process.env['VSCODE_DEV']) {
enableProdMode();
}

View File

@@ -1,199 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the Source EULA. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { NgModuleRef, enableProdMode } from '@angular/core';
import { platformBrowserDynamic, } from '@angular/platform-browser-dynamic';
import { BootstrapParams } from 'sql/services/bootstrap/bootstrapParams';
import { IConnectionManagementService, IConnectionDialogService, IErrorMessageService }
from 'sql/parts/connection/common/connectionManagement';
import { IMetadataService } from 'sql/services/metadata/metadataService';
import { IObjectExplorerService } from 'sql/parts/objectExplorer/common/objectExplorerService';
import { IQueryEditorService } from 'sql/parts/query/common/queryEditorService';
import { IScriptingService } from 'sql/services/scripting/scriptingService';
import { IQueryManagementService } from 'sql/parts/query/common/queryManagement';
import { IQueryModelService } from 'sql/parts/query/execution/queryModel';
import { IAdminService } from 'sql/parts/admin/common/adminService';
import { IRestoreDialogController, IRestoreService } from 'sql/parts/disasterRecovery/restore/common/restoreService';
import { IBackupService, IBackupUiService } from 'sql/parts/disasterRecovery/backup/common/backupService';
import { IAngularEventingService } from 'sql/services/angularEventing/angularEventingService';
import { IInsightsDialogService } from 'sql/parts/insights/common/interfaces';
import { ISqlOAuthService } from 'sql/common/sqlOAuthService';
import { IFileBrowserService, IFileBrowserDialogController } from 'sql/parts/fileBrowser/common/interfaces';
import { IClipboardService } from 'sql/platform/clipboard/common/clipboardService';
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
import { IDashboardViewService } from 'sql/services/dashboard/common/dashboardViewService';
import { IModelViewService } from 'sql/services/modelComponents/modelViewService';
import { $ } from 'vs/base/browser/dom';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { IEditorInput } from 'vs/platform/editor/common/editor';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from './bootstrapService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IAccountManagementService } from 'sql/services/accountManagement/interfaces';
import { IWindowsService, IWindowService } from 'vs/platform/windows/common/windows';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IStorageService } from 'vs/platform/storage/common/storage';
import { ConfigurationEditingService } from 'vs/workbench/services/configuration/node/configurationEditingService';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IJobManagementService } from 'sql/parts/jobManagement/common/interfaces';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INotificationService } from 'vs/platform/notification/common/notification';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
export class BootstrapService implements IBootstrapService {
public _serviceBrand: any;
// Maps uniqueSelectors (as opposed to selectors) to BootstrapParams
private _bootstrapParameterMap: Map<string, BootstrapParams>;
// Maps selectors (as opposed to uniqueSelectors) to a queue of uniqueSelectors
private _selectorQueueMap: Map<string, string[]>;
// Maps selectors (as opposed to uniqueSelectors) to the next available uniqueSelector ID number
private _selectorCountMap: Map<string, number>;
public configurationEditorService: ConfigurationEditingService;
constructor(
@IConnectionManagementService public connectionManagementService: IConnectionManagementService,
@IMetadataService public metadataService: IMetadataService,
@IObjectExplorerService public objectExplorerService: IObjectExplorerService,
@IScriptingService public scriptingService: IScriptingService,
@IQueryEditorService public queryEditorService: IQueryEditorService,
@IAdminService public adminService: IAdminService,
@IWorkbenchThemeService public themeService: IWorkbenchThemeService,
@IWorkbenchEditorService public editorService: IWorkbenchEditorService,
@IBackupService public backupService: IBackupService,
@IBackupUiService public backupUiService: IBackupUiService,
@IRestoreDialogController public restoreDialogService: IRestoreDialogController,
@IRestoreService public restoreService: IRestoreService,
@IConnectionDialogService public connectionDialogService: IConnectionDialogService,
@IQueryModelService public queryModelService: IQueryModelService,
@IKeybindingService public keybindingService: IKeybindingService,
@IContextKeyService public contextKeyService: IContextKeyService,
@IContextMenuService public contextMenuService: IContextMenuService,
@IErrorMessageService public errorMessageService: IErrorMessageService,
@IPartService public partService: IPartService,
@IQueryManagementService public queryManagementService: IQueryManagementService,
@IInstantiationService public instantiationService: IInstantiationService,
@IAngularEventingService public angularEventingService: IAngularEventingService,
@IConfigurationService public configurationService: IConfigurationService,
@IInsightsDialogService public insightsDialogService: IInsightsDialogService,
@IContextViewService public contextViewService: IContextViewService,
@INotificationService public notificationService: INotificationService,
@IWorkspaceContextService public workspaceContextService: IWorkspaceContextService,
@IAccountManagementService public accountManagementService: IAccountManagementService,
@IWindowsService public windowsService: IWindowsService,
@ISqlOAuthService public sqlOAuthService: ISqlOAuthService,
@IFileBrowserService public fileBrowserService: IFileBrowserService,
@IFileBrowserDialogController public fileBrowserDialogService: IFileBrowserDialogController,
@IWindowService public windowService: IWindowService,
@ITelemetryService public telemetryService: ITelemetryService,
@IStorageService public storageService: IStorageService,
@IClipboardService public clipboardService: IClipboardService,
@ICapabilitiesService public capabilitiesService: ICapabilitiesService,
@ICommandService public commandService: ICommandService,
@IDashboardViewService public dashboardViewService: IDashboardViewService,
@IModelViewService public modelViewService: IModelViewService,
@IJobManagementService public jobManagementService: IJobManagementService,
@IEnvironmentService public environmentService: IEnvironmentService
) {
this.configurationEditorService = this.instantiationService.createInstance(ConfigurationEditingService);
this._bootstrapParameterMap = new Map<string, BootstrapParams>();
this._selectorQueueMap = new Map<string, string[]>();
this._selectorCountMap = new Map<string, number>();
}
public bootstrap(moduleType: any, container: HTMLElement, selectorString: string, params: BootstrapParams, input?: IEditorInput, callbackSetModule?: (value: NgModuleRef<{}>) => void): string {
// Create the uniqueSelectorString
let uniqueSelectorString: string = this._getUniqueSelectorString(selectorString);
let selector: HTMLElement = $(uniqueSelectorString);
container.appendChild(selector);
// Associate the elementId
this._setUniqueSelector(selectorString, uniqueSelectorString);
// Associate the params
this._bootstrapParameterMap.set(uniqueSelectorString, params);
// Perform the bootsrap
let providers = [
{ provide: BOOTSTRAP_SERVICE_ID, useValue: this },
{ provide: IWorkbenchThemeService, useValue: this.themeService },
{ provide: IContextViewService, useValue: this.contextViewService }
];
platformBrowserDynamic(providers).bootstrapModule(moduleType).then(moduleRef => {
if (input) {
input.onDispose(() => {
moduleRef.destroy();
});
}
if (callbackSetModule) {
callbackSetModule(moduleRef);
}
});
return uniqueSelectorString;
}
public getBootstrapParams(id: string): any {
let idLowercase = id.toLowerCase();
let params: BootstrapParams = this._bootstrapParameterMap.get(idLowercase);
this._bootstrapParameterMap.delete(idLowercase);
return params;
}
public getUniqueSelector(selectorString: string): string {
let idArray = this._selectorQueueMap.get(selectorString);
if (!idArray) {
return undefined;
}
let id: string = idArray.shift();
if (idArray.length === 0) {
this._selectorQueueMap.delete(selectorString);
} else {
this._selectorQueueMap.set(selectorString, idArray);
}
return id;
}
private _getUniqueSelectorString(selectorString: string): string {
let count: number = this._selectorCountMap.get(selectorString);
if (!count) {
this._selectorCountMap.set(selectorString, 1);
count = 0;
} else {
this._selectorCountMap.set(selectorString, count + 1);
}
let casedString = selectorString + count.toString();
return casedString.toLowerCase();
}
private _setUniqueSelector(selectorString: string, elementId: string) {
let idArray = this._selectorQueueMap.get(selectorString);
if (!idArray) {
idArray = [];
}
idArray.push(elementId);
this._selectorQueueMap.set(selectorString, idArray);
}
}
if (!process.env['VSCODE_DEV']) {
enableProdMode();
}

View File

@@ -5,46 +5,24 @@
/* Node Modules */
import { Injectable, Inject, forwardRef, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
/* SQL imports */
import { DefaultComponentParams } from 'sql/services/bootstrap/bootstrapParams';
import { IBootstrapService, BOOTSTRAP_SERVICE_ID } from 'sql/services/bootstrap/bootstrapService';
import { IDefaultComponentParams } from 'sql/services/bootstrap/bootstrapParams';
import { IBootstrapParams } from 'sql/services/bootstrap/bootstrapService';
import { IMetadataService } from 'sql/services/metadata/metadataService';
import { IConnectionManagementService } from 'sql/parts/connection/common/connectionManagement';
import { ConnectionManagementInfo } from 'sql/parts/connection/common/connectionManagementInfo';
import { IAdminService } from 'sql/parts/admin/common/adminService';
import { IQueryManagementService } from 'sql/parts/query/common/queryManagement';
import { toDisposableSubscription } from 'sql/parts/common/rxjsUtils';
import { IInsightsDialogService } from 'sql/parts/insights/common/interfaces';
import { ICapabilitiesService } from 'sql/services/capabilities/capabilitiesService';
import { IConnectionProfile } from 'sql/parts/connection/common/interfaces';
import { AngularEventType, IAngularEvent, IAngularEventingService } from 'sql/services/angularEventing/angularEventingService';
import { IModelViewService } from 'sql/services/modelComponents/modelViewService';
import { AngularDisposable } from 'sql/base/common/lifecycle';
import { ConnectionContextkey } from 'sql/parts/connection/common/connectionContextKey';
import { ProviderMetadata, DatabaseInfo, SimpleExecuteResult } from 'sqlops';
/* VS imports */
import { IWorkbenchThemeService } from 'vs/workbench/services/themes/common/workbenchThemeService';
import { IContextMenuService, IContextViewService } from 'vs/platform/contextview/browser/contextView';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IDisposable } from 'vs/base/common/lifecycle';
import { IConfigurationService, ConfigurationTarget } from 'vs/platform/configuration/common/configuration';
import { ConfigurationEditingService, IConfigurationValue } from 'vs/workbench/services/configuration/node/configurationEditingService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IStorageService } from 'vs/platform/storage/common/storage';
import Event, { Emitter } from 'vs/base/common/event';
import Severity from 'vs/base/common/severity';
import * as nls from 'vs/nls';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { deepClone } from 'vs/base/common/objects';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IContextKeyService, RawContextKey, IContextKey } from 'vs/platform/contextkey/common/contextkey';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { INotificationService } from 'vs/platform/notification/common/notification';
/* Wrapper for a metadata service that contains the uri string to use on each request */
export class SingleConnectionMetadataService {
@@ -119,115 +97,40 @@ export class SingleQueryManagementService {
export class CommonServiceInterface extends AngularDisposable {
protected _uniqueSelector: string;
protected _uri: string;
protected _bootstrapParams: DefaultComponentParams;
/* Static Services */
protected _themeService = this._bootstrapService.themeService;
protected _contextMenuService = this._bootstrapService.contextMenuService;
protected _instantiationService = this._bootstrapService.instantiationService;
protected _configService = this._bootstrapService.configurationService;
protected _insightsDialogService = this._bootstrapService.insightsDialogService;
protected _contextViewService = this._bootstrapService.contextViewService;
protected _notificationService = this._bootstrapService.notificationService;
protected _workspaceContextService = this._bootstrapService.workspaceContextService;
protected _storageService = this._bootstrapService.storageService;
protected _capabilitiesService = this._bootstrapService.capabilitiesService;
protected _configurationEditingService = this._bootstrapService.configurationEditorService;
protected _commandService = this._bootstrapService.commandService;
protected _modelViewService = this._bootstrapService.modelViewService;
protected _partService = this._bootstrapService.partService;
protected _angularEventingService = this._bootstrapService.angularEventingService;
protected _environmentService = this._bootstrapService.environmentService;
/* Special Services */
protected _metadataService: SingleConnectionMetadataService;
protected _connectionManagementService: SingleConnectionManagementService;
protected _adminService: SingleAdminService;
protected _queryManagementService: SingleQueryManagementService;
protected _contextKeyService: IContextKeyService;
protected _singleMetadataService: SingleConnectionMetadataService;
protected _singleConnectionManagementService: SingleConnectionManagementService;
protected _singleAdminService: SingleAdminService;
protected _singleQueryManagementService: SingleQueryManagementService;
public scopedContextKeyService: IContextKeyService;
protected _connectionContextKey: ConnectionContextkey;
constructor(
@Inject(BOOTSTRAP_SERVICE_ID) protected _bootstrapService: IBootstrapService
@Inject(IBootstrapParams) protected _params: IDefaultComponentParams,
@Inject(IMetadataService) protected _metadataService: IMetadataService,
@Inject(IConnectionManagementService) protected _connectionManagementService: IConnectionManagementService,
@Inject(IAdminService) protected _adminService: IAdminService,
@Inject(IQueryManagementService) protected _queryManagementService: IQueryManagementService
) {
super();
}
public get notificationService(): INotificationService {
return this._notificationService;
}
public get configurationEditingService(): ConfigurationEditingService {
return this._configurationEditingService;
}
public get metadataService(): SingleConnectionMetadataService {
return this._metadataService;
return this._singleMetadataService;
}
public get connectionManagementService(): SingleConnectionManagementService {
return this._connectionManagementService;
}
public get commandService(): ICommandService {
return this._commandService;
}
public get themeService(): IWorkbenchThemeService {
return this._themeService;
}
public get contextMenuService(): IContextMenuService {
return this._contextMenuService;
}
public get instantiationService(): IInstantiationService {
return this._instantiationService;
}
public get modelViewService(): IModelViewService {
return this._modelViewService;
}
public get partService(): IPartService {
return this._partService;
}
public get contextKeyService(): IContextKeyService {
return this._contextKeyService;
return this._singleConnectionManagementService;
}
public get adminService(): SingleAdminService {
return this._adminService;
return this._singleAdminService;
}
public get queryManagementService(): SingleQueryManagementService {
return this._queryManagementService;
}
public get environmentService(): IEnvironmentService {
return this._environmentService;
}
public get contextViewService(): IContextViewService {
return this._contextViewService;
}
public get workspaceContextService(): IWorkspaceContextService {
return this._workspaceContextService;
}
public get storageService(): IStorageService {
return this._storageService;
}
public get capabilitiesService(): ICapabilitiesService {
return this._capabilitiesService;
}
public get angularEventingService(): IAngularEventingService {
return this._angularEventingService;
return this._singleQueryManagementService;
}
/**
@@ -239,18 +142,17 @@ export class CommonServiceInterface extends AngularDisposable {
}
protected _getbootstrapParams(): void {
this._bootstrapParams = this._bootstrapService.getBootstrapParams<DefaultComponentParams>(this._uniqueSelector);
this._contextKeyService = this._bootstrapParams.scopedContextService;
this._connectionContextKey = this._bootstrapParams.connectionContextKey;
this.uri = this._bootstrapParams.ownerUri;
this.scopedContextKeyService = this._params.scopedContextService;
this._connectionContextKey = this._params.connectionContextKey;
this.uri = this._params.ownerUri;
}
protected setUri(uri: string) {
this._uri = uri;
this._metadataService = new SingleConnectionMetadataService(this._bootstrapService.metadataService, this._uri);
this._connectionManagementService = new SingleConnectionManagementService(this._bootstrapService.connectionManagementService, this._uri, this._connectionContextKey);
this._adminService = new SingleAdminService(this._bootstrapService.adminService, this._uri);
this._queryManagementService = new SingleQueryManagementService(this._bootstrapService.queryManagementService, this._uri);
this._singleMetadataService = new SingleConnectionMetadataService(this._metadataService, this._uri);
this._singleConnectionManagementService = new SingleConnectionManagementService(this._connectionManagementService, this._uri, this._connectionContextKey);
this._singleAdminService = new SingleAdminService(this._adminService, this._uri);
this._singleQueryManagementService = new SingleQueryManagementService(this._queryManagementService, this._uri);
}
/**
@@ -274,6 +176,6 @@ export class CommonServiceInterface extends AngularDisposable {
}
public getOriginalConnectionProfile(): IConnectionProfile {
return this._bootstrapParams.connection;
return this._params.connection;
}
}