More promise cleanup (#8100)

* Some promise cleanup

* Handle more promise issues

* Remove changes that aren't needed anymore

* Use log service

* another one

* Be more explicit

* Some more promises cleaned up

* Handle promises here too

* Strings for errors

* Some more cleanup

* Remove unused imports
This commit is contained in:
Amir Omidi
2019-10-31 14:30:08 -07:00
committed by GitHub
parent 572a83dac7
commit b62c0cf2ab
11 changed files with 165 additions and 189 deletions

View File

@@ -587,7 +587,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
} }
public saveProfileGroup(profile: IConnectionProfileGroup): Promise<string> { public saveProfileGroup(profile: IConnectionProfileGroup): Promise<string> {
TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.AddServerGroup); TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.AddServerGroup).catch((e) => this._logService.error(e));
return this._connectionStore.saveProfileGroup(profile).then(groupId => { return this._connectionStore.saveProfileGroup(profile).then(groupId => {
this._onAddConnectionProfile.fire(undefined); this._onAddConnectionProfile.fire(undefined);
return groupId; return groupId;
@@ -834,13 +834,13 @@ export class ConnectionManagementService extends Disposable implements IConnecti
extensionConnectionTime: connection.extensionTimer.elapsed() - connection.serviceTimer.elapsed(), extensionConnectionTime: connection.extensionTimer.elapsed() - connection.serviceTimer.elapsed(),
serviceConnectionTime: connection.serviceTimer.elapsed() serviceConnectionTime: connection.serviceTimer.elapsed()
}); }).catch((e) => this._logService.error(e));
} }
private addTelemetryForConnectionDisconnected(connection: interfaces.IConnectionProfile): void { private addTelemetryForConnectionDisconnected(connection: interfaces.IConnectionProfile): void {
TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.DatabaseDisconnected, { TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.DatabaseDisconnected, {
provider: connection.providerName provider: connection.providerName
}); }).catch((e) => this._logService.error(e));
} }
public onConnectionComplete(handle: number, info: azdata.ConnectionInfoSummary): void { public onConnectionComplete(handle: number, info: azdata.ConnectionInfoSummary): void {
@@ -882,13 +882,13 @@ export class ConnectionManagementService extends Disposable implements IConnecti
} }
public changeGroupIdForConnectionGroup(source: ConnectionProfileGroup, target: ConnectionProfileGroup): Promise<void> { public changeGroupIdForConnectionGroup(source: ConnectionProfileGroup, target: ConnectionProfileGroup): Promise<void> {
TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.MoveServerConnection); TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.MoveServerConnection).catch((e) => this._logService.error(e));
return this._connectionStore.changeGroupIdForConnectionGroup(source, target); return this._connectionStore.changeGroupIdForConnectionGroup(source, target);
} }
public changeGroupIdForConnection(source: ConnectionProfile, targetGroupId: string): Promise<void> { public changeGroupIdForConnection(source: ConnectionProfile, targetGroupId: string): Promise<void> {
let id = Utils.generateUri(source); let id = Utils.generateUri(source);
TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.MoveServerGroup); TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.MoveServerGroup).catch((e) => this._logService.error(e));
return this._connectionStore.changeGroupIdForConnection(source, targetGroupId).then(result => { return this._connectionStore.changeGroupIdForConnection(source, targetGroupId).then(result => {
if (id && targetGroupId) { if (id && targetGroupId) {
source.groupId = targetGroupId; source.groupId = targetGroupId;
@@ -971,7 +971,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
}); });
// send connection request // send connection request
self.sendConnectRequest(connection, uri); self.sendConnectRequest(connection, uri).catch((e) => this._logService.error(e));
}); });
} }
@@ -1144,7 +1144,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
*/ */
public deleteConnection(connection: ConnectionProfile): Promise<boolean> { public deleteConnection(connection: ConnectionProfile): Promise<boolean> {
TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.DeleteConnection, {}, connection); TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.DeleteConnection, {}, connection).catch((e) => this._logService.error(e));
// Disconnect if connected // Disconnect if connected
let uri = Utils.generateUri(connection); let uri = Utils.generateUri(connection);
if (this.isConnected(uri) || this.isConnecting(uri)) { if (this.isConnected(uri) || this.isConnecting(uri)) {
@@ -1174,7 +1174,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
* Disconnects a connection before removing from config. If disconnect fails, settings is not modified. * Disconnects a connection before removing from config. If disconnect fails, settings is not modified.
*/ */
public deleteConnectionGroup(group: ConnectionProfileGroup): Promise<boolean> { public deleteConnectionGroup(group: ConnectionProfileGroup): Promise<boolean> {
TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.DeleteServerGroup); TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.DeleteServerGroup).catch((e) => this._logService.error(e));
// Get all connections for this group // Get all connections for this group
let connections = ConnectionProfileGroup.getConnectionsInGroup(group); let connections = ConnectionProfileGroup.getConnectionsInGroup(group);

View File

@@ -15,6 +15,7 @@ import * as azdata from 'azdata';
import { IQueryManagementService } from 'sql/platform/query/common/queryManagement'; import { IQueryManagementService } from 'sql/platform/query/common/queryManagement';
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces'; import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile'; import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { ILogService } from 'vs/platform/log/common/log';
@extHostNamedCustomer(SqlMainContext.MainThreadQueryEditor) @extHostNamedCustomer(SqlMainContext.MainThreadQueryEditor)
export class MainThreadQueryEditor extends Disposable implements MainThreadQueryEditorShape { export class MainThreadQueryEditor extends Disposable implements MainThreadQueryEditorShape {
@@ -26,7 +27,8 @@ export class MainThreadQueryEditor extends Disposable implements MainThreadQuery
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService, @IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IQueryModelService private _queryModelService: IQueryModelService, @IQueryModelService private _queryModelService: IQueryModelService,
@IEditorService private _editorService: IEditorService, @IEditorService private _editorService: IEditorService,
@IQueryManagementService private _queryManagementService: IQueryManagementService @IQueryManagementService private _queryManagementService: IQueryManagementService,
@ILogService private _logService: ILogService
) { ) {
super(); super();
if (extHostContext) { if (extHostContext) {
@@ -101,9 +103,9 @@ export class MainThreadQueryEditor extends Disposable implements MainThreadQuery
if (editor instanceof QueryEditor) { if (editor instanceof QueryEditor) {
let queryEditor: QueryEditor = editor; let queryEditor: QueryEditor = editor;
if (runCurrentQuery) { if (runCurrentQuery) {
queryEditor.runCurrentQuery(); queryEditor.runCurrentQuery().catch((e) => this._logService.error(e));
} else { } else {
queryEditor.runQuery(); queryEditor.runQuery().catch((e) => this._logService.error(e));
} }
} }
} }

View File

@@ -23,6 +23,7 @@ import { QueryTextEditor } from 'sql/workbench/browser/modelComponents/queryText
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
import { SimpleEditorProgressService } from 'vs/editor/standalone/browser/simpleServices'; import { SimpleEditorProgressService } from 'vs/editor/standalone/browser/simpleServices';
import { IProgressService } from 'vs/platform/progress/common/progress'; import { IProgressService } from 'vs/platform/progress/common/progress';
import { ILogService } from 'vs/platform/log/common/log';
@Component({ @Component({
template: '', template: '',
@@ -45,33 +46,33 @@ export default class EditorComponent extends ComponentBase implements IComponent
@Inject(forwardRef(() => ElementRef)) el: ElementRef, @Inject(forwardRef(() => ElementRef)) el: ElementRef,
@Inject(IInstantiationService) private _instantiationService: IInstantiationService, @Inject(IInstantiationService) private _instantiationService: IInstantiationService,
@Inject(IModelService) private _modelService: IModelService, @Inject(IModelService) private _modelService: IModelService,
@Inject(IModeService) private _modeService: IModeService @Inject(IModeService) private _modeService: IModeService,
@Inject(ILogService) private _logService: ILogService
) { ) {
super(changeRef, el); super(changeRef, el);
} }
ngOnInit(): void { ngOnInit(): void {
this.baseInit(); this.baseInit();
this._createEditor(); this._createEditor().catch((e) => this._logService.error(e));
this._register(DOM.addDisposableListener(window, DOM.EventType.RESIZE, e => { this._register(DOM.addDisposableListener(window, DOM.EventType.RESIZE, e => {
this.layout(); this.layout();
})); }));
} }
private _createEditor(): void { private async _createEditor(): Promise<void> {
let instantiationService = this._instantiationService.createChild(new ServiceCollection([IProgressService, new SimpleEditorProgressService()])); let instantiationService = this._instantiationService.createChild(new ServiceCollection([IProgressService, new SimpleEditorProgressService()]));
this._editor = instantiationService.createInstance(QueryTextEditor); this._editor = instantiationService.createInstance(QueryTextEditor);
this._editor.create(this._el.nativeElement); this._editor.create(this._el.nativeElement);
this._editor.setVisible(true); this._editor.setVisible(true);
let uri = this.createUri(); let uri = this.createUri();
this._editorInput = instantiationService.createInstance(UntitledEditorInput, uri, false, 'plaintext', '', ''); this._editorInput = instantiationService.createInstance(UntitledEditorInput, uri, false, 'plaintext', '', '');
this._editor.setInput(this._editorInput, undefined); await this._editor.setInput(this._editorInput, undefined);
this._editorInput.resolve().then(model => { const model = await this._editorInput.resolve();
this._editorModel = model.textEditorModel; this._editorModel = model.textEditorModel;
this.fireEvent({ this.fireEvent({
eventType: ComponentEventType.onComponentCreated, eventType: ComponentEventType.onComponentCreated,
args: this._uri args: this._uri
});
}); });
this._register(this._editor); this._register(this._editor);

View File

@@ -25,14 +25,14 @@ export class ScriptSelectAction extends Action {
super(id, label); super(id, label);
} }
public run(actionContext: BaseActionContext): Promise<boolean> { public async run(actionContext: BaseActionContext): Promise<boolean> {
return scriptSelect( return scriptSelect(
actionContext.profile, actionContext.profile,
actionContext.object, actionContext.object,
this._connectionManagementService, this._connectionManagementService,
this._queryEditorService, this._queryEditorService,
this._scriptingService this._scriptingService
).then(() => true); );
} }
} }
@@ -50,7 +50,7 @@ export class ScriptExecuteAction extends Action {
super(id, label); super(id, label);
} }
public run(actionContext: BaseActionContext): Promise<boolean> { public async run(actionContext: BaseActionContext): Promise<boolean> {
return script( return script(
actionContext.profile, actionContext.profile,
actionContext.object, actionContext.object,
@@ -59,7 +59,7 @@ export class ScriptExecuteAction extends Action {
this._scriptingService, this._scriptingService,
ScriptOperation.Execute, ScriptOperation.Execute,
this._errorMessageService this._errorMessageService
).then(() => true); );
} }
} }
@@ -77,7 +77,7 @@ export class ScriptAlterAction extends Action {
super(id, label); super(id, label);
} }
public run(actionContext: BaseActionContext): Promise<boolean> { public async run(actionContext: BaseActionContext): Promise<boolean> {
return script( return script(
actionContext.profile, actionContext.profile,
actionContext.object, actionContext.object,
@@ -86,7 +86,7 @@ export class ScriptAlterAction extends Action {
this._scriptingService, this._scriptingService,
ScriptOperation.Alter, ScriptOperation.Alter,
this._errorMessageService this._errorMessageService
).then(() => true); );
} }
} }
@@ -103,14 +103,14 @@ export class EditDataAction extends Action {
super(id, label); super(id, label);
} }
public run(actionContext: BaseActionContext): Promise<boolean> { public async run(actionContext: BaseActionContext): Promise<boolean> {
return scriptEditSelect( return scriptEditSelect(
actionContext.profile, actionContext.profile,
actionContext.object, actionContext.object,
this._connectionManagementService, this._connectionManagementService,
this._queryEditorService, this._queryEditorService,
this._scriptingService this._scriptingService
).then(() => true); );
} }
} }
@@ -128,7 +128,7 @@ export class ScriptCreateAction extends Action {
super(id, label); super(id, label);
} }
public run(actionContext: BaseActionContext): Promise<boolean> { public async run(actionContext: BaseActionContext): Promise<boolean> {
return script( return script(
actionContext.profile, actionContext.profile,
actionContext.object, actionContext.object,
@@ -137,7 +137,7 @@ export class ScriptCreateAction extends Action {
this._scriptingService, this._scriptingService,
ScriptOperation.Create, ScriptOperation.Create,
this._errorMessageService this._errorMessageService
).then(() => true); );
} }
} }
@@ -155,7 +155,7 @@ export class ScriptDeleteAction extends Action {
super(id, label); super(id, label);
} }
public run(actionContext: BaseActionContext): Promise<boolean> { public async run(actionContext: BaseActionContext): Promise<boolean> {
return script( return script(
actionContext.profile, actionContext.profile,
actionContext.object, actionContext.object,
@@ -164,6 +164,6 @@ export class ScriptDeleteAction extends Action {
this._scriptingService, this._scriptingService,
ScriptOperation.Delete, ScriptOperation.Delete,
this._errorMessageService this._errorMessageService
).then(() => true); );
} }
} }

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/ *--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata'; import * as azdata from 'azdata';
import { IConnectionManagementService, IConnectionCompletionOptions, ConnectionType, IConnectableInput, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement'; import { IConnectionManagementService, IConnectionCompletionOptions, ConnectionType, RunQueryOnConnectionMode } from 'sql/platform/connection/common/connectionManagement';
import { ConnectionManagementInfo } from 'sql/platform/connection/common/connectionManagementInfo'; import { ConnectionManagementInfo } from 'sql/platform/connection/common/connectionManagementInfo';
import * as nls from 'vs/nls'; import * as nls from 'vs/nls';
import Severity from 'vs/base/common/severity'; import Severity from 'vs/base/common/severity';
@@ -12,7 +12,6 @@ import { IErrorMessageService } from 'sql/platform/errorMessage/common/errorMess
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces'; import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService'; import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
import { IScriptingService, ScriptOperation } from 'sql/platform/scripting/common/scriptingService'; import { IScriptingService, ScriptOperation } from 'sql/platform/scripting/common/scriptingService';
import { EditDataInput } from 'sql/workbench/parts/editData/browser/editDataInput';
// map for the version of SQL Server (default is 140) // map for the version of SQL Server (default is 140)
const scriptCompatibilityOptionMap = { const scriptCompatibilityOptionMap = {
@@ -41,71 +40,53 @@ const targetDatabaseEngineEditionMap = {
/** /**
* Select the top rows from an object * Select the top rows from an object
*/ */
export function scriptSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<void> { export async function scriptSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<boolean> {
return new Promise<void>((resolve, reject) => { const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => { let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata); const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails);
scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails).then(result => { if (result && result.script) {
if (result && result.script) { const owner = await queryEditorService.newSqlEditor(result.script);
queryEditorService.newSqlEditor(result.script).then((owner: IConnectableInput) => { // Connect our editor to the input connection
// Connect our editor to the input connection let options: IConnectionCompletionOptions = {
let options: IConnectionCompletionOptions = { params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery, input: owner },
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery, input: owner }, saveTheConnection: false,
saveTheConnection: false, showDashboard: false,
showDashboard: false, showConnectionDialogOnError: true,
showConnectionDialogOnError: true, showFirewallRuleOnError: true
showFirewallRuleOnError: true };
}; const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
connectionService.connect(connectionProfile, owner.uri, options).then(() => {
resolve(); return Boolean(innerConnectionResult) && innerConnectionResult.connected;
}); } else {
}).catch(editorError => { let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
reject(editorError); throw new Error(errMsg.concat(metadata.metadataTypeName));
}); }
} else {
let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
reject(errMsg.concat(metadata.metadataTypeName));
}
}, scriptError => {
reject(scriptError);
});
});
});
} }
/** /**
* Opens a new Edit Data session * Opens a new Edit Data session
*/ */
export function scriptEditSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<void> { export async function scriptEditSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<boolean> {
return new Promise<void>((resolve, reject) => { const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => { let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata); const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails);
scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails).then(result => { if (result && result.script) {
if (result && result.script) { const owner = await queryEditorService.newEditDataEditor(metadata.schema, metadata.name, result.script);
queryEditorService.newEditDataEditor(metadata.schema, metadata.name, result.script).then((owner: EditDataInput) => { // Connect our editor
// Connect our editor let options: IConnectionCompletionOptions = {
let options: IConnectionCompletionOptions = { params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner }, saveTheConnection: false,
saveTheConnection: false, showDashboard: false,
showDashboard: false, showConnectionDialogOnError: true,
showConnectionDialogOnError: true, showFirewallRuleOnError: true
showFirewallRuleOnError: true };
}; const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
connectionService.connect(connectionProfile, owner.uri, options).then(() => {
resolve(); return Boolean(innerConnectionResult) && innerConnectionResult.connected;
}); } else {
}).catch(editorError => { let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
reject(editorError); throw new Error(errMsg.concat(metadata.metadataTypeName));
}); }
} else {
let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
reject(errMsg.concat(metadata.metadataTypeName));
}
}, scriptError => {
reject(scriptError);
});
});
});
} }
@@ -132,61 +113,51 @@ export function GetScriptOperationName(operation: ScriptOperation) {
/** /**
* Script the object as a statement based on the provided action (except Select) * Script the object as a statement based on the provided action (except Select)
*/ */
export function script(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, export async function script(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata,
connectionService: IConnectionManagementService, connectionService: IConnectionManagementService,
queryEditorService: IQueryEditorService, queryEditorService: IQueryEditorService,
scriptingService: IScriptingService, scriptingService: IScriptingService,
operation: ScriptOperation, operation: ScriptOperation,
errorMessageService: IErrorMessageService): Promise<void> { errorMessageService: IErrorMessageService): Promise<boolean> {
return new Promise<void>((resolve, reject) => { const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => { let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata); const result = await scriptingService.script(connectionResult, metadata, operation, paramDetails);
scriptingService.script(connectionResult, metadata, operation, paramDetails).then(result => { if (result) {
if (result) { let script: string = result.script;
let script: string = result.script;
if (script) { if (script) {
let description = (metadata.schema && metadata.schema !== '') ? `${metadata.schema}.${metadata.name}` : metadata.name; let description = (metadata.schema && metadata.schema !== '') ? `${metadata.schema}.${metadata.name}` : metadata.name;
queryEditorService.newSqlEditor(script, connectionProfile.providerName, undefined, description).then((owner) => { const owner = await queryEditorService.newSqlEditor(script, connectionProfile.providerName, undefined, description);
// Connect our editor to the input connection // Connect our editor to the input connection
let options: IConnectionCompletionOptions = { let options: IConnectionCompletionOptions = {
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner }, params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
saveTheConnection: false, saveTheConnection: false,
showDashboard: false, showDashboard: false,
showConnectionDialogOnError: true, showConnectionDialogOnError: true,
showFirewallRuleOnError: true showFirewallRuleOnError: true
}; };
connectionService.connect(connectionProfile, owner.uri, options).then(() => { const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
resolve();
}); return Boolean(innerConnectionResult) && innerConnectionResult.connected;
}).catch(editorError => {
reject(editorError); } else {
}); let scriptNotFoundMsg = nls.localize('scriptNotFoundForObject', "No script was returned when scripting as {0} on object {1}",
} else { GetScriptOperationName(operation), metadata.metadataTypeName);
let scriptNotFoundMsg = nls.localize('scriptNotFoundForObject', "No script was returned when scripting as {0} on object {1}", let messageDetail = '';
GetScriptOperationName(operation), metadata.metadataTypeName); let operationResult = scriptingService.getOperationFailedResult(result.operationId);
let messageDetail = ''; if (operationResult && operationResult.hasError && operationResult.errorMessage) {
let operationResult = scriptingService.getOperationFailedResult(result.operationId); scriptNotFoundMsg = operationResult.errorMessage;
if (operationResult && operationResult.hasError && operationResult.errorMessage) { messageDetail = operationResult.errorDetails;
scriptNotFoundMsg = operationResult.errorMessage; }
messageDetail = operationResult.errorDetails; if (errorMessageService) {
} let title = nls.localize('scriptingFailed', "Scripting Failed");
if (errorMessageService) { errorMessageService.showDialog(Severity.Error, title, scriptNotFoundMsg, messageDetail);
let title = nls.localize('scriptingFailed', "Scripting Failed"); }
errorMessageService.showDialog(Severity.Error, title, scriptNotFoundMsg, messageDetail); throw new Error(scriptNotFoundMsg);
} }
reject(scriptNotFoundMsg); } else {
} throw new Error(nls.localize('scriptNotFound', "No script was returned when scripting as {0}", GetScriptOperationName(operation)));
} else { }
reject(nls.localize('scriptNotFound', "No script was returned when scripting as {0}", GetScriptOperationName(operation)));
}
}, scriptingError => {
reject(scriptingError);
});
}).catch(connectionError => {
reject(connectionError);
});
});
} }
function getScriptingParamDetails(connectionService: IConnectionManagementService, ownerUri: string, metadata: azdata.ObjectMetadata): azdata.ScriptingParamDetails { function getScriptingParamDetails(connectionService: IConnectionManagementService, ownerUri: string, metadata: azdata.ObjectMetadata): azdata.ScriptingParamDetails {

View File

@@ -77,7 +77,7 @@ export class DashboardEditor extends BaseEditor {
this._dashboardService.layout(dimension); this._dashboardService.layout(dimension);
} }
public setInput(input: DashboardInput, options: EditorOptions): Promise<void> { public async setInput(input: DashboardInput, options: EditorOptions): Promise<void> {
if (this.input && this.input.matches(input)) { if (this.input && this.input.matches(input)) {
return Promise.resolve(undefined); return Promise.resolve(undefined);
} }
@@ -93,10 +93,10 @@ export class DashboardEditor extends BaseEditor {
container.style.height = '100%'; container.style.height = '100%';
this._dashboardContainer = DOM.append(parentElement, container); this._dashboardContainer = DOM.append(parentElement, container);
this.input.container = this._dashboardContainer; this.input.container = this._dashboardContainer;
return Promise.resolve(input.initializedPromise.then(() => this.bootstrapAngular(input))); await input.initializedPromise;
this.bootstrapAngular(input);
} else { } else {
this._dashboardContainer = DOM.append(parentElement, this.input.container); this._dashboardContainer = DOM.append(parentElement, this.input.container);
return Promise.resolve(null);
} }
} }

