mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-17 17:22:42 -05:00
window reuse for connections (#4049)
* window reuse for connections * space after colon * use undefined instead of null
This commit is contained in:
@@ -7,7 +7,7 @@ import { ConnectionProfile } from 'sql/platform/connection/common/connectionProf
|
||||
import { ICommandLineProcessing } from 'sql/workbench/services/commandLine/common/commandLine';
|
||||
import { IConnectionManagementService } from 'sql/platform/connection/common/connectionManagement';
|
||||
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { IEnvironmentService, ParsedArgs } from 'vs/platform/environment/common/environment';
|
||||
import * as Constants from 'sql/platform/connection/common/constants';
|
||||
import { IQueryEditorService } from 'sql/parts/query/common/queryEditorService';
|
||||
import * as platform from 'vs/platform/registry/common/platform';
|
||||
@@ -18,14 +18,12 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
|
||||
import { IWorkspaceConfigurationService } from 'vs/workbench/services/configuration/common/configuration';
|
||||
import { ICommandService } from 'vs/platform/commands/common/commands';
|
||||
import { warn } from 'sql/base/common/log';
|
||||
import { ipcRenderer as ipc} from 'electron';
|
||||
|
||||
export class CommandLineService implements ICommandLineProcessing {
|
||||
private _connectionProfile: ConnectionProfile;
|
||||
private _showConnectionDialog: boolean;
|
||||
private _commandName: string;
|
||||
|
||||
constructor(
|
||||
@ICapabilitiesService _capabilitiesService: ICapabilitiesService,
|
||||
@ICapabilitiesService private _capabilitiesService: ICapabilitiesService,
|
||||
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
|
||||
@IEnvironmentService private _environmentService: IEnvironmentService,
|
||||
@IQueryEditorService private _queryEditorService: IQueryEditorService,
|
||||
@@ -34,52 +32,62 @@ export class CommandLineService implements ICommandLineProcessing {
|
||||
@ICommandService private _commandService: ICommandService,
|
||||
@IWorkspaceConfigurationService private _configurationService: IWorkspaceConfigurationService
|
||||
) {
|
||||
let profile = null;
|
||||
if (this._environmentService) {
|
||||
if (this._commandService) {
|
||||
this._commandName = this._environmentService.args.command;
|
||||
}
|
||||
if (this._environmentService.args.server) {
|
||||
profile = new ConnectionProfile(_capabilitiesService, null);
|
||||
// We want connection store to use any matching password it finds
|
||||
profile.savePassword = true;
|
||||
profile.providerName = Constants.mssqlProviderName;
|
||||
profile.serverName = _environmentService.args.server;
|
||||
profile.databaseName = _environmentService.args.database ? _environmentService.args.database : '';
|
||||
profile.userName = _environmentService.args.user ? _environmentService.args.user : '';
|
||||
profile.authenticationType = _environmentService.args.integrated ? 'Integrated' : 'SqlLogin';
|
||||
profile.connectionName = '';
|
||||
profile.setOptionValue('applicationName', Constants.applicationName);
|
||||
profile.setOptionValue('databaseDisplayName', profile.databaseName);
|
||||
profile.setOptionValue('groupId', profile.groupId);
|
||||
}
|
||||
if (ipc) {
|
||||
ipc.on('ads:processCommandLine', (event: any, args: ParsedArgs) => this.onLaunched(args));
|
||||
}
|
||||
this._connectionProfile = profile;
|
||||
// we only get the ipc from main during window reuse
|
||||
this.onLaunched(_environmentService.args);
|
||||
}
|
||||
|
||||
private onLaunched(args: ParsedArgs)
|
||||
{
|
||||
const registry = platform.Registry.as<IConnectionProviderRegistry>(ConnectionProviderExtensions.ConnectionProviderContributions);
|
||||
let sqlProvider = registry.getProperties(Constants.mssqlProviderName);
|
||||
// We can't connect to object explorer until the MSSQL connection provider is registered
|
||||
if (sqlProvider) {
|
||||
this.processCommandLine().catch(reason => { warn('processCommandLine failed: ' + reason); });
|
||||
this.processCommandLine(args).catch(reason => { warn('processCommandLine failed: ' + reason); });
|
||||
} else {
|
||||
registry.onNewProvider(e => {
|
||||
if (e.id === Constants.mssqlProviderName) {
|
||||
this.processCommandLine().catch(reason => { warn('processCommandLine failed: ' + reason); });
|
||||
this.processCommandLine(args).catch(reason => { warn('processCommandLine failed: ' + reason); });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public _serviceBrand: any;
|
||||
// We base our logic on the combination of (server, command) values.
|
||||
// (serverName, commandName) => Connect object explorer and execute the command, passing the connection profile to the command. Do not load query editor.
|
||||
// (null, commandName) => Launch the command with a null connection. If the command implementation needs a connection, it will need to create it.
|
||||
// (serverName, null) => Connect object explorer and open a new query editor
|
||||
// (null, null) => Prompt for a connection unless there are registered servers
|
||||
public processCommandLine(): Promise<void> {
|
||||
public processCommandLine(args: ParsedArgs): Promise<void> {
|
||||
let profile = undefined;
|
||||
let commandName = undefined;
|
||||
if (args) {
|
||||
if (this._commandService) {
|
||||
commandName = args.command;
|
||||
}
|
||||
|
||||
if (args.server) {
|
||||
profile = new ConnectionProfile(this._capabilitiesService, null);
|
||||
// We want connection store to use any matching password it finds
|
||||
profile.savePassword = true;
|
||||
profile.providerName = Constants.mssqlProviderName;
|
||||
profile.serverName = args.server;
|
||||
profile.databaseName = args.database ? args.database : '';
|
||||
profile.userName = args.user ? args.user : '';
|
||||
profile.authenticationType = args.integrated ? 'Integrated' : 'SqlLogin';
|
||||
profile.connectionName = '';
|
||||
profile.setOptionValue('applicationName', Constants.applicationName);
|
||||
profile.setOptionValue('databaseDisplayName', profile.databaseName);
|
||||
profile.setOptionValue('groupId', profile.groupId);
|
||||
}
|
||||
}
|
||||
let self = this;
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
let showConnectDialogOnStartup: boolean = this._configurationService.getValue('workbench.showConnectDialogOnStartup');
|
||||
if (showConnectDialogOnStartup && !self._commandName && !self._connectionProfile && !self._connectionManagementService.hasRegisteredServers()) {
|
||||
let showConnectDialogOnStartup: boolean = self._configurationService.getValue('workbench.showConnectDialogOnStartup');
|
||||
if (showConnectDialogOnStartup && !commandName && !profile && !self._connectionManagementService.hasRegisteredServers()) {
|
||||
// prompt the user for a new connection on startup if no profiles are registered
|
||||
self._connectionManagementService.showConnectionDialog()
|
||||
.then(() => {
|
||||
@@ -88,11 +96,11 @@ export class CommandLineService implements ICommandLineProcessing {
|
||||
error => {
|
||||
reject(error);
|
||||
});
|
||||
} else if (self._connectionProfile) {
|
||||
if (!self._commandName) {
|
||||
self._connectionManagementService.connectIfNotConnected(self._connectionProfile, 'connection', true)
|
||||
} else if (profile) {
|
||||
if (!commandName) {
|
||||
self._connectionManagementService.connectIfNotConnected(profile, 'connection', true)
|
||||
.then(() => {
|
||||
TaskUtilities.newQuery(self._connectionProfile,
|
||||
TaskUtilities.newQuery(profile,
|
||||
self._connectionManagementService,
|
||||
self._queryEditorService,
|
||||
self._objectExplorerService,
|
||||
@@ -109,15 +117,15 @@ export class CommandLineService implements ICommandLineProcessing {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
self._connectionManagementService.connectIfNotConnected(self._connectionProfile, 'connection', true)
|
||||
self._connectionManagementService.connectIfNotConnected(profile, 'connection', true)
|
||||
.then(() => {
|
||||
self._commandService.executeCommand(self._commandName, self._connectionProfile.id).then(() => resolve(), error => reject(error));
|
||||
self._commandService.executeCommand(commandName, profile.id).then(() => resolve(), error => reject(error));
|
||||
}, error => {
|
||||
reject(error);
|
||||
});
|
||||
}
|
||||
} else if (self._commandName) {
|
||||
self._commandService.executeCommand(self._commandName).then(() => resolve(), error => reject(error));
|
||||
} else if (commandName) {
|
||||
self._commandService.executeCommand(commandName).then(() => resolve(), error => reject(error));
|
||||
}
|
||||
else {
|
||||
resolve();
|
||||
|
||||
Reference in New Issue
Block a user