Public api changes to namespace accounts & connection. (#2383)

* 1.Added following functions to namespace accounts
function getAllAccounts(): Thenable<AccountWithProviderHandle[]>;
function getSecurityToken(account: AccountWithProviderHandle): Thenable<{}>;
2.Added class AccountWithProviderHandle as the wrapper for Account
3.Changed function openConnectionDialog of namespace connection to allow connection dialog initialized with specified parameters, i.e., server name, database name, etc.
function openConnectionDialog(provider?: string[], initialConnectionProfile?: IConnectionProfile): Thenable<connection.Connection>;

* Added unit tests for ExtHostAccountManagement.$getAllAccounts
This commit is contained in:
Vincent Feng
2018-09-03 11:48:00 +08:00
committed by GitHub
parent b27f69aace
commit 8600dbb04e
9 changed files with 170 additions and 9 deletions

View File

@@ -64,6 +64,33 @@ export class ExtHostAccountManagement extends ExtHostAccountManagementShape {
this._proxy.$accountUpdated(updatedAccount);
}
public $getAllAccounts(): Thenable<sqlops.AccountWithProviderHandle[]> {
if (Object.keys(this._providers).length === 0) {
throw new Error('No account providers registered.');
}
let accountWithProviderHandles: sqlops.AccountWithProviderHandle[] = [];
let promises: Thenable<void>[] = [];
for (let providerKey in this._providers) {
let providerHandle = parseInt(providerKey);
let provider = this._providers[providerHandle];
promises.push(this._proxy.$getAccountsForProvider(provider.metadata.id).then(
(accounts) => {
accounts.forEach((account) => {
accountWithProviderHandles.push({
account: account,
providerHandle: providerHandle
});
});
}
));
}
return Promise.all(promises).then(() => accountWithProviderHandles);
}
public $registerAccountProvider(providerMetadata: sqlops.AccountProviderMetadata, provider: sqlops.AccountProvider): Disposable {
let self = this;

View File

@@ -32,8 +32,8 @@ export class ExtHostConnectionManagement extends ExtHostConnectionManagementShap
return this._proxy.$getCredentials(connectionId);
}
public $openConnectionDialog(providers?: string[]): Thenable<sqlops.connection.Connection> {
return this._proxy.$openConnectionDialog(providers);
public $openConnectionDialog(providers?: string[], initialConnectionProfile?: sqlops.IConnectionProfile): Thenable<sqlops.connection.Connection> {
return this._proxy.$openConnectionDialog(providers, initialConnectionProfile);
}
public $listDatabases(connectionId: string): Thenable<string[]> {

View File

@@ -46,6 +46,10 @@ export class MainThreadAccountManagement implements MainThreadAccountManagementS
this._accountManagementService.accountUpdated(updatedAccount);
}
public $getAccountsForProvider(providerId: string): Thenable<sqlops.Account[]> {
return this._accountManagementService.getAccountsForProvider(providerId);
}
public $registerAccountProvider(providerMetadata: sqlops.AccountProviderMetadata, handle: number): Thenable<any> {
let self = this;

View File

@@ -51,8 +51,8 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag
}
public async $openConnectionDialog(providers: string[]): Promise<sqlops.connection.Connection> {
let connectionProfile = await this._connectionDialogService.openDialogAndWait(this._connectionManagementService, { connectionType: 1, providers: providers });
public async $openConnectionDialog(providers: string[], initialConnectionProfile?: IConnectionProfile): Promise<sqlops.connection.Connection> {
let connectionProfile = await this._connectionDialogService.openDialogAndWait(this._connectionManagementService, { connectionType: 1, providers: providers }, initialConnectionProfile);
return connectionProfile ? {
connectionId: connectionProfile.id,
options: connectionProfile.options,

View File

@@ -90,6 +90,12 @@ export function createApiFactory(
},
accountUpdated(updatedAccount: sqlops.Account): void {
return extHostAccountManagement.$accountUpdated(updatedAccount);
},
getAllAccounts(): Thenable<sqlops.AccountWithProviderHandle[]> {
return extHostAccountManagement.$getAllAccounts();
},
getSecurityToken(account: sqlops.AccountWithProviderHandle): Thenable<{}> {
return extHostAccountManagement.$getSecurityToken(account.providerHandle, account.account);
}
};
@@ -104,8 +110,8 @@ export function createApiFactory(
getCredentials(connectionId: string): Thenable<{ [name: string]: string }> {
return extHostConnectionManagement.$getCredentials(connectionId);
},
openConnectionDialog(providers?: string[]): Thenable<sqlops.connection.Connection> {
return extHostConnectionManagement.$openConnectionDialog(providers);
openConnectionDialog(providers?: string[], initialConnectionProfile?: sqlops.IConnectionProfile): Thenable<sqlops.connection.Connection> {
return extHostConnectionManagement.$openConnectionDialog(providers, initialConnectionProfile);
},
listDatabases(connectionId: string): Thenable<string[]> {
return extHostConnectionManagement.$listDatabases(connectionId);

View File

@@ -446,6 +446,8 @@ export interface MainThreadAccountManagementShape extends IDisposable {
$endAutoOAuthDeviceCode(): void;
$accountUpdated(updatedAccount: sqlops.Account): void;
$getAccountsForProvider(providerId: string): Thenable<sqlops.Account[]>;
}
export interface MainThreadResourceProviderShape extends IDisposable {
@@ -499,7 +501,7 @@ export interface MainThreadConnectionManagementShape extends IDisposable {
$getActiveConnections(): Thenable<sqlops.connection.Connection[]>;
$getCurrentConnection(): Thenable<sqlops.connection.Connection>;
$getCredentials(connectionId: string): Thenable<{ [name: string]: string }>;
$openConnectionDialog(providers: string[]): Thenable<sqlops.connection.Connection>;
$openConnectionDialog(providers: string[], initialConnectionProfile?: sqlops.IConnectionProfile): Thenable<sqlops.connection.Connection>;
$listDatabases(connectionId: string): Thenable<string[]>;
$getConnectionString(connectionId: string, includePassword: boolean): Thenable<string>;
$getUriForConnection(connectionId: string): Thenable<string>;
@@ -687,4 +689,4 @@ export interface ExtHostQueryEditorShape {
export interface MainThreadQueryEditorShape extends IDisposable {
$connect(fileUri: string, connectionId: string): Thenable<void>;
$runQuery(fileUri: string): void;
}
}