mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-18 01:25:37 -05:00
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:
@@ -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, {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user