View File

@@ -578,29 +578,29 @@ export class QueryEditor extends BaseEditor {
/** /**
* Calls the runCurrent method of this editor's RunQueryAction * Calls the runCurrent method of this editor's RunQueryAction
*/ */
public runCurrentQuery(): void { public async runCurrentQuery(): Promise<void> {
this._runQueryAction.runCurrent(); return this._runQueryAction.runCurrent();
} }
/** /**
* Calls the runCurrentQueryWithActualPlan method of this editor's ActualQueryPlanAction * Calls the runCurrentQueryWithActualPlan method of this editor's ActualQueryPlanAction
*/ */
public runCurrentQueryWithActualPlan(): void { public async runCurrentQueryWithActualPlan(): Promise<void> {
this._actualQueryPlanAction.run(); return this._actualQueryPlanAction.run();
} }
/** /**
* Calls the run method of this editor's RunQueryAction * Calls the run method of this editor's RunQueryAction
*/ */
public runQuery(): void { public async runQuery(): Promise<void> {
this._runQueryAction.run(); return this._runQueryAction.run();
} }
/** /**
* Calls the run method of this editor's CancelQueryAction * Calls the run method of this editor's CancelQueryAction
*/ */
public cancelQuery(): void { public async cancelQuery(): Promise<void> {
this._cancelQueryAction.run(); return this._cancelQueryAction.run();
} }
public registerQueryModelViewTab(title: string, componentId: string): void { public registerQueryModelViewTab(title: string, componentId: string): void {

View File

@@ -10,6 +10,7 @@ import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/com
import { ConnectionController } from 'sql/workbench/services/connection/browser/connectionController'; import { ConnectionController } from 'sql/workbench/services/connection/browser/connectionController';
import { CmsConnectionWidget } from 'sql/workbench/services/connection/browser/cmsConnectionWidget'; import { CmsConnectionWidget } from 'sql/workbench/services/connection/browser/cmsConnectionWidget';
import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController'; import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController';
import { ILogService } from 'vs/platform/log/common/log';
/** /**
* Connection Controller for CMS Connections * Connection Controller for CMS Connections
@@ -22,9 +23,10 @@ export class CmsConnectionController extends ConnectionController {
providerName: string, providerName: string,
@IConnectionManagementService _connectionManagementService: IConnectionManagementService, @IConnectionManagementService _connectionManagementService: IConnectionManagementService,
@IInstantiationService _instantiationService: IInstantiationService, @IInstantiationService _instantiationService: IInstantiationService,
@IServerGroupController _serverGroupController: IServerGroupController @IServerGroupController _serverGroupController: IServerGroupController,
@ILogService _logService: ILogService
) { ) {
super(connectionProperties, callback, providerName, _connectionManagementService, _instantiationService, _serverGroupController); super(connectionProperties, callback, providerName, _connectionManagementService, _instantiationService, _serverGroupController, _logService);
let specialOptions = this._providerOptions.filter( let specialOptions = this._providerOptions.filter(
(property) => (property.specialValueType !== null && property.specialValueType !== undefined)); (property) => (property.specialValueType !== null && property.specialValueType !== undefined));
this._connectionWidget = this._instantiationService.createInstance(CmsConnectionWidget, specialOptions, { this._connectionWidget = this._instantiationService.createInstance(CmsConnectionWidget, specialOptions, {

View File

@@ -16,6 +16,7 @@ import { ConnectionOptionSpecialType } from 'sql/workbench/api/common/sqlExtHost
import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension'; import { ConnectionProviderProperties } from 'sql/workbench/parts/connection/common/connectionProviderExtension';
import { ConnectionWidget } from 'sql/workbench/services/connection/browser/connectionWidget'; import { ConnectionWidget } from 'sql/workbench/services/connection/browser/connectionWidget';
import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController'; import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController';
import { ILogService } from 'vs/platform/log/common/log';
export class ConnectionController implements IConnectionComponentController { export class ConnectionController implements IConnectionComponentController {
private _advancedController: AdvancedPropertiesController; private _advancedController: AdvancedPropertiesController;
@@ -33,7 +34,8 @@ export class ConnectionController implements IConnectionComponentController {
providerName: string, providerName: string,
@IConnectionManagementService protected readonly _connectionManagementService: IConnectionManagementService, @IConnectionManagementService protected readonly _connectionManagementService: IConnectionManagementService,
@IInstantiationService protected readonly _instantiationService: IInstantiationService, @IInstantiationService protected readonly _instantiationService: IInstantiationService,
@IServerGroupController protected readonly _serverGroupController: IServerGroupController @IServerGroupController protected readonly _serverGroupController: IServerGroupController,
@ILogService private readonly _logService: ILogService
) { ) {
this._callback = callback; this._callback = callback;
this._providerOptions = connectionProperties.connectionOptions; this._providerOptions = connectionProperties.connectionOptions;
@@ -52,7 +54,7 @@ export class ConnectionController implements IConnectionComponentController {
this._providerName = providerName; this._providerName = providerName;
} }
protected onFetchDatabases(serverName: string, authenticationType: string, userName?: string, password?: string): Promise<string[]> { protected async onFetchDatabases(serverName: string, authenticationType: string, userName?: string, password?: string): Promise<string[]> {
let tempProfile = this._model; let tempProfile = this._model;
tempProfile.serverName = serverName; tempProfile.serverName = serverName;
tempProfile.authenticationType = authenticationType; tempProfile.authenticationType = authenticationType;
@@ -61,39 +63,35 @@ export class ConnectionController implements IConnectionComponentController {
tempProfile.groupFullName = ''; tempProfile.groupFullName = '';
tempProfile.saveProfile = false; tempProfile.saveProfile = false;
let uri = this._connectionManagementService.getConnectionUri(tempProfile); let uri = this._connectionManagementService.getConnectionUri(tempProfile);
return new Promise<string[]>((resolve, reject) => { if (this._databaseCache.has(uri)) {
if (this._databaseCache.has(uri)) { let cachedDatabases: string[] = this._databaseCache.get(uri);
let cachedDatabases: string[] = this._databaseCache.get(uri); if (cachedDatabases !== null) {
if (cachedDatabases !== null) { return cachedDatabases;
resolve(cachedDatabases); } else {
throw new Error('database cache didn\'t have value');
}
} else {
const connResult = await this._connectionManagementService.connect(tempProfile, uri);
if (connResult && connResult.connected) {
const result = await this._connectionManagementService.listDatabases(uri);
if (result && result.databaseNames) {
this._databaseCache.set(uri, result.databaseNames);
return result.databaseNames;
} else { } else {
reject(); this._databaseCache.set(uri, null);
throw new Error('list databases failed');
} }
} else { } else {
this._connectionManagementService.connect(tempProfile, uri).then(connResult => { throw new Error(connResult.errorMessage);
if (connResult && connResult.connected) {
this._connectionManagementService.listDatabases(uri).then(result => {
if (result && result.databaseNames) {
this._databaseCache.set(uri, result.databaseNames);
resolve(result.databaseNames);
} else {
this._databaseCache.set(uri, null);
reject();
}
});
} else {
reject(connResult.errorMessage);
}
});
} }
}); }
} }
protected onCreateNewServerGroup(): void { protected onCreateNewServerGroup(): void {
this._serverGroupController.showCreateGroupDialog({ this._serverGroupController.showCreateGroupDialog({
onAddGroup: (groupName) => this._connectionWidget.updateServerGroup(this.getAllServerGroups(), groupName), onAddGroup: (groupName) => this._connectionWidget.updateServerGroup(this.getAllServerGroups(), groupName),
onClose: () => this._connectionWidget.focusOnServerGroup() onClose: () => this._connectionWidget.focusOnServerGroup()
}); }).catch((e) => this._logService.error(e));
} }
protected handleonSetAzureTimeOut(): void { protected handleonSetAzureTimeOut(): void {

View File

@@ -228,7 +228,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
*/ */
public onSessionCreated(handle: number, session: azdata.ObjectExplorerSession): void { public onSessionCreated(handle: number, session: azdata.ObjectExplorerSession): void {
if (session && session.success) { if (session && session.success) {
this.handleSessionCreated(session); this.handleSessionCreated(session).catch((e) => this.logService.error(e));
} else { } else {
let errorMessage = session && session.errorMessage ? session.errorMessage : errSessionCreateFailed; let errorMessage = session && session.errorMessage ? session.errorMessage : errSessionCreateFailed;
this.logService.error(errorMessage); this.logService.error(errorMessage);
@@ -283,7 +283,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
connection.isDisconnecting = true; connection.isDisconnecting = true;
this._connectionManagementService.disconnect(connection).then((value) => { this._connectionManagementService.disconnect(connection).then((value) => {
connection.isDisconnecting = false; connection.isDisconnecting = false;
}); }).catch((e) => this.logService.error(e));
}); });
} }
} }
@@ -346,7 +346,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
return new Promise<azdata.ObjectExplorerExpandInfo>((resolve, reject) => { return new Promise<azdata.ObjectExplorerExpandInfo>((resolve, reject) => {
let provider = this._providers[providerId]; let provider = this._providers[providerId];
if (provider) { if (provider) {
TelemetryUtils.addTelemetry(this._telemetryService, this.logService, TelemetryKeys.ObjectExplorerExpand, { refresh: 0, provider: providerId }); TelemetryUtils.addTelemetry(this._telemetryService, this.logService, TelemetryKeys.ObjectExplorerExpand, { refresh: 0, provider: providerId }).catch((e) => this.logService.error(e));
this.expandOrRefreshNode(providerId, session, nodePath).then(result => { this.expandOrRefreshNode(providerId, session, nodePath).then(result => {
resolve(result); resolve(result);
}, error => { }, error => {
@@ -484,7 +484,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
public refreshNode(providerId: string, session: azdata.ObjectExplorerSession, nodePath: string): Thenable<azdata.ObjectExplorerExpandInfo> { public refreshNode(providerId: string, session: azdata.ObjectExplorerSession, nodePath: string): Thenable<azdata.ObjectExplorerExpandInfo> {
let provider = this._providers[providerId]; let provider = this._providers[providerId];
if (provider) { if (provider) {
TelemetryUtils.addTelemetry(this._telemetryService, this.logService, TelemetryKeys.ObjectExplorerExpand, { refresh: 1, provider: providerId }); TelemetryUtils.addTelemetry(this._telemetryService, this.logService, TelemetryKeys.ObjectExplorerExpand, { refresh: 1, provider: providerId }).catch((e) => this.logService.error(e));
return this.expandOrRefreshNode(providerId, session, nodePath, true); return this.expandOrRefreshNode(providerId, session, nodePath, true);
} }
return Promise.resolve(undefined); return Promise.resolve(undefined);

View File

@@ -30,6 +30,7 @@ import { ILanguageSelection } from 'vs/editor/common/services/modeService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService'; import { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput'; import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { ILogService } from 'vs/platform/log/common/log';
/** /**
* Service wrapper for opening and creating SQL documents as sql editor inputs * Service wrapper for opening and creating SQL documents as sql editor inputs
@@ -54,7 +55,8 @@ export class QueryEditorService implements IQueryEditorService {
@IInstantiationService private _instantiationService: IInstantiationService, @IInstantiationService private _instantiationService: IInstantiationService,
@IEditorService private _editorService: IEditorService, @IEditorService private _editorService: IEditorService,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService, @IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IConfigurationService private _configurationService: IConfigurationService @IConfigurationService private _configurationService: IConfigurationService,
@ILogService private _logService: ILogService
) { ) {
} }
@@ -139,7 +141,7 @@ export class QueryEditorService implements IQueryEditorService {
} else { } else {
input.onConnectReject(); input.onConnectReject();
} }
}); }).catch((e) => this._logService.error(e));
} }
} }
}); });