mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-16 09:35:36 -05:00
Read publish profile using DacFX (#16110)
* Read publish profile using DacFX in VS Code * Fixes * complete promise on hide * comment
This commit is contained in:
@@ -7,6 +7,7 @@ import * as vscode from 'vscode';
|
||||
import * as constants from '../common/constants';
|
||||
import { IGenerateScriptSettings, IPublishSettings } from '../models/IPublishSettings';
|
||||
import { Project } from '../models/project';
|
||||
import { PublishProfile, readPublishProfile } from '../models/publishProfile/publishProfile';
|
||||
import { promptForPublishProfile } from './publishDatabaseDialog';
|
||||
|
||||
/**
|
||||
@@ -15,21 +16,57 @@ import { promptForPublishProfile } from './publishDatabaseDialog';
|
||||
export async function launchPublishDatabaseQuickpick(project: Project): Promise<void> {
|
||||
|
||||
// 1. Select publish settings file (optional)
|
||||
// TODO@chgagnon: Hook up to dacfx service
|
||||
const browseProfileOption = await vscode.window.showQuickPick(
|
||||
[constants.dontUseProfile, constants.browseForProfile],
|
||||
{ title: constants.selectProfile, ignoreFocusOut: true });
|
||||
if (!browseProfileOption) {
|
||||
return;
|
||||
}
|
||||
// Create custom quickpick so we can control stuff like displaying the loading indicator
|
||||
const quickPick = vscode.window.createQuickPick();
|
||||
quickPick.items = [{ label: constants.dontUseProfile }, { label: constants.browseForProfile }];
|
||||
quickPick.ignoreFocusOut = true;
|
||||
quickPick.title = constants.selectProfileToUse;
|
||||
const profilePicked = new Promise<PublishProfile | undefined>((resolve, reject) => {
|
||||
quickPick.onDidHide(() => {
|
||||
// If the quickpick is hidden that means the user cancelled or another quickpick came up - so we reject
|
||||
// here to be able to complete the promise being waited on below
|
||||
reject();
|
||||
});
|
||||
quickPick.onDidChangeSelection(async items => {
|
||||
if (items[0].label === constants.browseForProfile) {
|
||||
const locations = await promptForPublishProfile(project.projectFolderPath);
|
||||
if (!locations) {
|
||||
// Clear items so that this event will trigger again if they select the same item
|
||||
quickPick.selectedItems = [];
|
||||
quickPick.activeItems = [];
|
||||
// If the user cancels out of the file picker then just return and let them choose another option
|
||||
return;
|
||||
}
|
||||
let publishProfileUri = locations[0];
|
||||
try {
|
||||
// Show loading state while reading profile
|
||||
quickPick.busy = true;
|
||||
quickPick.enabled = false;
|
||||
const profile = await readPublishProfile(publishProfileUri);
|
||||
resolve(profile);
|
||||
} catch (err) {
|
||||
// readPublishProfile will handle displaying an error if one occurs
|
||||
// Clear items so that this event will trigger again if they select the same item
|
||||
quickPick.selectedItems = [];
|
||||
quickPick.activeItems = [];
|
||||
quickPick.busy = false;
|
||||
quickPick.enabled = true;
|
||||
|
||||
// let publishSettingsFile: vscode.Uri | undefined;
|
||||
if (browseProfileOption === constants.browseForProfile) {
|
||||
const locations = await promptForPublishProfile(project.projectFolderPath);
|
||||
if (!locations) {
|
||||
return;
|
||||
}
|
||||
// publishSettingsFile = locations[0];
|
||||
}
|
||||
} else {
|
||||
// Selected no profile so just continue on
|
||||
resolve(undefined);
|
||||
}
|
||||
});
|
||||
});
|
||||
quickPick.show();
|
||||
let publishProfile: PublishProfile | undefined = undefined;
|
||||
try {
|
||||
publishProfile = await profilePicked;
|
||||
} catch (err) {
|
||||
// User cancelled or another quickpick came up and hid the current one
|
||||
// so exit the flow.
|
||||
return;
|
||||
}
|
||||
|
||||
// 2. Select connection
|
||||
@@ -83,8 +120,9 @@ export async function launchPublishDatabaseQuickpick(project: Project): Promise<
|
||||
|
||||
|
||||
// 4. Modify sqlcmd vars
|
||||
// TODO@chgagnon: Concat ones from publish profile
|
||||
let sqlCmdVariables = Object.assign({}, project.sqlCmdVariables);
|
||||
// If a publish profile is provided then the values from there will overwrite the ones in the
|
||||
// project file (if they exist)
|
||||
let sqlCmdVariables = Object.assign({}, project.sqlCmdVariables, publishProfile?.sqlCmdVariables);
|
||||
|
||||
if (Object.keys(sqlCmdVariables).length > 0) {
|
||||
// Continually loop here, allowing the user to modify SQLCMD variables one
|
||||
@@ -123,7 +161,7 @@ export async function launchPublishDatabaseQuickpick(project: Project): Promise<
|
||||
sqlCmdVariables[sqlCmd.key] = newValue;
|
||||
}
|
||||
} else if (sqlCmd.isResetAllVars) {
|
||||
sqlCmdVariables = Object.assign({}, project.sqlCmdVariables);
|
||||
sqlCmdVariables = Object.assign({}, project.sqlCmdVariables, publishProfile?.sqlCmdVariables);
|
||||
} else if (sqlCmd.isDone) {
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user