mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-20 17:22:51 -05:00
remove event emitter and use event and emitter instead (#5361)
This commit is contained in:
@@ -11,19 +11,18 @@ import { IQueryManagementService } from 'sql/platform/query/common/queryManageme
|
||||
import * as Utils from 'sql/platform/connection/common/utils';
|
||||
import { SaveFormat } from 'sql/workbench/parts/grid/common/interfaces';
|
||||
import { Deferred } from 'sql/base/common/promise';
|
||||
import { IQueryPlanInfo } from 'sql/platform/query/common/queryModel';
|
||||
import { ResultSerializer } from 'sql/platform/node/resultSerializer';
|
||||
|
||||
import Severity from 'vs/base/common/severity';
|
||||
import * as nls from 'vs/nls';
|
||||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
|
||||
import * as types from 'vs/base/common/types';
|
||||
import { EventEmitter } from 'sql/base/common/eventEmitter';
|
||||
import { IDisposable, Disposable } from 'vs/base/common/lifecycle';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { INotificationService } from 'vs/platform/notification/common/notification';
|
||||
import { Emitter, Event } from 'vs/base/common/event';
|
||||
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { ResultSerializer } from 'sql/platform/node/resultSerializer';
|
||||
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
|
||||
import { IQueryPlanInfo } from 'sql/platform/query/common/queryModel';
|
||||
import { ITextResourcePropertiesService } from 'vs/editor/common/services/resourceConfiguration';
|
||||
import { URI } from 'vs/base/common/uri';
|
||||
|
||||
@@ -33,28 +32,6 @@ export interface IEditSessionReadyEvent {
|
||||
message: string;
|
||||
}
|
||||
|
||||
export const enum EventType {
|
||||
START = 'start',
|
||||
COMPLETE = 'complete',
|
||||
MESSAGE = 'message',
|
||||
BATCH_START = 'batchStart',
|
||||
BATCH_COMPLETE = 'batchComplete',
|
||||
RESULT_SET = 'resultSet',
|
||||
EDIT_SESSION_READY = 'editSessionReady',
|
||||
QUERY_PLAN_AVAILABLE = 'queryPlanAvailable'
|
||||
}
|
||||
|
||||
export interface IEventType {
|
||||
start: void;
|
||||
complete: string;
|
||||
message: azdata.IResultMessage;
|
||||
batchStart: azdata.BatchSummary;
|
||||
batchComplete: azdata.BatchSummary;
|
||||
resultSet: azdata.ResultSetSummary;
|
||||
editSessionReady: IEditSessionReadyEvent;
|
||||
queryPlanAvailable: IQueryPlanInfo;
|
||||
}
|
||||
|
||||
export interface IGridMessage extends azdata.IResultMessage {
|
||||
selection: azdata.ISelectionData;
|
||||
}
|
||||
@@ -71,7 +48,6 @@ export default class QueryRunner extends Disposable {
|
||||
private _hasCompleted: boolean = false;
|
||||
private _batchSets: azdata.BatchSummary[] = [];
|
||||
private _messages: azdata.IResultMessage[] = [];
|
||||
private _eventEmitter = new EventEmitter();
|
||||
private registered = false;
|
||||
|
||||
private _isQueryPlan: boolean;
|
||||
@@ -80,7 +56,7 @@ export default class QueryRunner extends Disposable {
|
||||
public get planXml(): Thenable<string> { return this._planXml.promise; }
|
||||
|
||||
private _onMessage = this._register(new Emitter<azdata.IResultMessage>());
|
||||
public readonly onMessage = this._onMessage.event;
|
||||
public get onMessage(): Event<azdata.IResultMessage> { return this._onMessage.event; } // this is the only way typemoq can moq this... needs investigation @todo anthonydresser 5/2/2019
|
||||
|
||||
private _onResultSet = this._register(new Emitter<azdata.ResultSetSummary>());
|
||||
public readonly onResultSet = this._onResultSet.event;
|
||||
@@ -92,7 +68,7 @@ export default class QueryRunner extends Disposable {
|
||||
public readonly onQueryStart: Event<void> = this._onQueryStart.event;
|
||||
|
||||
private _onQueryEnd = this._register(new Emitter<string>());
|
||||
public readonly onQueryEnd: Event<string> = this._onQueryEnd.event;
|
||||
public get onQueryEnd(): Event<string> { return this._onQueryEnd.event; }
|
||||
|
||||
private _onBatchStart = this._register(new Emitter<azdata.BatchSummary>());
|
||||
public readonly onBatchStart: Event<azdata.BatchSummary> = this._onBatchStart.event;
|
||||
@@ -100,6 +76,12 @@ export default class QueryRunner extends Disposable {
|
||||
private _onBatchEnd = this._register(new Emitter<azdata.BatchSummary>());
|
||||
public readonly onBatchEnd: Event<azdata.BatchSummary> = this._onBatchEnd.event;
|
||||
|
||||
private _onEditSessionReady = this._register(new Emitter<IEditSessionReadyEvent>());
|
||||
public readonly onEditSessionReady = this._onEditSessionReady.event;
|
||||
|
||||
private _onQueryPlanAvailable = this._register(new Emitter<IQueryPlanInfo>());
|
||||
public readonly onQueryPlanAvailable = this._onQueryPlanAvailable.event;
|
||||
|
||||
private _queryStartTime: Date;
|
||||
public get queryStartTime(): Date {
|
||||
return this._queryStartTime;
|
||||
@@ -146,10 +128,6 @@ export default class QueryRunner extends Disposable {
|
||||
|
||||
// PUBLIC METHODS ======================================================
|
||||
|
||||
public addListener<K extends keyof IEventType>(event: K, f: (e: IEventType[K]) => void): IDisposable {
|
||||
return this._eventEmitter.addListener(event, f);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels the running query, if there is one
|
||||
*/
|
||||
@@ -229,7 +207,6 @@ export default class QueryRunner extends Disposable {
|
||||
// this isn't exact, but its the best we can do
|
||||
this._queryStartTime = new Date();
|
||||
// The query has started, so lets fire up the result pane
|
||||
this._eventEmitter.emit(EventType.START);
|
||||
if (!this.registered) {
|
||||
this.registered = true;
|
||||
this._queryManagementService.registerRunner(this, this.uri);
|
||||
@@ -270,8 +247,6 @@ export default class QueryRunner extends Disposable {
|
||||
});
|
||||
|
||||
let timeStamp = Utils.parseNumAsTimeString(this._totalElapsedMilliseconds);
|
||||
|
||||
this._eventEmitter.emit(EventType.COMPLETE, timeStamp);
|
||||
// We're done with this query so shut down any waiting mechanisms
|
||||
|
||||
let message = {
|
||||
@@ -311,7 +286,6 @@ export default class QueryRunner extends Disposable {
|
||||
isError: false
|
||||
};
|
||||
this._messages.push(message);
|
||||
this._eventEmitter.emit(EventType.BATCH_START, batch);
|
||||
this._onMessage.fire(message);
|
||||
this._onBatchStart.fire(batch);
|
||||
}
|
||||
@@ -331,7 +305,6 @@ export default class QueryRunner extends Disposable {
|
||||
this.sendBatchTimeMessage(batch.id, Utils.parseNumAsTimeString(executionTime));
|
||||
}
|
||||
|
||||
this._eventEmitter.emit(EventType.BATCH_COMPLETE, batch);
|
||||
this._onBatchEnd.fire(batch);
|
||||
}
|
||||
|
||||
@@ -376,7 +349,6 @@ export default class QueryRunner extends Disposable {
|
||||
if (batchSet && !batchSet.resultSetSummaries[resultSet.id]) {
|
||||
// Store the result set in the batch and emit that a result set has completed
|
||||
batchSet.resultSetSummaries[resultSet.id] = resultSet;
|
||||
this._eventEmitter.emit(EventType.RESULT_SET, resultSet);
|
||||
this._onResultSet.fire(resultSet);
|
||||
}
|
||||
}
|
||||
@@ -398,7 +370,7 @@ export default class QueryRunner extends Disposable {
|
||||
this._planXml.resolve(e.resultSubset.rows[0][0].displayValue);
|
||||
// fire query plan available event if execution is completed
|
||||
if (result.resultSetSummary.complete) {
|
||||
this._eventEmitter.emit(EventType.QUERY_PLAN_AVAILABLE, {
|
||||
this._onQueryPlanAvailable.fire({
|
||||
providerId: 'MSSQL',
|
||||
fileUri: result.ownerUri,
|
||||
planXml: planXmlString
|
||||
@@ -425,7 +397,6 @@ export default class QueryRunner extends Disposable {
|
||||
this._messages.push(message);
|
||||
|
||||
// Send the message to the results pane
|
||||
this._eventEmitter.emit(EventType.MESSAGE, message);
|
||||
this._onMessage.fire(message);
|
||||
}
|
||||
|
||||
@@ -461,7 +432,7 @@ export default class QueryRunner extends Disposable {
|
||||
|
||||
return this._queryManagementService.initializeEdit(ownerUri, schemaName, objectName, objectType, rowLimit, queryString).then(result => {
|
||||
// The query has started, so lets fire up the result pane
|
||||
this._eventEmitter.emit(EventType.START);
|
||||
this._onQueryStart.fire();
|
||||
this._queryManagementService.registerRunner(this, ownerUri);
|
||||
}, error => {
|
||||
// Attempting to launch the query failed, show the error message
|
||||
@@ -511,7 +482,7 @@ export default class QueryRunner extends Disposable {
|
||||
}
|
||||
|
||||
public handleEditSessionReady(ownerUri: string, success: boolean, message: string): void {
|
||||
this._eventEmitter.emit(EventType.EDIT_SESSION_READY, { ownerUri, success, message });
|
||||
this._onEditSessionReady.fire({ ownerUri, success, message });
|
||||
}
|
||||
|
||||
public updateCell(ownerUri: string, rowId: number, columnId: number, newValue: string): Thenable<azdata.EditUpdateCellResult> {
|
||||
|
||||
Reference in New Issue
Block a user