mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-17 09:35:37 -05:00
Initial Code Layering (#3788)
* working on formatting * fixed basic lint errors; starting moving things to their appropriate location * formatting * update tslint to match the version of vscode we have * remove unused code * work in progress fixing layering * formatting * moved connection management service to platform * formatting * add missing file * moving more servies * formatting * moving more services * formatting * wip * moving more services * formatting * revert back tslint rules * move css file * add missing svgs
This commit is contained in:
129
src/sql/workbench/services/admin/common/adminService.ts
Normal file
129
src/sql/workbench/services/admin/common/adminService.ts
Normal file
@@ -0,0 +1,129 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { localize } from 'vs/nls';
|
||||
|
||||
export const SERVICE_ID = 'adminService';
|
||||
|
||||
import { IInstantiationService, createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { CreateLoginInput } from 'sql/parts/admin/security/createLoginInput';
|
||||
import { TaskDialogInput } from 'sql/parts/tasks/dialog/taskDialogInput';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IEditorService, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
|
||||
import * as sqlops from 'sqlops';
|
||||
|
||||
export const IAdminService = createDecorator<IAdminService>(SERVICE_ID);
|
||||
|
||||
export interface IAdminService {
|
||||
_serviceBrand: any;
|
||||
|
||||
registerProvider(providerId: string, provider: sqlops.AdminServicesProvider): void;
|
||||
|
||||
showCreateDatabaseWizard(uri: string, connection: IConnectionProfile): Promise<any>;
|
||||
|
||||
showCreateLoginWizard(uri: string, connection: IConnectionProfile): Promise<any>;
|
||||
|
||||
createDatabase(connectionUri: string, database: sqlops.DatabaseInfo): Thenable<sqlops.CreateDatabaseResponse>;
|
||||
|
||||
getDefaultDatabaseInfo(connectionUri: string): Thenable<sqlops.DatabaseInfo>;
|
||||
|
||||
getDatabaseInfo(connectionUri: string): Thenable<sqlops.DatabaseInfo>;
|
||||
}
|
||||
|
||||
export class AdminService implements IAdminService {
|
||||
_serviceBrand: any;
|
||||
|
||||
private _providers: { [handle: string]: sqlops.AdminServicesProvider; } = Object.create(null);
|
||||
|
||||
constructor(
|
||||
@IInstantiationService private _instantiationService: IInstantiationService,
|
||||
@IEditorService private _editorService: IEditorService,
|
||||
@IConnectionManagementService private _connectionService: IConnectionManagementService
|
||||
) {
|
||||
}
|
||||
|
||||
private _runAction<T>(uri: string, action: (handler: sqlops.AdminServicesProvider) => Thenable<T>): Thenable<T> {
|
||||
let providerId: string = this._connectionService.getProviderIdFromUri(uri);
|
||||
|
||||
if (!providerId) {
|
||||
return TPromise.wrapError(new Error(localize('adminService.providerIdNotValidError', 'Connection is required in order to interact with adminservice')));
|
||||
}
|
||||
let handler = this._providers[providerId];
|
||||
if (handler) {
|
||||
return action(handler);
|
||||
} else {
|
||||
return TPromise.wrapError(new Error(localize('adminService.noHandlerRegistered', 'No Handler Registered')));
|
||||
}
|
||||
}
|
||||
|
||||
public showCreateDatabaseWizard(uri: string, connection: IConnectionProfile): Promise<any> {
|
||||
const self = this;
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
let input: TaskDialogInput = self._instantiationService ? self._instantiationService.createInstance(TaskDialogInput, uri, connection) : undefined;
|
||||
self._editorService.openEditor(input, { pinned: true }, ACTIVE_GROUP);
|
||||
resolve(true);
|
||||
});
|
||||
}
|
||||
|
||||
public createDatabase(connectionUri: string, database: sqlops.DatabaseInfo): Thenable<sqlops.CreateDatabaseResponse> {
|
||||
let providerId: string = this._connectionService.getProviderIdFromUri(connectionUri);
|
||||
if (providerId) {
|
||||
let provider = this._providers[providerId];
|
||||
if (provider) {
|
||||
return provider.createDatabase(connectionUri, database);
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
public showCreateLoginWizard(uri: string, connection: IConnectionProfile): Promise<any> {
|
||||
const self = this;
|
||||
self.createLogin(uri, { name: 'TEST: login name' });
|
||||
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
let loginInput: CreateLoginInput = self._instantiationService ? self._instantiationService.createInstance(CreateLoginInput, uri, connection) : undefined;
|
||||
self._editorService.openEditor(loginInput, { pinned: true }, ACTIVE_GROUP);
|
||||
resolve(true);
|
||||
});
|
||||
}
|
||||
|
||||
public createLogin(connectionUri: string, login: sqlops.LoginInfo): Thenable<sqlops.CreateLoginResponse> {
|
||||
let providerId: string = this._connectionService.getProviderIdFromUri(connectionUri);
|
||||
if (providerId) {
|
||||
let provider = this._providers[providerId];
|
||||
if (provider) {
|
||||
return provider.createLogin(connectionUri, login);
|
||||
}
|
||||
}
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
public getDefaultDatabaseInfo(connectionUri: string): Thenable<sqlops.DatabaseInfo> {
|
||||
let providerId: string = this._connectionService.getProviderIdFromUri(connectionUri);
|
||||
if (providerId) {
|
||||
let provider = this._providers[providerId];
|
||||
if (provider) {
|
||||
return provider.getDefaultDatabaseInfo(connectionUri);
|
||||
}
|
||||
}
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
public getDatabaseInfo(connectionUri: string): Thenable<sqlops.DatabaseInfo> {
|
||||
return this._runAction(connectionUri, (runner) => {
|
||||
return runner.getDatabaseInfo(connectionUri);
|
||||
});
|
||||
}
|
||||
|
||||
public registerProvider(providerId: string, provider: sqlops.AdminServicesProvider): void {
|
||||
this._providers[providerId] = provider;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user