adding task integration with wizard and dialog framework (#1929)

* adding task integration with wizard and dialog framework
This commit is contained in:
Leila Lali
2018-07-18 16:28:36 -07:00
committed by GitHub
parent e026ab85a7
commit 6680be6a73
20 changed files with 648 additions and 92 deletions

View File

@@ -0,0 +1,113 @@
/*---------------------------------------------------------------------------------------------
* 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 { IMainContext } from 'vs/workbench/api/node/extHost.protocol';
import { ExtHostBackgroundTaskManagementShape, SqlMainContext, MainThreadBackgroundTaskManagementShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
import * as sqlops from 'sqlops';
import * as vscode from 'vscode';
import { Emitter } from 'vs/base/common/event';
import { generateUuid } from 'vs/base/common/uuid';
export enum TaskStatus {
NotStarted = 0,
InProgress = 1,
Succeeded = 2,
SucceededWithWarning = 3,
Failed = 4,
Canceled = 5,
Canceling = 6
}
export class ExtBackgroundOperation implements sqlops.BackgroundOperation {
private readonly _proxy: MainThreadBackgroundTaskManagementShape;
private _onCanceled = new Emitter<void>();
constructor(
private _id: string,
mainContext: IMainContext
) {
this._proxy = mainContext.getProxy(SqlMainContext.MainThreadBackgroundTaskManagement);
}
public updateStatus(status: TaskStatus, message?: string): void {
this._proxy.$updateTask({
message: message,
status: status,
taskId: this.id
});
}
public get onCanceled(): vscode.Event<void> {
return this._onCanceled.event;
}
public cancel(): void {
this._onCanceled.fire();
}
public get id(): string {
return this._id;
}
}
export class ExtHostBackgroundTaskManagement implements ExtHostBackgroundTaskManagementShape {
private readonly _proxy: MainThreadBackgroundTaskManagementShape;
private readonly _handlers = new Map<string, sqlops.BackgroundOperationInfo>();
private readonly _operations = new Map<string, ExtBackgroundOperation>();
private readonly _mainContext: IMainContext;
constructor(
mainContext: IMainContext
) {
this._proxy = mainContext.getProxy(SqlMainContext.MainThreadBackgroundTaskManagement);
this._mainContext = mainContext;
}
$onTaskRegistered(operationId: string): void {
let extOperationInfo = new ExtBackgroundOperation(operationId, this._mainContext);
this._operations.set(operationId, extOperationInfo);
let operationInfo = this._handlers.get(operationId);
if (operationInfo) {
operationInfo.operation(extOperationInfo);
}
}
$onTaskCanceled(operationId: string): void {
let operation = this._operations.get(operationId);
if (operation) {
operation.cancel();
}
}
$registerTask(operationInfo: sqlops.BackgroundOperationInfo): void {
let operationId = operationInfo.operationId || `OperationId${generateUuid()}`;
if (this._handlers.has(operationId)) {
throw new Error(`operation '${operationId}' already exists`);
}
this._handlers.set(operationId, operationInfo);
let taskInfo: sqlops.TaskInfo = {
databaseName: undefined,
serverName: undefined,
description: operationInfo.description,
isCancelable: operationInfo.isCancelable,
name: operationInfo.displayName,
providerName: undefined, //setting provider name will cause the task to be processed by the provider. But this task is created in the extension and needs to be handled
//by the extension
taskExecutionMode: 0,
taskId: operationId,
status: TaskStatus.NotStarted,
connection: operationInfo.connection
};
this._proxy.$registerTask(taskInfo);
}
$removeTask(operationId: string) {
if (this._handlers.has(operationId)) {
this._handlers.delete(operationId);
}
}
}

View File

@@ -8,11 +8,12 @@ import { IMainContext } from 'vs/workbench/api/node/extHost.protocol';
import { Event, Emitter } from 'vs/base/common/event';
import { deepClone } from 'vs/base/common/objects';
import * as nls from 'vs/nls';
import { generateUuid } from 'vs/base/common/uuid';
import * as vscode from 'vscode';
import * as sqlops from 'sqlops';
import { SqlMainContext, ExtHostModelViewDialogShape, MainThreadModelViewDialogShape, ExtHostModelViewShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
import { SqlMainContext, ExtHostModelViewDialogShape, MainThreadModelViewDialogShape, ExtHostModelViewShape, ExtHostBackgroundTaskManagementShape } from 'sql/workbench/api/node/sqlExtHost.protocol';
import { IItemConfig, ModelComponentTypes, IComponentShape } from 'sql/workbench/api/common/sqlExtHostTypes';
const DONE_LABEL = nls.localize('dialogDoneLabel', 'Done');
@@ -95,12 +96,22 @@ class DialogImpl extends ModelViewPanelImpl implements sqlops.window.modelviewdi
public customButtons: sqlops.window.modelviewdialog.Button[];
private _message: sqlops.window.modelviewdialog.DialogMessage;
private _closeValidator: () => boolean | Thenable<boolean>;
private _operationHandler: BackgroundOperationHandler;
constructor(extHostModelViewDialog: ExtHostModelViewDialog,
extHostModelView: ExtHostModelViewShape) {
extHostModelView: ExtHostModelViewShape,
extHostTaskManagement: ExtHostBackgroundTaskManagementShape) {
super('modelViewDialog', extHostModelViewDialog, extHostModelView);
this.okButton = this._extHostModelViewDialog.createButton(DONE_LABEL);
this.cancelButton = this._extHostModelViewDialog.createButton(CANCEL_LABEL);
this._operationHandler = new BackgroundOperationHandler('dialog', extHostTaskManagement);
this.okButton.onClick(() => {
this._operationHandler.createOperation();
});
}
public registerOperation(operationInfo: sqlops.BackgroundOperationInfo): void {
this._operationHandler.registerOperation(operationInfo);
}
public setModelViewId(value: string) {
@@ -192,13 +203,40 @@ class ButtonImpl implements sqlops.window.modelviewdialog.Button {
}
}
class BackgroundOperationHandler {
private _operationInfo: sqlops.BackgroundOperationInfo;
constructor(
private _name: string,
private _extHostTaskManagement: ExtHostBackgroundTaskManagementShape) {
}
public createOperation(): void {
if (!this._operationInfo.operationId) {
let uniqueId = generateUuid();
this._operationInfo.operationId = 'OperationId' + uniqueId + this._name;
}
if (this._operationInfo && this._operationInfo.operation) {
this._extHostTaskManagement.$registerTask(this._operationInfo);
}
}
public registerOperation(operationInfo: sqlops.BackgroundOperationInfo): void {
this._operationInfo = operationInfo;
}
}
class WizardPageImpl extends ModelViewPanelImpl implements sqlops.window.modelviewdialog.WizardPage {
public customButtons: sqlops.window.modelviewdialog.Button[];
private _enabled: boolean = true;
private _description: string;
constructor(public title: string, _extHostModelViewDialog: ExtHostModelViewDialog, _extHostModelView: ExtHostModelViewShape) {
super('modelViewWizardPage', _extHostModelViewDialog, _extHostModelView);
constructor(public title: string,
extHostModelViewDialog: ExtHostModelViewDialog,
extHostModelView: ExtHostModelViewShape) {
super('modelViewWizardPage', extHostModelViewDialog, extHostModelView);
}
public get enabled(): boolean {
@@ -253,8 +291,9 @@ class WizardImpl implements sqlops.window.modelviewdialog.Wizard {
private _navigationValidator: (info: sqlops.window.modelviewdialog.WizardPageChangeInfo) => boolean | Thenable<boolean>;
private _message: sqlops.window.modelviewdialog.DialogMessage;
private _displayPageTitles: boolean = true;
private _operationHandler: BackgroundOperationHandler;
constructor(public title: string, private _extHostModelViewDialog: ExtHostModelViewDialog) {
constructor(public title: string, private _extHostModelViewDialog: ExtHostModelViewDialog, extHostTaskManagement: ExtHostBackgroundTaskManagementShape) {
this.doneButton = this._extHostModelViewDialog.createButton(DONE_LABEL);
this.cancelButton = this._extHostModelViewDialog.createButton(CANCEL_LABEL);
this.generateScriptButton = this._extHostModelViewDialog.createButton(GENERATE_SCRIPT_LABEL);
@@ -263,6 +302,14 @@ class WizardImpl implements sqlops.window.modelviewdialog.Wizard {
this._extHostModelViewDialog.registerWizardPageInfoChangedCallback(this, info => this.handlePageInfoChanged(info));
this._currentPage = 0;
this.onPageChanged(info => this._currentPage = info.newPage);
this._operationHandler = new BackgroundOperationHandler('wizard' + this.title, extHostTaskManagement);
this.doneButton.onClick(() => {
this._operationHandler.createOperation();
});
}
public registerOperation(operationInfo: sqlops.BackgroundOperationInfo): void {
this._operationHandler.registerOperation(operationInfo);
}
public get currentPage(): number {
@@ -344,7 +391,8 @@ export class ExtHostModelViewDialog implements ExtHostModelViewDialogShape {
constructor(
mainContext: IMainContext,
private _extHostModelView: ExtHostModelViewShape
private _extHostModelView: ExtHostModelViewShape,
private _extHostTaskManagement: ExtHostBackgroundTaskManagementShape
) {
this._proxy = mainContext.getProxy(SqlMainContext.MainThreadModelViewDialog);
}
@@ -473,7 +521,7 @@ export class ExtHostModelViewDialog implements ExtHostModelViewDialogShape {
}
public createDialog(title: string): sqlops.window.modelviewdialog.Dialog {
let dialog = new DialogImpl(this, this._extHostModelView);
let dialog = new DialogImpl(this, this._extHostModelView, this._extHostTaskManagement);
dialog.title = title;
dialog.handle = this.getHandle(dialog);
return dialog;
@@ -516,7 +564,7 @@ export class ExtHostModelViewDialog implements ExtHostModelViewDialogShape {
}
public createWizard(title: string): sqlops.window.modelviewdialog.Wizard {
let wizard = new WizardImpl(title, this);
let wizard = new WizardImpl(title, this, this._extHostTaskManagement);
this.getHandle(wizard);
return wizard;
}

View File

@@ -0,0 +1,52 @@
/*---------------------------------------------------------------------------------------------
* 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 { ITaskService } from 'sql/parts/taskHistory/common/taskService';
import { MainThreadBackgroundTaskManagementShape, SqlMainContext, ExtHostBackgroundTaskManagementShape, SqlExtHostContext } from 'sql/workbench/api/node/sqlExtHost.protocol';
import { extHostNamedCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers';
import { IExtHostContext } from 'vs/workbench/api/node/extHost.protocol';
import { Disposable } from 'vs/base/common/lifecycle';
import * as sqlops from 'sqlops';
export enum TaskStatus {
NotStarted = 0,
InProgress = 1,
Succeeded = 2,
SucceededWithWarning = 3,
Failed = 4,
Canceled = 5,
Canceling = 6
}
@extHostNamedCustomer(SqlMainContext.MainThreadBackgroundTaskManagement)
export class MainThreadBackgroundTaskManagement extends Disposable implements MainThreadBackgroundTaskManagementShape {
private readonly _proxy: ExtHostBackgroundTaskManagementShape;
constructor(
context: IExtHostContext,
@ITaskService private _taskService: ITaskService
) {
super();
this._proxy = context.getProxy(SqlExtHostContext.ExtHostBackgroundTaskManagement);
this._register(this._taskService.onTaskComplete(task => {
if (task.status === TaskStatus.Canceling) {
this._proxy.$onTaskCanceled(task.id);
}
}));
}
$registerTask(taskInfo: sqlops.TaskInfo): void {
this._taskService.createNewTask(taskInfo);
this._proxy.$onTaskRegistered(taskInfo.taskId);
}
$updateTask(taskProgressInfo: sqlops.TaskProgressInfo): void {
this._taskService.updateTask(taskProgressInfo);
}
}

View File

@@ -34,6 +34,7 @@ import { ExtHostObjectExplorer } from 'sql/workbench/api/node/extHostObjectExplo
import { ExtHostLogService } from 'vs/workbench/api/node/extHostLogService';
import { ExtHostModelViewDialog } from 'sql/workbench/api/node/extHostModelViewDialog';
import { ExtHostQueryEditor } from 'sql/workbench/api/node/extHostQueryEditor';
import { ExtHostBackgroundTaskManagement } from './extHostBackgroundTaskManagement';
export interface ISqlExtensionApiFactory {
vsCodeFactory(extension: IExtensionDescription): typeof vscode;
@@ -63,10 +64,11 @@ export function createApiFactory(
const extHostResourceProvider = rpcProtocol.set(SqlExtHostContext.ExtHostResourceProvider, new ExtHostResourceProvider(rpcProtocol));
const extHostModalDialogs = rpcProtocol.set(SqlExtHostContext.ExtHostModalDialogs, new ExtHostModalDialogs(rpcProtocol));
const extHostTasks = rpcProtocol.set(SqlExtHostContext.ExtHostTasks, new ExtHostTasks(rpcProtocol, logService));
const extHostBackgroundTaskManagement = rpcProtocol.set(SqlExtHostContext.ExtHostBackgroundTaskManagement, new ExtHostBackgroundTaskManagement(rpcProtocol));
const extHostWebviewWidgets = rpcProtocol.set(SqlExtHostContext.ExtHostDashboardWebviews, new ExtHostDashboardWebviews(rpcProtocol));
const extHostModelView = rpcProtocol.set(SqlExtHostContext.ExtHostModelView, new ExtHostModelView(rpcProtocol));
const extHostDashboard = rpcProtocol.set(SqlExtHostContext.ExtHostDashboard, new ExtHostDashboard(rpcProtocol));
const extHostModelViewDialog = rpcProtocol.set(SqlExtHostContext.ExtHostModelViewDialog, new ExtHostModelViewDialog(rpcProtocol, extHostModelView));
const extHostModelViewDialog = rpcProtocol.set(SqlExtHostContext.ExtHostModelViewDialog, new ExtHostModelViewDialog(rpcProtocol, extHostModelView, extHostBackgroundTaskManagement));
const extHostQueryEditor = rpcProtocol.set(SqlExtHostContext.ExtHostQueryEditor, new ExtHostQueryEditor(rpcProtocol));
@@ -334,6 +336,9 @@ export function createApiFactory(
const tasks: typeof sqlops.tasks = {
registerTask(id: string, task: (...args: any[]) => any, thisArgs?: any): vscode.Disposable {
return extHostTasks.registerTask(id, task, thisArgs);
},
startBackgroundOperation(operationInfo: sqlops.BackgroundOperationInfo): void {
extHostBackgroundTaskManagement.$registerTask(operationInfo);
}
};

View File

@@ -14,6 +14,7 @@ import 'sql/workbench/api/node/mainThreadConnectionManagement';
import 'sql/workbench/api/node/mainThreadCredentialManagement';
import 'sql/workbench/api/node/mainThreadDataProtocol';
import 'sql/workbench/api/node/mainThreadObjectExplorer';
import 'sql/workbench/api/node/mainThreadBackgroundTaskManagement';
import 'sql/workbench/api/node/mainThreadSerializationProvider';
import 'sql/workbench/api/node/mainThreadResourceProvider';
import 'sql/workbench/api/electron-browser/mainThreadTasks';

View File

@@ -496,6 +496,7 @@ export const SqlMainContext = {
MainThreadCredentialManagement: createMainId<MainThreadCredentialManagementShape>('MainThreadCredentialManagement'),
MainThreadDataProtocol: createMainId<MainThreadDataProtocolShape>('MainThreadDataProtocol'),
MainThreadObjectExplorer: createMainId<MainThreadObjectExplorerShape>('MainThreadObjectExplorer'),
MainThreadBackgroundTaskManagement: createMainId<MainThreadBackgroundTaskManagementShape>('MainThreadBackgroundTaskManagement'),
MainThreadSerializationProvider: createMainId<MainThreadSerializationProviderShape>('MainThreadSerializationProvider'),
MainThreadResourceProvider: createMainId<MainThreadResourceProviderShape>('MainThreadResourceProvider'),
MainThreadModalDialog: createMainId<MainThreadModalDialogShape>('MainThreadModalDialog'),
@@ -517,6 +518,7 @@ export const SqlExtHostContext = {
ExtHostResourceProvider: createExtId<ExtHostResourceProviderShape>('ExtHostResourceProvider'),
ExtHostModalDialogs: createExtId<ExtHostModalDialogsShape>('ExtHostModalDialogs'),
ExtHostTasks: createExtId<ExtHostTasksShape>('ExtHostTasks'),
ExtHostBackgroundTaskManagement: createExtId<ExtHostBackgroundTaskManagementShape>('ExtHostBackgroundTaskManagement'),
ExtHostDashboardWebviews: createExtId<ExtHostDashboardWebviewsShape>('ExtHostDashboardWebviews'),
ExtHostModelView: createExtId<ExtHostModelViewShape>('ExtHostModelView'),
ExtHostDashboard: createExtId<ExtHostDashboardShape>('ExtHostDashboard'),
@@ -578,6 +580,18 @@ export interface ExtHostModelViewShape {
$runCustomValidations(handle: number, id: string): Thenable<boolean>;
}
export interface ExtHostBackgroundTaskManagementShape {
$onTaskRegistered(operationId: string): void;
$onTaskCanceled(operationId: string): void;
$registerTask(operationInfo: sqlops.BackgroundOperationInfo): void;
$removeTask(operationId: string): void;
}
export interface MainThreadBackgroundTaskManagementShape extends IDisposable {
$registerTask(taskInfo: sqlops.TaskInfo): void;
$updateTask(taskProgressInfo: sqlops.TaskProgressInfo): void;
}
export interface MainThreadModelViewShape extends IDisposable {
$registerProvider(id: string): void;
$initializeModel(handle: number, rootComponent: IComponentShape): Thenable<void>;