mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Add connection API method to get URI (#2021)
This commit is contained in:
@@ -152,10 +152,12 @@ export interface IConnectionManagementService {
|
|||||||
|
|
||||||
getAdvancedProperties(): sqlops.ConnectionOption[];
|
getAdvancedProperties(): sqlops.ConnectionOption[];
|
||||||
|
|
||||||
getConnectionId(connectionProfile: IConnectionProfile): string;
|
getConnectionUri(connectionProfile: IConnectionProfile): string;
|
||||||
|
|
||||||
getFormattedUri(uri: string, connectionProfile: IConnectionProfile): string;
|
getFormattedUri(uri: string, connectionProfile: IConnectionProfile): string;
|
||||||
|
|
||||||
|
getConnectionUriFromId(connectionId: string): string;
|
||||||
|
|
||||||
isConnected(fileUri: string): boolean;
|
isConnected(fileUri: string): boolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -648,6 +648,15 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
return this._connectionStatusManager.getActiveConnectionProfiles();
|
return this._connectionStatusManager.getActiveConnectionProfiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getConnectionUriFromId(connectionId: string): string {
|
||||||
|
let connection = this.getActiveConnections().find(connection => connection.id === connectionId);
|
||||||
|
if (connection) {
|
||||||
|
return this.getConnectionUri(connection);
|
||||||
|
} else {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public saveProfileGroup(profile: IConnectionProfileGroup): Promise<string> {
|
public saveProfileGroup(profile: IConnectionProfileGroup): Promise<string> {
|
||||||
TelemetryUtils.addTelemetry(this._telemetryService, TelemetryKeys.AddServerGroup);
|
TelemetryUtils.addTelemetry(this._telemetryService, TelemetryKeys.AddServerGroup);
|
||||||
return new Promise<string>((resolve, reject) => {
|
return new Promise<string>((resolve, reject) => {
|
||||||
@@ -704,7 +713,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getConnectionId(connectionProfile: IConnectionProfile): string {
|
public getConnectionUri(connectionProfile: IConnectionProfile): string {
|
||||||
return this._connectionStatusManager.getOriginalOwnerUri(Utils.generateUri(connectionProfile));
|
return this._connectionStatusManager.getOriginalOwnerUri(Utils.generateUri(connectionProfile));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -716,7 +725,7 @@ export class ConnectionManagementService extends Disposable implements IConnecti
|
|||||||
*/
|
*/
|
||||||
public getFormattedUri(uri: string, connectionProfile: IConnectionProfile): string {
|
public getFormattedUri(uri: string, connectionProfile: IConnectionProfile): string {
|
||||||
if (this._connectionStatusManager.isDefaultTypeUri(uri)) {
|
if (this._connectionStatusManager.isDefaultTypeUri(uri)) {
|
||||||
return this.getConnectionId(connectionProfile);
|
return this.getConnectionUri(connectionProfile);
|
||||||
} else {
|
} else {
|
||||||
return uri;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ export class ConnectionController implements IConnectionComponentController {
|
|||||||
tempProfile.password = password;
|
tempProfile.password = password;
|
||||||
tempProfile.groupFullName = '';
|
tempProfile.groupFullName = '';
|
||||||
tempProfile.saveProfile = false;
|
tempProfile.saveProfile = false;
|
||||||
let uri = this._connectionManagementService.getConnectionId(tempProfile);
|
let uri = this._connectionManagementService.getConnectionUri(tempProfile);
|
||||||
return new Promise<string[]>((resolve, reject) => {
|
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);
|
||||||
|
|||||||
@@ -146,7 +146,7 @@ export class BackupUiService implements IBackupUiService {
|
|||||||
|
|
||||||
let backupOptions = this.getOptions(this._currentProvider);
|
let backupOptions = this.getOptions(this._currentProvider);
|
||||||
return new TPromise<void>(() => {
|
return new TPromise<void>(() => {
|
||||||
let uri = this._connectionManagementService.getConnectionId(connection)
|
let uri = this._connectionManagementService.getConnectionUri(connection)
|
||||||
+ ProviderConnectionInfo.idSeparator
|
+ ProviderConnectionInfo.idSeparator
|
||||||
+ ConnectionUtils.ConnectionUriBackupIdAttributeName
|
+ ConnectionUtils.ConnectionUriBackupIdAttributeName
|
||||||
+ ProviderConnectionInfo.nameValueSeparator
|
+ ProviderConnectionInfo.nameValueSeparator
|
||||||
|
|||||||
@@ -293,7 +293,7 @@ export class RestoreDialogController implements IRestoreDialogController {
|
|||||||
return new TPromise<void>((resolve, reject) => {
|
return new TPromise<void>((resolve, reject) => {
|
||||||
let result: void;
|
let result: void;
|
||||||
|
|
||||||
this._ownerUri = this._connectionService.getConnectionId(connection)
|
this._ownerUri = this._connectionService.getConnectionUri(connection)
|
||||||
+ ProviderConnectionInfo.idSeparator
|
+ ProviderConnectionInfo.idSeparator
|
||||||
+ Utils.ConnectionUriRestoreIdAttributeName
|
+ Utils.ConnectionUriRestoreIdAttributeName
|
||||||
+ ProviderConnectionInfo.nameValueSeparator
|
+ ProviderConnectionInfo.nameValueSeparator
|
||||||
|
|||||||
@@ -185,7 +185,7 @@ export class OEScriptSelectAction extends ScriptSelectAction {
|
|||||||
}
|
}
|
||||||
this._treeSelectionHandler.onTreeActionStateChange(true);
|
this._treeSelectionHandler.onTreeActionStateChange(true);
|
||||||
var connectionProfile = TreeUpdateUtils.getConnectionProfile(this._objectExplorerTreeNode);
|
var connectionProfile = TreeUpdateUtils.getConnectionProfile(this._objectExplorerTreeNode);
|
||||||
var ownerUri = this._connectionManagementService.getConnectionId(connectionProfile);
|
var ownerUri = this._connectionManagementService.getConnectionUri(connectionProfile);
|
||||||
ownerUri = this._connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
ownerUri = this._connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
||||||
var metadata = this._objectExplorerTreeNode.metadata;
|
var metadata = this._objectExplorerTreeNode.metadata;
|
||||||
|
|
||||||
@@ -255,7 +255,7 @@ export class OEScriptCreateAction extends ScriptCreateAction {
|
|||||||
this._treeSelectionHandler.onTreeActionStateChange(true);
|
this._treeSelectionHandler.onTreeActionStateChange(true);
|
||||||
var connectionProfile = TreeUpdateUtils.getConnectionProfile(<TreeNode>this._objectExplorerTreeNode);
|
var connectionProfile = TreeUpdateUtils.getConnectionProfile(<TreeNode>this._objectExplorerTreeNode);
|
||||||
var metadata = (<TreeNode>this._objectExplorerTreeNode).metadata;
|
var metadata = (<TreeNode>this._objectExplorerTreeNode).metadata;
|
||||||
var ownerUri = this._connectionManagementService.getConnectionId(connectionProfile);
|
var ownerUri = this._connectionManagementService.getConnectionUri(connectionProfile);
|
||||||
ownerUri = this._connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
ownerUri = this._connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
||||||
|
|
||||||
return super.run({ profile: connectionProfile, object: metadata }).then((result) => {
|
return super.run({ profile: connectionProfile, object: metadata }).then((result) => {
|
||||||
@@ -291,7 +291,7 @@ export class OEScriptExecuteAction extends ScriptExecuteAction {
|
|||||||
this._treeSelectionHandler.onTreeActionStateChange(true);
|
this._treeSelectionHandler.onTreeActionStateChange(true);
|
||||||
var connectionProfile = TreeUpdateUtils.getConnectionProfile(<TreeNode>this._objectExplorerTreeNode);
|
var connectionProfile = TreeUpdateUtils.getConnectionProfile(<TreeNode>this._objectExplorerTreeNode);
|
||||||
var metadata = (<TreeNode>this._objectExplorerTreeNode).metadata;
|
var metadata = (<TreeNode>this._objectExplorerTreeNode).metadata;
|
||||||
var ownerUri = this._connectionManagementService.getConnectionId(connectionProfile);
|
var ownerUri = this._connectionManagementService.getConnectionUri(connectionProfile);
|
||||||
ownerUri = this._connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
ownerUri = this._connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
||||||
|
|
||||||
return super.run({ profile: connectionProfile, object: metadata }).then((result) => {
|
return super.run({ profile: connectionProfile, object: metadata }).then((result) => {
|
||||||
@@ -327,7 +327,7 @@ export class OEScriptAlterAction extends ScriptAlterAction {
|
|||||||
this._treeSelectionHandler.onTreeActionStateChange(true);
|
this._treeSelectionHandler.onTreeActionStateChange(true);
|
||||||
var connectionProfile = TreeUpdateUtils.getConnectionProfile(<TreeNode>this._objectExplorerTreeNode);
|
var connectionProfile = TreeUpdateUtils.getConnectionProfile(<TreeNode>this._objectExplorerTreeNode);
|
||||||
var metadata = (<TreeNode>this._objectExplorerTreeNode).metadata;
|
var metadata = (<TreeNode>this._objectExplorerTreeNode).metadata;
|
||||||
var ownerUri = this._connectionManagementService.getConnectionId(connectionProfile);
|
var ownerUri = this._connectionManagementService.getConnectionUri(connectionProfile);
|
||||||
ownerUri = this._connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
ownerUri = this._connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
||||||
|
|
||||||
return super.run({ profile: connectionProfile, object: metadata }).then((result) => {
|
return super.run({ profile: connectionProfile, object: metadata }).then((result) => {
|
||||||
@@ -363,7 +363,7 @@ export class OEScriptDeleteAction extends ScriptDeleteAction {
|
|||||||
this._treeSelectionHandler.onTreeActionStateChange(true);
|
this._treeSelectionHandler.onTreeActionStateChange(true);
|
||||||
var connectionProfile = TreeUpdateUtils.getConnectionProfile(<TreeNode>this._objectExplorerTreeNode);
|
var connectionProfile = TreeUpdateUtils.getConnectionProfile(<TreeNode>this._objectExplorerTreeNode);
|
||||||
var metadata = (<TreeNode>this._objectExplorerTreeNode).metadata;
|
var metadata = (<TreeNode>this._objectExplorerTreeNode).metadata;
|
||||||
var ownerUri = this._connectionManagementService.getConnectionId(connectionProfile);
|
var ownerUri = this._connectionManagementService.getConnectionUri(connectionProfile);
|
||||||
ownerUri = this._connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
ownerUri = this._connectionManagementService.getFormattedUri(ownerUri, connectionProfile);
|
||||||
|
|
||||||
return super.run({ profile: connectionProfile, object: metadata }).then((result) => {
|
return super.run({ profile: connectionProfile, object: metadata }).then((result) => {
|
||||||
|
|||||||
@@ -51,14 +51,13 @@ export class MainThreadConnectionManagement implements MainThreadConnectionManag
|
|||||||
|
|
||||||
public async $listDatabases(connectionId: string): Promise<string[]> {
|
public async $listDatabases(connectionId: string): Promise<string[]> {
|
||||||
let connection = this._connectionManagementService.getActiveConnections().find(profile => profile.id === connectionId);
|
let connection = this._connectionManagementService.getActiveConnections().find(profile => profile.id === connectionId);
|
||||||
let connectionUri = this._connectionManagementService.getConnectionId(connection);
|
let connectionUri = this._connectionManagementService.getConnectionUri(connection);
|
||||||
let result = await this._connectionManagementService.listDatabases(connectionUri);
|
let result = await this._connectionManagementService.listDatabases(connectionUri);
|
||||||
return result.databaseNames;
|
return result.databaseNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
public $getUriForConnection(connectionId: string): Thenable<string> {
|
public $getUriForConnection(connectionId: string): Thenable<string> {
|
||||||
let connection = this._connectionManagementService.getActiveConnections().find(profile => profile.id === connectionId);
|
return Promise.resolve(this._connectionManagementService.getConnectionUriFromId(connectionId));
|
||||||
return Promise.resolve(this._connectionManagementService.getConnectionId(connection));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private convertConnection(profile: IConnectionProfile): sqlops.connection.Connection {
|
private convertConnection(profile: IConnectionProfile): sqlops.connection.Connection {
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ export function GetScriptOperationName(operation: ScriptOperation) {
|
|||||||
|
|
||||||
export function connectIfNotAlreadyConnected(connectionProfile: IConnectionProfile, connectionService: IConnectionManagementService): Promise<void> {
|
export function connectIfNotAlreadyConnected(connectionProfile: IConnectionProfile, connectionService: IConnectionManagementService): Promise<void> {
|
||||||
return new Promise<void>((resolve, reject) => {
|
return new Promise<void>((resolve, reject) => {
|
||||||
let connectionID = connectionService.getConnectionId(connectionProfile);
|
let connectionID = connectionService.getConnectionUri(connectionProfile);
|
||||||
let uri: string = connectionService.getFormattedUri(connectionID, connectionProfile);
|
let uri: string = connectionService.getFormattedUri(connectionID, connectionProfile);
|
||||||
if (!connectionService.isConnected(uri)) {
|
if (!connectionService.isConnected(uri)) {
|
||||||
let options: IConnectionCompletionOptions = {
|
let options: IConnectionCompletionOptions = {
|
||||||
|
|||||||
@@ -756,8 +756,8 @@ suite('SQL ConnectionManagementService tests', () => {
|
|||||||
connect(ownerUri, undefined, false, connectionProfileWithoutDb).then(() => {
|
connect(ownerUri, undefined, false, connectionProfileWithoutDb).then(() => {
|
||||||
try {
|
try {
|
||||||
// If I get the URI for the connection with or without a database from the connection management service
|
// If I get the URI for the connection with or without a database from the connection management service
|
||||||
let actualUriWithDb = connectionManagementService.getConnectionId(connectionProfileWithDb);
|
let actualUriWithDb = connectionManagementService.getConnectionUri(connectionProfileWithDb);
|
||||||
let actualUriWithoutDb = connectionManagementService.getConnectionId(connectionProfileWithoutDb);
|
let actualUriWithoutDb = connectionManagementService.getConnectionUri(connectionProfileWithoutDb);
|
||||||
|
|
||||||
// Then the retrieved URIs should match the one on the connection
|
// Then the retrieved URIs should match the one on the connection
|
||||||
let expectedUri = Utils.generateUri(connectionProfileWithoutDb);
|
let expectedUri = Utils.generateUri(connectionProfileWithoutDb);
|
||||||
@@ -804,4 +804,33 @@ suite('SQL ConnectionManagementService tests', () => {
|
|||||||
let credentials = connectionManagementService.getActiveConnectionCredentials(profile.id);
|
let credentials = connectionManagementService.getActiveConnectionCredentials(profile.id);
|
||||||
assert.equal(credentials['password'], profile.options['password']);
|
assert.equal(credentials['password'], profile.options['password']);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getConnectionUriFromId returns a URI of an active connection with the given id', () => {
|
||||||
|
let profile = Object.assign({}, connectionProfile);
|
||||||
|
profile.options = {password: profile.password};
|
||||||
|
profile.id = 'test_id';
|
||||||
|
let uri = 'test_initial_uri';
|
||||||
|
connectionStatusManager.addConnection(profile, uri);
|
||||||
|
(connectionManagementService as any)._connectionStatusManager = connectionStatusManager;
|
||||||
|
|
||||||
|
// If I call getConnectionUriFromId on the given connection
|
||||||
|
let foundUri = connectionManagementService.getConnectionUriFromId(profile.id);
|
||||||
|
|
||||||
|
// Then the returned URI matches the connection's
|
||||||
|
assert.equal(foundUri, Utils.generateUri(new ConnectionProfile(capabilitiesService, profile)));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('getConectionUriFromId returns undefined if the given connection is not active', () => {
|
||||||
|
let profile = Object.assign({}, connectionProfile);
|
||||||
|
profile.options = {password: profile.password};
|
||||||
|
profile.id = 'test_id';
|
||||||
|
connectionStatusManager.addConnection(profile, Utils.generateUri(profile));
|
||||||
|
(connectionManagementService as any)._connectionStatusManager = connectionStatusManager;
|
||||||
|
|
||||||
|
// If I call getConnectionUriFromId with a different URI than the connection's
|
||||||
|
let foundUri = connectionManagementService.getConnectionUriFromId('different_id');
|
||||||
|
|
||||||
|
// Then undefined is returned
|
||||||
|
assert.equal(foundUri, undefined);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -115,7 +115,7 @@ export class TestConnectionManagementService implements IConnectionManagementSer
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
getConnectionId(connectionProfile: ConnectionProfile): string {
|
getConnectionUri(connectionProfile: ConnectionProfile): string {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,6 +123,10 @@ export class TestConnectionManagementService implements IConnectionManagementSer
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getConnectionUriFromId(connectionId: string): string {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
isConnected(fileUri: string, connectionProfile?: ConnectionProfile): boolean {
|
isConnected(fileUri: string, connectionProfile?: ConnectionProfile): boolean {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user