mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-26 01:25:38 -05:00
Use SQL input / output template instead (#18768)
* use sql input / output template instead * workaround for storage wizard that is opened
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
import * as os from 'os';
|
||||
import * as fs from 'fs';
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
@@ -133,32 +132,6 @@ export async function getAzureFunctionsExtensionApi(): Promise<AzureFunctionsExt
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO REMOVE defaultSqlBindingTextLines
|
||||
* Overwrites the Azure function methods body to work with the binding
|
||||
* @param filePath is the path for the function file (.cs for C# functions)
|
||||
*/
|
||||
export function overwriteAzureFunctionMethodBody(filePath: string): void {
|
||||
let defaultBindedFunctionText = fs.readFileSync(filePath, 'utf-8');
|
||||
// Replace default binding text
|
||||
let newValueLines = defaultBindedFunctionText.split(os.EOL);
|
||||
const defaultFunctionTextToSkip = new Set(constants.defaultSqlBindingTextLines);
|
||||
let replacedValueLines = [];
|
||||
for (let defaultLine of newValueLines) {
|
||||
// Skipped lines
|
||||
if (defaultFunctionTextToSkip.has(defaultLine.trimStart())) {
|
||||
continue;
|
||||
} else if (defaultLine.trimStart() === constants.defaultBindingResult) { // Result change
|
||||
replacedValueLines.push(defaultLine.replace(constants.defaultBindingResult, constants.sqlBindingResult));
|
||||
} else {
|
||||
// Normal lines to be included
|
||||
replacedValueLines.push(defaultLine);
|
||||
}
|
||||
}
|
||||
defaultBindedFunctionText = replacedValueLines.join(os.EOL);
|
||||
fs.writeFileSync(filePath, defaultBindedFunctionText, 'utf-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the azure function project for the user to choose from a list of projects files
|
||||
* If only one project is found that project is used to add the binding to
|
||||
@@ -276,7 +249,7 @@ export async function addNugetReferenceToProjectFile(selectedProjectFile: string
|
||||
export async function addConnectionStringToConfig(connectionString: string, projectFile: string): Promise<void> {
|
||||
const settingsFile = await getSettingsFile(projectFile);
|
||||
if (settingsFile) {
|
||||
await setLocalAppSetting(path.dirname(settingsFile), constants.sqlConnectionString, connectionString);
|
||||
await setLocalAppSetting(path.dirname(settingsFile), constants.sqlConnectionStringSetting, connectionString);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,21 +10,14 @@ const localize = nls.loadMessageBundle();
|
||||
|
||||
// Azure Functions
|
||||
export const azureFunctionsExtensionName = 'ms-azuretools.vscode-azurefunctions';
|
||||
export const sqlConnectionString = 'SqlConnectionString';
|
||||
export const linkToAzureFunctionExtension = 'https://docs.microsoft.com/azure/azure-functions/functions-develop-vs-code';
|
||||
export const sqlBindingsDoc = 'https://aka.ms/sqlbindings';
|
||||
export const defaultSqlBindingTextLines =
|
||||
[
|
||||
'log.LogInformation(\"C# HTTP trigger function processed a request.\");',
|
||||
'string name = req.Query[\"name\"];',
|
||||
'string requestBody = await new StreamReader(req.Body).ReadToEndAsync();',
|
||||
'dynamic data = JsonConvert.DeserializeObject(requestBody);',
|
||||
'name = name ?? data?.name;',
|
||||
'string responseMessage = string.IsNullOrEmpty(name) ? \"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.\" : $\"Hello, {name}. This HTTP triggered function executed successfully.\";'
|
||||
];
|
||||
export const defaultBindingResult = 'return new OkObjectResult(responseMessage);';
|
||||
export const sqlBindingResult = `return new OkObjectResult(result);`;
|
||||
export const sqlConnectionStringSetting = 'SqlConnectionString';
|
||||
export const azureWebJobsStorageSetting = 'AzureWebJobsStorage';
|
||||
export const azureWebJobsStoragePlaceholder = 'Enter your Azure Web Jobs storage connection string';
|
||||
export const sqlExtensionPackageName = 'Microsoft.Azure.WebJobs.Extensions.Sql';
|
||||
export const inputTemplateID = 'SqlInputBinding';
|
||||
export const outputTemplateID = 'SqlOutputBinding';
|
||||
export const functionNameTitle = localize('functionNameTitle', 'Function Name');
|
||||
export const selectProject = localize('selectProject', 'Select the Azure Function project for the SQL Binding');
|
||||
export const azureFunctionsExtensionNotFound = localize('azureFunctionsExtensionNotFound', 'The Azure Functions extension is required to create a new Azure Function with SQL binding but is not installed, install it now?');
|
||||
@@ -65,7 +58,6 @@ export const noAzureFunctionsProjectsInWorkspace = localize('noAzureFunctionsPro
|
||||
export const addPackage = localize('addPackage', "Add Package");
|
||||
export const createNewLocalAppSetting = localize('createNewLocalAppSetting', 'Create new local app setting');
|
||||
export const createNewLocalAppSettingWithIcon = `$(add) ${createNewLocalAppSetting}`;
|
||||
export const sqlConnectionStringSetting = 'SqlConnectionString';
|
||||
export const valueMustNotBeEmpty = localize('valueMustNotBeEmpty', "Value must not be empty");
|
||||
export const enterConnectionStringSettingName = localize('enterConnectionStringSettingName', "Enter connection string setting name");
|
||||
export const enterConnectionString = localize('enterConnectionString', "Enter connection string");
|
||||
|
||||
Reference in New Issue
Block a user