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> {
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 => {
this._onAddConnectionProfile.fire(undefined);
return groupId;
@@ -834,13 +834,13 @@ export class ConnectionManagementService extends Disposable implements IConnecti
extensionConnectionTime: connection.extensionTimer.elapsed() - connection.serviceTimer.elapsed(),
serviceConnectionTime: connection.serviceTimer.elapsed()
});
}).catch((e) => this._logService.error(e));
}
private addTelemetryForConnectionDisconnected(connection: interfaces.IConnectionProfile): void {
TelemetryUtils.addTelemetry(this._telemetryService, this._logService, TelemetryKeys.DatabaseDisconnected, {
provider: connection.providerName
});
}).catch((e) => this._logService.error(e));
}
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> {
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);
}
public changeGroupIdForConnection(source: ConnectionProfile, targetGroupId: string): Promise<void> {
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 => {
if (id && targetGroupId) {
source.groupId = targetGroupId;
@@ -971,7 +971,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
});
// 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> {
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
let uri = Utils.generateUri(connection);
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.
*/
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
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 { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { ILogService } from 'vs/platform/log/common/log';
@extHostNamedCustomer(SqlMainContext.MainThreadQueryEditor)
export class MainThreadQueryEditor extends Disposable implements MainThreadQueryEditorShape {
@@ -26,7 +27,8 @@ export class MainThreadQueryEditor extends Disposable implements MainThreadQuery
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@IQueryModelService private _queryModelService: IQueryModelService,
@IEditorService private _editorService: IEditorService,
@IQueryManagementService private _queryManagementService: IQueryManagementService
@IQueryManagementService private _queryManagementService: IQueryManagementService,
@ILogService private _logService: ILogService
) {
super();
if (extHostContext) {
@@ -101,9 +103,9 @@ export class MainThreadQueryEditor extends Disposable implements MainThreadQuery
if (editor instanceof QueryEditor) {
let queryEditor: QueryEditor = editor;
if (runCurrentQuery) {
queryEditor.runCurrentQuery();
queryEditor.runCurrentQuery().catch((e) => this._logService.error(e));
} 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 { SimpleEditorProgressService } from 'vs/editor/standalone/browser/simpleServices';
import { IProgressService } from 'vs/platform/progress/common/progress';
import { ILogService } from 'vs/platform/log/common/log';
@Component({
template: '',
@@ -45,33 +46,33 @@ export default class EditorComponent extends ComponentBase implements IComponent
@Inject(forwardRef(() => ElementRef)) el: ElementRef,
@Inject(IInstantiationService) private _instantiationService: IInstantiationService,
@Inject(IModelService) private _modelService: IModelService,
@Inject(IModeService) private _modeService: IModeService
@Inject(IModeService) private _modeService: IModeService,
@Inject(ILogService) private _logService: ILogService
) {
super(changeRef, el);
}
ngOnInit(): void {
this.baseInit();
this._createEditor();
this._createEditor().catch((e) => this._logService.error(e));
this._register(DOM.addDisposableListener(window, DOM.EventType.RESIZE, e => {
this.layout();
}));
}
private _createEditor(): void {
private async _createEditor(): Promise<void> {
let instantiationService = this._instantiationService.createChild(new ServiceCollection([IProgressService, new SimpleEditorProgressService()]));
this._editor = instantiationService.createInstance(QueryTextEditor);
this._editor.create(this._el.nativeElement);
this._editor.setVisible(true);
let uri = this.createUri();
this._editorInput = instantiationService.createInstance(UntitledEditorInput, uri, false, 'plaintext', '', '');
this._editor.setInput(this._editorInput, undefined);
this._editorInput.resolve().then(model => {
this._editorModel = model.textEditorModel;
this.fireEvent({
eventType: ComponentEventType.onComponentCreated,
args: this._uri
});
await this._editor.setInput(this._editorInput, undefined);
const model = await this._editorInput.resolve();
this._editorModel = model.textEditorModel;
this.fireEvent({
eventType: ComponentEventType.onComponentCreated,
args: this._uri
});
this._register(this._editor);

View File

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

View File

@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
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 * as nls from 'vs/nls';
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 { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
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)
const scriptCompatibilityOptionMap = {
@@ -41,71 +40,53 @@ const targetDatabaseEngineEditionMap = {
/**
* Select the top rows from an object
*/
export function scriptSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<void> {
return new Promise<void>((resolve, reject) => {
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => {
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails).then(result => {
if (result && result.script) {
queryEditorService.newSqlEditor(result.script).then((owner: IConnectableInput) => {
// Connect our editor to the input connection
let options: IConnectionCompletionOptions = {
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery, input: owner },
saveTheConnection: false,
showDashboard: false,
showConnectionDialogOnError: true,
showFirewallRuleOnError: true
};
connectionService.connect(connectionProfile, owner.uri, options).then(() => {
resolve();
});
}).catch(editorError => {
reject(editorError);
});
} 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);
});
});
});
export async function scriptSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<boolean> {
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails);
if (result && result.script) {
const owner = await queryEditorService.newSqlEditor(result.script);
// Connect our editor to the input connection
let options: IConnectionCompletionOptions = {
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.executeQuery, input: owner },
saveTheConnection: false,
showDashboard: false,
showConnectionDialogOnError: true,
showFirewallRuleOnError: true
};
const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
return Boolean(innerConnectionResult) && innerConnectionResult.connected;
} else {
let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
throw new Error(errMsg.concat(metadata.metadataTypeName));
}
}
/**
* Opens a new Edit Data session
*/
export function scriptEditSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<void> {
return new Promise<void>((resolve, reject) => {
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => {
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails).then(result => {
if (result && result.script) {
queryEditorService.newEditDataEditor(metadata.schema, metadata.name, result.script).then((owner: EditDataInput) => {
// Connect our editor
let options: IConnectionCompletionOptions = {
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
saveTheConnection: false,
showDashboard: false,
showConnectionDialogOnError: true,
showFirewallRuleOnError: true
};
connectionService.connect(connectionProfile, owner.uri, options).then(() => {
resolve();
});
}).catch(editorError => {
reject(editorError);
});
} 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);
});
});
});
export async function scriptEditSelect(connectionProfile: IConnectionProfile, metadata: azdata.ObjectMetadata, connectionService: IConnectionManagementService, queryEditorService: IQueryEditorService, scriptingService: IScriptingService): Promise<boolean> {
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
let paramDetails: azdata.ScriptingParamDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
const result = await scriptingService.script(connectionResult, metadata, ScriptOperation.Select, paramDetails);
if (result && result.script) {
const owner = await queryEditorService.newEditDataEditor(metadata.schema, metadata.name, result.script);
// Connect our editor
let options: IConnectionCompletionOptions = {
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
saveTheConnection: false,
showDashboard: false,
showConnectionDialogOnError: true,
showFirewallRuleOnError: true
};
const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
return Boolean(innerConnectionResult) && innerConnectionResult.connected;
} else {
let errMsg: string = nls.localize('scriptSelectNotFound', "No script was returned when calling select script on object ");
throw new Error(errMsg.concat(metadata.metadataTypeName));
}
}
@@ -132,61 +113,51 @@ export function GetScriptOperationName(operation: ScriptOperation) {
/**
* 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,
queryEditorService: IQueryEditorService,
scriptingService: IScriptingService,
operation: ScriptOperation,
errorMessageService: IErrorMessageService): Promise<void> {
return new Promise<void>((resolve, reject) => {
connectionService.connectIfNotConnected(connectionProfile).then(connectionResult => {
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
scriptingService.script(connectionResult, metadata, operation, paramDetails).then(result => {
if (result) {
let script: string = result.script;
errorMessageService: IErrorMessageService): Promise<boolean> {
const connectionResult = await connectionService.connectIfNotConnected(connectionProfile);
let paramDetails = getScriptingParamDetails(connectionService, connectionResult, metadata);
const result = await scriptingService.script(connectionResult, metadata, operation, paramDetails);
if (result) {
let script: string = result.script;
if (script) {
let description = (metadata.schema && metadata.schema !== '') ? `${metadata.schema}.${metadata.name}` : metadata.name;
queryEditorService.newSqlEditor(script, connectionProfile.providerName, undefined, description).then((owner) => {
// Connect our editor to the input connection
let options: IConnectionCompletionOptions = {
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
saveTheConnection: false,
showDashboard: false,
showConnectionDialogOnError: true,
showFirewallRuleOnError: true
};
connectionService.connect(connectionProfile, owner.uri, options).then(() => {
resolve();
});
}).catch(editorError => {
reject(editorError);
});
} else {
let scriptNotFoundMsg = nls.localize('scriptNotFoundForObject', "No script was returned when scripting as {0} on object {1}",
GetScriptOperationName(operation), metadata.metadataTypeName);
let messageDetail = '';
let operationResult = scriptingService.getOperationFailedResult(result.operationId);
if (operationResult && operationResult.hasError && operationResult.errorMessage) {
scriptNotFoundMsg = operationResult.errorMessage;
messageDetail = operationResult.errorDetails;
}
if (errorMessageService) {
let title = nls.localize('scriptingFailed', "Scripting Failed");
errorMessageService.showDialog(Severity.Error, title, scriptNotFoundMsg, messageDetail);
}
reject(scriptNotFoundMsg);
}
} else {
reject(nls.localize('scriptNotFound', "No script was returned when scripting as {0}", GetScriptOperationName(operation)));
}
}, scriptingError => {
reject(scriptingError);
});
}).catch(connectionError => {
reject(connectionError);
});
});
if (script) {
let description = (metadata.schema && metadata.schema !== '') ? `${metadata.schema}.${metadata.name}` : metadata.name;
const owner = await queryEditorService.newSqlEditor(script, connectionProfile.providerName, undefined, description);
// Connect our editor to the input connection
let options: IConnectionCompletionOptions = {
params: { connectionType: ConnectionType.editor, runQueryOnCompletion: RunQueryOnConnectionMode.none, input: owner },
saveTheConnection: false,
showDashboard: false,
showConnectionDialogOnError: true,
showFirewallRuleOnError: true
};
const innerConnectionResult = await connectionService.connect(connectionProfile, owner.uri, options);
return Boolean(innerConnectionResult) && innerConnectionResult.connected;
} else {
let scriptNotFoundMsg = nls.localize('scriptNotFoundForObject', "No script was returned when scripting as {0} on object {1}",
GetScriptOperationName(operation), metadata.metadataTypeName);
let messageDetail = '';
let operationResult = scriptingService.getOperationFailedResult(result.operationId);
if (operationResult && operationResult.hasError && operationResult.errorMessage) {
scriptNotFoundMsg = operationResult.errorMessage;
messageDetail = operationResult.errorDetails;
}
if (errorMessageService) {
let title = nls.localize('scriptingFailed', "Scripting Failed");
errorMessageService.showDialog(Severity.Error, title, scriptNotFoundMsg, messageDetail);
}
throw new Error(scriptNotFoundMsg);
}
} else {
throw new Error(nls.localize('scriptNotFound', "No script was returned when scripting as {0}", GetScriptOperationName(operation)));
}
}
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);
}
public setInput(input: DashboardInput, options: EditorOptions): Promise<void> {
public async setInput(input: DashboardInput, options: EditorOptions): Promise<void> {
if (this.input && this.input.matches(input)) {
return Promise.resolve(undefined);
}
@@ -93,10 +93,10 @@ export class DashboardEditor extends BaseEditor {
container.style.height = '100%';
this._dashboardContainer = DOM.append(parentElement, container);
this.input.container = this._dashboardContainer;
return Promise.resolve(input.initializedPromise.then(() => this.bootstrapAngular(input)));
await input.initializedPromise;
this.bootstrapAngular(input);
} else {
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
*/
public runCurrentQuery(): void {
this._runQueryAction.runCurrent();
public async runCurrentQuery(): Promise<void> {
return this._runQueryAction.runCurrent();
}
/**
* Calls the runCurrentQueryWithActualPlan method of this editor's ActualQueryPlanAction
*/
public runCurrentQueryWithActualPlan(): void {
this._actualQueryPlanAction.run();
public async runCurrentQueryWithActualPlan(): Promise<void> {
return this._actualQueryPlanAction.run();
}
/**
* Calls the run method of this editor's RunQueryAction
*/
public runQuery(): void {
this._runQueryAction.run();
public async runQuery(): Promise<void> {
return this._runQueryAction.run();
}
/**
* Calls the run method of this editor's CancelQueryAction
*/
public cancelQuery(): void {
this._cancelQueryAction.run();
public async cancelQuery(): Promise<void> {
return this._cancelQueryAction.run();
}
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 { CmsConnectionWidget } from 'sql/workbench/services/connection/browser/cmsConnectionWidget';
import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController';
import { ILogService } from 'vs/platform/log/common/log';
/**
* Connection Controller for CMS Connections
@@ -22,9 +23,10 @@ export class CmsConnectionController extends ConnectionController {
providerName: string,
@IConnectionManagementService _connectionManagementService: IConnectionManagementService,
@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(
(property) => (property.specialValueType !== null && property.specialValueType !== undefined));
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 { ConnectionWidget } from 'sql/workbench/services/connection/browser/connectionWidget';
import { IServerGroupController } from 'sql/platform/serverGroup/common/serverGroupController';
import { ILogService } from 'vs/platform/log/common/log';
export class ConnectionController implements IConnectionComponentController {
private _advancedController: AdvancedPropertiesController;
@@ -33,7 +34,8 @@ export class ConnectionController implements IConnectionComponentController {
providerName: string,
@IConnectionManagementService protected readonly _connectionManagementService: IConnectionManagementService,
@IInstantiationService protected readonly _instantiationService: IInstantiationService,
@IServerGroupController protected readonly _serverGroupController: IServerGroupController
@IServerGroupController protected readonly _serverGroupController: IServerGroupController,
@ILogService private readonly _logService: ILogService
) {
this._callback = callback;
this._providerOptions = connectionProperties.connectionOptions;
@@ -52,7 +54,7 @@ export class ConnectionController implements IConnectionComponentController {
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;
tempProfile.serverName = serverName;
tempProfile.authenticationType = authenticationType;
@@ -61,39 +63,35 @@ export class ConnectionController implements IConnectionComponentController {
tempProfile.groupFullName = '';
tempProfile.saveProfile = false;
let uri = this._connectionManagementService.getConnectionUri(tempProfile);
return new Promise<string[]>((resolve, reject) => {
if (this._databaseCache.has(uri)) {
let cachedDatabases: string[] = this._databaseCache.get(uri);
if (cachedDatabases !== null) {
resolve(cachedDatabases);
if (this._databaseCache.has(uri)) {
let cachedDatabases: string[] = this._databaseCache.get(uri);
if (cachedDatabases !== null) {
return 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 {
reject();
this._databaseCache.set(uri, null);
throw new Error('list databases failed');
}
} else {
this._connectionManagementService.connect(tempProfile, uri).then(connResult => {
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);
}
});
throw new Error(connResult.errorMessage);
}
});
}
}
protected onCreateNewServerGroup(): void {
this._serverGroupController.showCreateGroupDialog({
onAddGroup: (groupName) => this._connectionWidget.updateServerGroup(this.getAllServerGroups(), groupName),
onClose: () => this._connectionWidget.focusOnServerGroup()
});
}).catch((e) => this._logService.error(e));
}
protected handleonSetAzureTimeOut(): void {

View File

@@ -228,7 +228,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
*/
public onSessionCreated(handle: number, session: azdata.ObjectExplorerSession): void {
if (session && session.success) {
this.handleSessionCreated(session);
this.handleSessionCreated(session).catch((e) => this.logService.error(e));
} else {
let errorMessage = session && session.errorMessage ? session.errorMessage : errSessionCreateFailed;
this.logService.error(errorMessage);
@@ -283,7 +283,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
connection.isDisconnecting = true;
this._connectionManagementService.disconnect(connection).then((value) => {
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) => {
let provider = this._providers[providerId];
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 => {
resolve(result);
}, error => {
@@ -484,7 +484,7 @@ export class ObjectExplorerService implements IObjectExplorerService {
public refreshNode(providerId: string, session: azdata.ObjectExplorerSession, nodePath: string): Thenable<azdata.ObjectExplorerExpandInfo> {
let provider = this._providers[providerId];
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 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 { IEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
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
@@ -54,7 +55,8 @@ export class QueryEditorService implements IQueryEditorService {
@IInstantiationService private _instantiationService: IInstantiationService,
@IEditorService private _editorService: IEditorService,
@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 {
input.onConnectReject();
}
});
}).catch((e) => this._logService.error(e));
}
}
});