Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 760a87b

Browse files
Changes to allow reporting success with an action on sqlTasksService (#20651)
1 parent 24d2641 commit 760a87b

File tree

7 files changed

+1403
-100
lines changed

7 files changed

+1403
-100
lines changed

extensions/mssql/src/constants/constants.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,9 @@ export const build = "build";
341341
export const sqlProjBuildTaskType = "sqlproj-build";
342342
export const msBuildProblemMatcher = "$msCompile";
343343
export const buildDirectory = "BuildDirectory";
344+
345+
// DacFx operation IDs (as reported by SQL Tools Service via taskOperation field)
346+
export const operationIdExportBacpac = "ExportOperation";
347+
export const operationIdExtractDacpac = "ExtractOperation";
348+
export const operationIdImportBacpac = "ImportOperation";
349+
export const operationIdDeployDacpac = "DeployOperation";

extensions/mssql/src/controllers/dacpacDialogWebviewController.ts

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -27,37 +27,16 @@ import {
2727
DatabaseNameValidationError,
2828
ConnectionMatcher,
2929
} from "../models/utils";
30-
import { PlatformInformation } from "../models/platform";
3130
import { UserSurvey } from "../nps/userSurvey";
3231
import { getErrorMessage } from "../utils/utils";
3332

3433
// File extension constants
3534
export const DACPAC_EXTENSION = ".dacpac";
3635
export const BACPAC_EXTENSION = ".bacpac";
3736

38-
// VS Code command constants
39-
const REVEAL_FILE_IN_OS_COMMAND = "revealFileInOS";
40-
4137
// View ID constant for NPS survey
4238
const DACPAC_DIALOG_VIEW_ID = "dacpacDialog";
4339

44-
/**
45-
* Gets the OS-specific localized text for the "Reveal/Open" file button
46-
* @returns The appropriate localized string based on the operating system
47-
*/
48-
function getRevealInOsButtonText(): string {
49-
const platformInfo = new PlatformInformation(process.platform, process.arch, undefined);
50-
51-
if (platformInfo.isMacOS) {
52-
return LocConstants.DacpacDialog.RevealInFinder;
53-
} else if (platformInfo.isLinux) {
54-
return LocConstants.DacpacDialog.OpenContainingFolder;
55-
} else {
56-
// Windows or any other platform
57-
return LocConstants.DacpacDialog.RevealInExplorer;
58-
}
59-
}
60-
6140
/**
6241
* Controller for the DacpacDialog webview.
6342
* Manages DACPAC and BACPAC operations (Deploy, Extract, Import, Export) using the Data-tier Application Framework (DacFx).
@@ -352,10 +331,6 @@ export class DacpacDialogWebviewController extends ReactWebviewPanelController<
352331
if (result.success) {
353332
this.logger.verbose("Deploy DACPAC operation completed successfully");
354333
activity.end(ActivityStatus.Succeeded);
355-
// Show success notification for Deploy operation
356-
void this.vscodeWrapper.showInformationMessage(
357-
LocConstants.DacpacDialog.DeploySuccessWithDatabase(params.databaseName),
358-
);
359334
// Prompt user for NPS survey feedback
360335
UserSurvey.getInstance().promptUserForNPSFeedback(
361336
`${DACPAC_DIALOG_VIEW_ID}_deploy`,
@@ -417,22 +392,6 @@ export class DacpacDialogWebviewController extends ReactWebviewPanelController<
417392
if (result.success) {
418393
this.logger.verbose("Extract DACPAC operation completed successfully");
419394
activity.end(ActivityStatus.Succeeded);
420-
// Show success notification with OS-specific "Reveal/Open" button for Extract operation
421-
const fileName = path.basename(params.packageFilePath);
422-
const revealButtonText = getRevealInOsButtonText();
423-
void this.vscodeWrapper
424-
.showInformationMessage(
425-
LocConstants.DacpacDialog.ExtractSuccessWithFile(fileName),
426-
revealButtonText,
427-
)
428-
.then((selection) => {
429-
if (selection === revealButtonText) {
430-
void vscode.commands.executeCommand(
431-
REVEAL_FILE_IN_OS_COMMAND,
432-
vscode.Uri.file(params.packageFilePath),
433-
);
434-
}
435-
});
436395
// Prompt user for NPS survey feedback
437396
UserSurvey.getInstance().promptUserForNPSFeedback(
438397
`${DACPAC_DIALOG_VIEW_ID}_extract`,
@@ -492,10 +451,6 @@ export class DacpacDialogWebviewController extends ReactWebviewPanelController<
492451
if (result.success) {
493452
this.logger.verbose("Import BACPAC operation completed successfully");
494453
activity.end(ActivityStatus.Succeeded);
495-
// Show success notification for Import operation
496-
void this.vscodeWrapper.showInformationMessage(
497-
LocConstants.DacpacDialog.ImportSuccessWithDatabase(params.databaseName),
498-
);
499454
// Prompt user for NPS survey feedback
500455
UserSurvey.getInstance().promptUserForNPSFeedback(
501456
`${DACPAC_DIALOG_VIEW_ID}_import`,
@@ -555,22 +510,6 @@ export class DacpacDialogWebviewController extends ReactWebviewPanelController<
555510
if (result.success) {
556511
this.logger.verbose("Export BACPAC operation completed successfully");
557512
activity.end(ActivityStatus.Succeeded);
558-
// Show success notification with OS-specific "Reveal/Open" button for Export operation
559-
const fileName = path.basename(params.packageFilePath);
560-
const revealButtonText = getRevealInOsButtonText();
561-
void this.vscodeWrapper
562-
.showInformationMessage(
563-
LocConstants.DacpacDialog.ExportSuccessWithFile(fileName),
564-
revealButtonText,
565-
)
566-
.then((selection) => {
567-
if (selection === revealButtonText) {
568-
void vscode.commands.executeCommand(
569-
REVEAL_FILE_IN_OS_COMMAND,
570-
vscode.Uri.file(params.packageFilePath),
571-
);
572-
}
573-
});
574513
// Prompt user for NPS survey feedback
575514
UserSurvey.getInstance().promptUserForNPSFeedback(
576515
`${DACPAC_DIALOG_VIEW_ID}_export`,

extensions/mssql/src/controllers/mainController.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,12 @@ export default class MainController implements vscode.Disposable {
573573
this.sqlTasksService = new SqlTasksService(
574574
SqlToolsServerClient.instance,
575575
this._sqlDocumentService,
576+
this._vscodeWrapper,
577+
);
578+
this.dacFxService = new DacFxService(
579+
SqlToolsServerClient.instance,
580+
this.sqlTasksService,
576581
);
577-
this.dacFxService = new DacFxService(SqlToolsServerClient.instance);
578582
this.sqlProjectsService = new SqlProjectsService(SqlToolsServerClient.instance);
579583
this.schemaCompareService = new SchemaCompareService(SqlToolsServerClient.instance);
580584
this.tableExplorerService = new TableExplorerService(SqlToolsServerClient.instance);

extensions/mssql/src/services/dacFxService.ts

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,84 @@ import SqlToolsServiceClient from "../languageservice/serviceclient";
77
import * as dacFxContracts from "../models/contracts/dacFx/dacFxContracts";
88
import * as mssql from "vscode-mssql";
99
import { ExtractTarget, TaskExecutionMode } from "../sharedInterfaces/schemaCompare";
10+
import { SqlTasksService } from "./sqlTasksService";
11+
import * as path from "path";
12+
import * as vscode from "vscode";
13+
import * as Constants from "../constants/constants";
14+
import * as LocalizedConstants from "../constants/locConstants";
15+
import { PlatformInformation } from "../models/platform";
1016

1117
export class DacFxService implements mssql.IDacFxService {
12-
constructor(private _client: SqlToolsServiceClient) {}
18+
constructor(
19+
private _client: SqlToolsServiceClient,
20+
sqlTasksService: SqlTasksService,
21+
) {
22+
this.registerTaskCompletionHandlers(sqlTasksService);
23+
}
24+
25+
/**
26+
* Register task completion handlers for dacpac operations
27+
*/
28+
private registerTaskCompletionHandlers(sqlTasksService: SqlTasksService): void {
29+
const platformInfo = new PlatformInformation(process.platform, process.arch, undefined);
30+
31+
// Determine the OS-specific reveal button text
32+
let revealButtonText: string;
33+
if (platformInfo.isMacOS) {
34+
revealButtonText = LocalizedConstants.DacpacDialog.RevealInFinder;
35+
} else if (platformInfo.isWindows) {
36+
revealButtonText = LocalizedConstants.DacpacDialog.RevealInExplorer;
37+
} else {
38+
// Linux and other platforms
39+
revealButtonText = LocalizedConstants.DacpacDialog.OpenContainingFolder;
40+
}
41+
42+
// Register handler for Export BACPAC operation
43+
sqlTasksService.registerCompletionSuccessHandler({
44+
operationName: Constants.operationIdExportBacpac,
45+
getTargetLocation: (taskInfo) => taskInfo.targetLocation,
46+
getSuccessMessage: (_taskInfo, targetLocation) => {
47+
const fileName = path.basename(targetLocation);
48+
return LocalizedConstants.DacpacDialog.ExportSuccessWithFile(fileName);
49+
},
50+
actionButtonText: revealButtonText,
51+
actionCommand: "revealFileInOS",
52+
getActionCommandArgs: (_taskInfo, targetLocation) => [vscode.Uri.file(targetLocation)],
53+
});
54+
55+
// Register handler for Extract DACPAC operation
56+
sqlTasksService.registerCompletionSuccessHandler({
57+
operationName: Constants.operationIdExtractDacpac,
58+
getTargetLocation: (taskInfo) => taskInfo.targetLocation,
59+
getSuccessMessage: (_taskInfo, targetLocation) => {
60+
const fileName = path.basename(targetLocation);
61+
return LocalizedConstants.DacpacDialog.ExtractSuccessWithFile(fileName);
62+
},
63+
actionButtonText: revealButtonText,
64+
actionCommand: "revealFileInOS",
65+
getActionCommandArgs: (_taskInfo, targetLocation) => [vscode.Uri.file(targetLocation)],
66+
});
67+
68+
// Register handler for Import BACPAC operation
69+
sqlTasksService.registerCompletionSuccessHandler({
70+
operationName: Constants.operationIdImportBacpac,
71+
getTargetLocation: (taskInfo) => taskInfo.databaseName,
72+
getSuccessMessage: (_taskInfo, databaseName) => {
73+
return LocalizedConstants.DacpacDialog.ImportSuccessWithDatabase(databaseName);
74+
},
75+
// No action button for database operations
76+
});
77+
78+
// Register handler for Deploy DACPAC operation
79+
sqlTasksService.registerCompletionSuccessHandler({
80+
operationName: Constants.operationIdDeployDacpac,
81+
getTargetLocation: (taskInfo) => taskInfo.databaseName,
82+
getSuccessMessage: (_taskInfo, databaseName) => {
83+
return LocalizedConstants.DacpacDialog.DeploySuccessWithDatabase(databaseName);
84+
},
85+
// No action button for database operations
86+
});
87+
}
1388

1489
public exportBacpac(
1590
databaseName: string,

0 commit comments

Comments
 (0)