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:
65
src/sql/platform/backup/common/backupService.ts
Normal file
65
src/sql/platform/backup/common/backupService.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
import * as sqlops from 'sqlops';
|
||||
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
|
||||
export enum TaskExecutionMode {
|
||||
execute = 0,
|
||||
script = 1,
|
||||
executeAndScript = 2,
|
||||
}
|
||||
|
||||
export const SERVICE_ID = 'backupService';
|
||||
export const UI_SERVICE_ID = 'backupUiService';
|
||||
|
||||
export const IBackupUiService = createDecorator<IBackupUiService>(UI_SERVICE_ID);
|
||||
|
||||
export interface IBackupUiService {
|
||||
_serviceBrand: any;
|
||||
|
||||
/**
|
||||
* Show backup wizard
|
||||
*/
|
||||
showBackup(connection: IConnectionProfile): Promise<any>;
|
||||
|
||||
/**
|
||||
* On show backup event
|
||||
*/
|
||||
onShowBackupEvent: Event<{ connection: IConnectionProfile, ownerUri: string }>;
|
||||
|
||||
/**
|
||||
* Close backup wizard
|
||||
*/
|
||||
closeBackup();
|
||||
|
||||
/**
|
||||
* After the backup dialog is rendered, run Modal methods to set focusable elements, etc.
|
||||
*/
|
||||
onShowBackupDialog();
|
||||
}
|
||||
|
||||
export const IBackupService = createDecorator<IBackupService>(SERVICE_ID);
|
||||
|
||||
export interface IBackupService {
|
||||
_serviceBrand: any;
|
||||
|
||||
getBackupConfigInfo(connectionUri: string): Thenable<sqlops.BackupConfigInfo>;
|
||||
|
||||
/**
|
||||
* Backup a data source using the provided connection
|
||||
*/
|
||||
backup(connectionUri: string, backupInfo: { [key: string]: any }, taskExecutionMode: sqlops.TaskExecutionMode): Thenable<sqlops.BackupResponse>;
|
||||
|
||||
/**
|
||||
* Register a disaster recovery provider
|
||||
*/
|
||||
registerProvider(providerId: string, provider: sqlops.BackupProvider): void;
|
||||
}
|
||||
74
src/sql/platform/backup/common/backupServiceImp.ts
Normal file
74
src/sql/platform/backup/common/backupServiceImp.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import * as sqlops from 'sqlops';
|
||||
import * as Constants from 'sql/common/constants';
|
||||
import * as TelemetryKeys from 'sql/common/telemetryKeys';
|
||||
import * as TelemetryUtils from 'sql/common/telemetryUtilities';
|
||||
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
|
||||
import { IBackupService, TaskExecutionMode } from 'sql/platform/backup/common/backupService';
|
||||
|
||||
export class BackupService implements IBackupService {
|
||||
|
||||
public _serviceBrand: any;
|
||||
private _providers: { [handle: string]: sqlops.BackupProvider; } = Object.create(null);
|
||||
|
||||
constructor(
|
||||
@IConnectionManagementService private _connectionService: IConnectionManagementService,
|
||||
@ITelemetryService private _telemetryService: ITelemetryService
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get database metadata needed to populate backup UI
|
||||
*/
|
||||
public getBackupConfigInfo(connectionUri: string): Thenable<sqlops.BackupConfigInfo> {
|
||||
let providerId: string = this._connectionService.getProviderIdFromUri(connectionUri);
|
||||
if (providerId) {
|
||||
let provider = this._providers[providerId];
|
||||
if (provider) {
|
||||
return provider.getBackupConfigInfo(connectionUri);
|
||||
}
|
||||
}
|
||||
return Promise.resolve(undefined);
|
||||
}
|
||||
|
||||
/**
|
||||
* Backup a data source using the provided connection
|
||||
*/
|
||||
public backup(connectionUri: string, backupInfo: { [key: string]: any }, taskExecutionMode: TaskExecutionMode): Thenable<sqlops.BackupResponse> {
|
||||
return new Promise<sqlops.BackupResponse>((resolve, reject) => {
|
||||
let providerResult = this.getProvider(connectionUri);
|
||||
if (providerResult) {
|
||||
TelemetryUtils.addTelemetry(this._telemetryService, TelemetryKeys.BackupCreated, { provider: providerResult.providerName });
|
||||
providerResult.provider.backup(connectionUri, backupInfo, taskExecutionMode).then(result => {
|
||||
resolve(result);
|
||||
}, error => {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
reject(Constants.InvalidProvider);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private getProvider(connectionUri: string): { provider: sqlops.BackupProvider, providerName: string } {
|
||||
let providerId: string = this._connectionService.getProviderIdFromUri(connectionUri);
|
||||
if (providerId) {
|
||||
return { provider: this._providers[providerId], providerName: providerId };
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a disaster recovery provider
|
||||
*/
|
||||
public registerProvider(providerId: string, provider: sqlops.BackupProvider): void {
|
||||
this._providers[providerId] = provider;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user