Skip to content

Commit b1d0e29

Browse files
authored
move service and make end to end working (#17227)
1 parent f02fd79 commit b1d0e29

File tree

3 files changed

+55
-69
lines changed

3 files changed

+55
-69
lines changed

src/azureFunction/azureFunctionProjectService.ts

-66
This file was deleted.

src/controllers/mainController.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import { QueryHistoryProvider } from '../queryHistory/queryHistoryProvider';
3232
import { QueryHistoryNode } from '../queryHistory/queryHistoryNode';
3333
import { DacFxService } from '../services/dacFxService';
3434
import { IConnectionInfo } from 'vscode-mssql';
35-
import { AzureFunctionProjectService } from '../azureFunction/azureFunctionProjectService';
3635
import { getConnectionString } from '../utils/connectionStringUtil';
3736
import { SchemaCompareService } from '../services/schemaCompareService';
3837
import { SqlTasksService } from '../services/sqlTasksService';
@@ -442,7 +441,6 @@ export default class MainController implements vscode.Disposable {
442441
}
443442
}));
444443

445-
const afService = new AzureFunctionProjectService(this.azureFunctionsService);
446444
// Generate Azure Function command
447445
this._context.subscriptions.push(vscode.commands.registerCommand(Constants.cmdCreateAzureFunction, async (node: TreeNodeInfo) => {
448446
const database = ObjectExplorerUtils.getDatabaseName(node);
@@ -452,7 +450,7 @@ export default class MainController implements vscode.Disposable {
452450
database,
453451
node.connectionInfo.user,
454452
node.connectionInfo.password);
455-
await afService.createAzureFunction(connStr, node.metadata.schema, node.metadata.name);
453+
await this.azureFunctionsService.createAzureFunction(connStr, node.metadata.schema, node.metadata.name);
456454
}));
457455
}
458456

src/services/azureFunctionsService.ts

+54
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44
* ------------------------------------------------------------------------------------------ */
55

66
import SqlToolsServiceClient from '../languageservice/serviceclient';
7+
import * as vscode from 'vscode';
78
import * as mssql from 'vscode-mssql';
89
import * as azureFunctionsContracts from '../models/contracts/azureFunctions/azureFunctionsContracts';
10+
import * as azureFunctionUtils from '../azureFunction/azureFunctionUtils';
11+
import * as constants from '../constants/constants';
12+
import { generateQuotedFullName } from '../utils/utils';
13+
import * as LocalizedConstants from '../constants/localizedConstants';
914

1015
export const hostFileName: string = 'host.json';
1116

@@ -55,4 +60,53 @@ export class AzureFunctionsService implements mssql.IAzureFunctionsService {
5560

5661
return this._client.sendRequest(azureFunctionsContracts.GetAzureFunctionsRequest.type, params);
5762
}
63+
64+
public async createAzureFunction(connectionString: string, schema: string, table: string): Promise<void> {
65+
const azureFunctionApi = await azureFunctionUtils.getAzureFunctionsExtensionApi();
66+
if (!azureFunctionApi) {
67+
return;
68+
}
69+
let projectFile = await azureFunctionUtils.getAzureFunctionProject();
70+
if (!projectFile) {
71+
vscode.window.showErrorMessage(LocalizedConstants.azureFunctionsProjectMustBeOpened);
72+
return;
73+
}
74+
75+
// because of an AF extension API issue, we have to get the newly created file by adding
76+
// a watcher: https://github.com/microsoft/vscode-azurefunctions/issues/2908
77+
const newFilePromise = azureFunctionUtils.waitForNewFunctionFile(projectFile);
78+
79+
// get function name from user
80+
const functionName = await vscode.window.showInputBox({
81+
title: constants.functionNameTitle,
82+
value: table,
83+
ignoreFocusOut: true
84+
});
85+
if (!functionName) {
86+
return;
87+
}
88+
89+
// create C# HttpTrigger
90+
await azureFunctionApi.createFunction({
91+
language: 'C#',
92+
templateId: 'HttpTrigger',
93+
functionName: functionName,
94+
folderPath: projectFile
95+
});
96+
97+
await azureFunctionUtils.addNugetReferenceToProjectFile(projectFile);
98+
await azureFunctionUtils.addConnectionStringToConfig(connectionString, projectFile);
99+
const functionFile = await newFilePromise;
100+
101+
let objectName = generateQuotedFullName(schema, table);
102+
await this.addSqlBinding(
103+
mssql.BindingType.input,
104+
functionFile,
105+
functionName,
106+
objectName,
107+
constants.sqlConnectionString
108+
);
109+
110+
azureFunctionUtils.overwriteAzureFunctionMethodBody(functionFile);
111+
}
58112
}

0 commit comments

Comments
 (0)