From fe26183336c48cbf05d319587eb99cfd8322a377 Mon Sep 17 00:00:00 2001 From: Lilian Kasem Date: Tue, 27 Jun 2023 15:19:21 -0700 Subject: [PATCH 1/2] Cleanup samples --- .../Cosmos/CosmosInputBindingFunctions.cs | 50 ++++++++ .../Cosmos/CosmosTriggerFunction.cs | 25 ++-- .../EventGrid/CloudEventSamples.cs | 48 +++++++ .../EventGrid/EventGridEventSamples.cs | 48 +++++++ .../EventGridTriggerBindingSamples.cs | 105 ---------------- ...iggerBindingSamples.cs => QueueSamples.cs} | 22 ++-- .../Table/TableInputBindingSamples.cs | 118 ------------------ .../Table/TableSamples.cs | 103 +++++++++++++++ .../WorkerBindingSamples/local.settings.json | 1 + 9 files changed, 279 insertions(+), 241 deletions(-) create mode 100644 samples/WorkerBindingSamples/EventGrid/CloudEventSamples.cs create mode 100644 samples/WorkerBindingSamples/EventGrid/EventGridEventSamples.cs delete mode 100644 samples/WorkerBindingSamples/EventGrid/EventGridTriggerBindingSamples.cs rename samples/WorkerBindingSamples/Queue/{QueueTriggerBindingSamples.cs => QueueSamples.cs} (59%) delete mode 100644 samples/WorkerBindingSamples/Table/TableInputBindingSamples.cs create mode 100644 samples/WorkerBindingSamples/Table/TableSamples.cs diff --git a/samples/WorkerBindingSamples/Cosmos/CosmosInputBindingFunctions.cs b/samples/WorkerBindingSamples/Cosmos/CosmosInputBindingFunctions.cs index 151eda81f..e5b433b0c 100644 --- a/samples/WorkerBindingSamples/Cosmos/CosmosInputBindingFunctions.cs +++ b/samples/WorkerBindingSamples/Cosmos/CosmosInputBindingFunctions.cs @@ -9,6 +9,9 @@ namespace SampleApp { + /// + /// Samples demonstrating binding to the , , and types. + /// public class CosmosInputBindingFunctions { private readonly ILogger _logger; @@ -18,6 +21,11 @@ public CosmosInputBindingFunctions(ILogger logger) _logger = logger; } + /// + /// This sample demonstrates how to retrieve a collection of documents. + /// The code uses a instance to read a list of documents. + /// The instance could also be used for write operations. + /// [Function(nameof(DocsByUsingCosmosClient))] public async Task DocsByUsingCosmosClient( [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, @@ -40,6 +48,11 @@ public async Task DocsByUsingCosmosClient( return req.CreateResponse(HttpStatusCode.OK); } + /// + /// This sample demonstrates how to retrieve a collection of documents. + /// The function is triggered by an HTTP request and binds to the specified database. + /// as a type. The function then queries for all collections in the database. + /// [Function(nameof(DocsByUsingDatabaseClient))] public async Task DocsByUsingDatabaseClient( [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, @@ -61,6 +74,11 @@ public async Task DocsByUsingDatabaseClient( return req.CreateResponse(HttpStatusCode.OK); } + /// + /// This sample demonstrates how to retrieve a collection of documents. + /// The function is triggered by an HTTP request and binds to the specified database and collection + /// as a type. The function then queries for all documents in the collection. + /// [Function(nameof(DocsByUsingContainerClient))] public async Task DocsByUsingContainerClient( [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, @@ -82,6 +100,11 @@ public async Task DocsByUsingContainerClient( return req.CreateResponse(HttpStatusCode.OK); } + /// + /// This sample demonstrates how to retrieve a single document. + /// The function is triggered by an HTTP request that uses a query string to specify the ID and partition key value to look up. + /// That ID and partition key value are used to retrieve a ToDoItem document from the specified database and collection. + /// [Function(nameof(DocByIdFromQueryString))] public HttpResponseData DocByIdFromQueryString( [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, @@ -106,6 +129,11 @@ public HttpResponseData DocByIdFromQueryString( return req.CreateResponse(HttpStatusCode.OK); } + /// + /// This sample demonstrates how to retrieve a single document. + /// The function is triggered by an HTTP request that uses route data to specify the ID and partition key value to look up. + /// That ID and partition key value are used to retrieve a ToDoItem document from the specified database and collection. + /// [Function(nameof(DocByIdFromRouteData))] public HttpResponseData DocByIdFromRouteData( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "todoitems/{partitionKey}/{id}")] HttpRequestData req, @@ -130,6 +158,12 @@ public HttpResponseData DocByIdFromRouteData( return req.CreateResponse(HttpStatusCode.OK); } + /// + /// This sample demonstrates how to retrieve a collection of documents. + /// The function is triggered by an HTTP request that uses route data to specify the ID to look up. + /// That ID is used to retrieve a list of ToDoItem documents from the specified database and collection. + /// The example shows how to use a binding expression in the parameter. + /// [Function(nameof(DocByIdFromRouteDataUsingSqlQuery))] public HttpResponseData DocByIdFromRouteDataUsingSqlQuery( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "todoitems2/{id}")] HttpRequestData req, @@ -150,6 +184,12 @@ public HttpResponseData DocByIdFromRouteDataUsingSqlQuery( return req.CreateResponse(HttpStatusCode.OK); } + /// + /// This sample demonstrates how to retrieve a collection of documents. + /// The function is triggered by an HTTP request that uses a query string to specify the ID to look up. + /// That ID is used to retrieve a list of ToDoItem documents from the specified database and collection. + /// The example shows how to use a binding expression in the parameter. + /// [Function(nameof(DocByIdFromQueryStringUsingSqlQuery))] public HttpResponseData DocByIdFromQueryStringUsingSqlQuery( [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, @@ -170,6 +210,10 @@ public HttpResponseData DocByIdFromQueryStringUsingSqlQuery( return req.CreateResponse(HttpStatusCode.OK); } + /// + /// This sample demonstrates how to retrieve a collection of documents. + /// The function is triggered by an HTTP request. The query is specified in the attribute property. + /// [Function(nameof(DocsBySqlQuery))] public HttpResponseData DocsBySqlQuery( [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, @@ -189,6 +233,12 @@ public HttpResponseData DocsBySqlQuery( return req.CreateResponse(HttpStatusCode.OK); } + /// + /// This sample demonstrates how to retrieve a single document. + /// The function is triggered by a queue message that contains a JSON object. The queue trigger parses the JSON into + /// an object of type ToDoItemLookup, which contains the ID and partition key value to look up. That ID and partition + /// key value are used to retrieve a ToDoItem document from the specified database and collection. + /// [Function(nameof(DocByIdFromJSON))] public void DocByIdFromJSON( [QueueTrigger("todoqueueforlookup")] ToDoItemLookup toDoItemLookup, diff --git a/samples/WorkerBindingSamples/Cosmos/CosmosTriggerFunction.cs b/samples/WorkerBindingSamples/Cosmos/CosmosTriggerFunction.cs index f7e11f6cd..d43086c9d 100644 --- a/samples/WorkerBindingSamples/Cosmos/CosmosTriggerFunction.cs +++ b/samples/WorkerBindingSamples/Cosmos/CosmosTriggerFunction.cs @@ -6,26 +6,35 @@ namespace SampleApp { - // We cannot use SDK-type bindings with the Cosmos trigger binding. There is no way for - // the CosmosDB SDK to let us know the ID of the document that triggered the function; - // therefore we cannot create a client that is able to pull the triggering document. - public static class CosmosTriggerFunction + /// + /// Samples demonstrating binding to the type. + /// + public class CosmosTriggerFunction { + private readonly ILogger _logger; + + public CosmosTriggerFunction(ILogger logger) + { + _logger = logger; + } + + /// + /// This function demonstrates binding to a collection of . + /// [Function(nameof(CosmosTriggerFunction))] - public static void Run([CosmosDBTrigger( + public void Run([CosmosDBTrigger( databaseName: "ToDoItems", containerName:"TriggerItems", Connection = "CosmosDBConnection", + LeaseContainerName = "leases", CreateLeaseContainerIfNotExists = true)] IReadOnlyList todoItems, FunctionContext context) { - var logger = context.GetLogger(nameof(CosmosTriggerFunction)); - if (todoItems is not null && todoItems.Any()) { foreach (var doc in todoItems) { - logger.LogInformation("ToDoItem: {desc}", doc.Description); + _logger.LogInformation("ToDoItem: {desc}", doc.Description); } } } diff --git a/samples/WorkerBindingSamples/EventGrid/CloudEventSamples.cs b/samples/WorkerBindingSamples/EventGrid/CloudEventSamples.cs new file mode 100644 index 000000000..1f3088bca --- /dev/null +++ b/samples/WorkerBindingSamples/EventGrid/CloudEventSamples.cs @@ -0,0 +1,48 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// Default URL for triggering event grid function in the local environment. +// http://localhost:7071/runtime/webhooks/EventGrid?functionName={functionname} + +using Azure.Messaging; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Extensions.Logging; + +namespace SampleApp +{ + /// + /// Samples demonstrating binding to the type. + /// + public class CloudEventSamples + { + private readonly ILogger _logger; + + public CloudEventSamples(ILogger logger) + { + _logger = logger; + } + + /// + /// This function demonstrates binding to a single . + /// + [Function(nameof(CloudEventFunction))] + public void CloudEventFunction([EventGridTrigger] CloudEvent cloudEvent) + { + _logger.LogInformation("Event type: {type}, Event subject: {subject}", cloudEvent.Type, cloudEvent.Subject); + } + + /// + /// This function demonstrates binding to an array of . + /// Note that when doing so, you must also set the property + /// to true. + /// + [Function(nameof(CloudEventBatchFunction))] + public void CloudEventBatchFunction([EventGridTrigger(IsBatched = true)] CloudEvent[] cloudEvents) + { + foreach (var cloudEvent in cloudEvents) + { + _logger.LogInformation("Event type: {type}, Event subject: {subject}", cloudEvent.Type, cloudEvent.Subject); + } + } + } +} diff --git a/samples/WorkerBindingSamples/EventGrid/EventGridEventSamples.cs b/samples/WorkerBindingSamples/EventGrid/EventGridEventSamples.cs new file mode 100644 index 000000000..024b60c36 --- /dev/null +++ b/samples/WorkerBindingSamples/EventGrid/EventGridEventSamples.cs @@ -0,0 +1,48 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +// Default URL for triggering event grid function in the local environment. +// http://localhost:7071/runtime/webhooks/EventGrid?functionName={functionname} + +using Azure.Messaging.EventGrid; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Extensions.Logging; + +namespace SampleApp +{ + /// + /// Samples demonstrating binding to the type. + /// + public class EventGridEventSamples + { + private readonly ILogger _logger; + + public EventGridEventSamples(ILogger logger) + { + _logger = logger; + } + + /// + /// This function demonstrates binding to a single . + /// + [Function(nameof(EventGridEventFunction))] + public void EventGridEventFunction([EventGridTrigger] EventGridEvent eventGridEvent) + { + _logger.LogInformation("Event received: {event}", eventGridEvent.Data.ToString()); + } + + /// + /// This function demonstrates binding to an array of . + /// Note that when doing so, you must also set the property + /// to true. + /// + [Function(nameof(EventGridEventBatchFunction))] + public void EventGridEventBatchFunction([EventGridTrigger(IsBatched = true)] EventGridEvent[] eventGridEvents) + { + foreach (var eventGridEvent in eventGridEvents) + { + _logger.LogInformation("Event received: {event}", eventGridEvent.Data.ToString()); + } + } + } +} diff --git a/samples/WorkerBindingSamples/EventGrid/EventGridTriggerBindingSamples.cs b/samples/WorkerBindingSamples/EventGrid/EventGridTriggerBindingSamples.cs deleted file mode 100644 index 5ffd9123a..000000000 --- a/samples/WorkerBindingSamples/EventGrid/EventGridTriggerBindingSamples.cs +++ /dev/null @@ -1,105 +0,0 @@ -// Default URL for triggering event grid function in the local environment. -// http://localhost:7071/runtime/webhooks/EventGrid?functionName={functionname} -using System; -using Azure.Messaging; -using Azure.Messaging.EventGrid; -using Microsoft.Azure.Functions.Worker; -using Microsoft.Extensions.Logging; - -namespace WorkerBindingSamples.EventGrid -{ - public class EventGridTriggerBindingSamples - { - private readonly ILogger _logger; - - public EventGridTriggerBindingSamples(ILoggerFactory loggerFactory) - { - _logger = loggerFactory.CreateLogger(); - } - - [Function("MyEventFunction")] - public void MyEventFunction([EventGridTrigger] MyEvent input) - { - _logger.LogInformation(input.Data?.ToString()); - } - - [Function("CloudEventFunction")] - public void CloudEventFunction([EventGridTrigger] CloudEvent input) - { - _logger.LogInformation("Event type: {type}, Event subject: {subject}", input.Type, input.Subject); - } - - [Function("MultipleCloudEventFunction")] - public void MultipleCloudEventFunction([EventGridTrigger(IsBatched = true)] CloudEvent[] input) - { - for (var i = 0; i < input.Length; i++) - { - var cloudEvent = input[i]; - _logger.LogInformation("Event type: {type}, Event subject: {subject}", cloudEvent.Type, cloudEvent.Subject); - } - } - - [Function("EventGridEvent")] - public void EventGridEvent([EventGridTrigger] EventGridEvent input) - { - _logger.LogInformation("Event received: {event}", input.Data.ToString()); - } - - [Function("EventGridEventArray")] - public void EventGridEventArray([EventGridTrigger(IsBatched = true)] EventGridEvent[] input) - { - for (var i = 0; i < input.Length; i++) - { - var eventGridEvent = input[i]; - _logger.LogInformation("Event received: {event}", eventGridEvent.Data.ToString()); - } - } - - [Function("BinaryDataEvent")] - public void BinaryDataEvent([EventGridTrigger] BinaryData input) - { - _logger.LogInformation("Event received: {event}", input.ToString()); - } - - [Function("BinaryDataArrayEvent")] - public void BinaryDataArrayEvent([EventGridTrigger(IsBatched = true)] BinaryData[] input) - { - for (var i = 0; i < input.Length; i++) - { - var binaryDataEvent = input[i]; - _logger.LogInformation("Event received: {event}", binaryDataEvent.ToString()); - } - } - - [Function("StringArrayEvent")] - public void StringArrayEvent([EventGridTrigger(IsBatched = true)] string[] input) - { - for (var i = 0; i < input.Length; i++) - { - var stringEventGrid = input[i]; - _logger.LogInformation("Event received: {event}", stringEventGrid); - } - } - - [Function("StringEvent")] - public void StringEvent([EventGridTrigger] string input) - { - _logger.LogInformation("Event received: {event}", input); - } - } - - public class MyEvent - { - public string? Id { get; set; } - - public string? Topic { get; set; } - - public string? Subject { get; set; } - - public string? EventType { get; set; } - - public DateTime EventTime { get; set; } - - public object? Data { get; set; } - } -} diff --git a/samples/WorkerBindingSamples/Queue/QueueTriggerBindingSamples.cs b/samples/WorkerBindingSamples/Queue/QueueSamples.cs similarity index 59% rename from samples/WorkerBindingSamples/Queue/QueueTriggerBindingSamples.cs rename to samples/WorkerBindingSamples/Queue/QueueSamples.cs index 5ef07b97a..c1240c8b3 100644 --- a/samples/WorkerBindingSamples/Queue/QueueTriggerBindingSamples.cs +++ b/samples/WorkerBindingSamples/Queue/QueueSamples.cs @@ -4,35 +4,37 @@ using Azure.Storage.Queues.Models; using Microsoft.Azure.Functions.Worker; using Microsoft.Extensions.Logging; -using System.Text.Json; namespace SampleApp { - public class QueueTriggerBindingSamples + /// + /// Samples demonstrating binding to and types. + /// + public class QueueSamples { - private readonly ILogger _logger; + private readonly ILogger _logger; - public QueueTriggerBindingSamples(ILogger logger) + public QueueSamples(ILogger logger) { _logger = logger; } + /// + /// This function demonstrates binding to a single . + /// [Function(nameof(QueueMessageFunction))] public void QueueMessageFunction([QueueTrigger("input-queue")] QueueMessage message) { _logger.LogInformation(message.MessageText); } + /// + /// This function demonstrates binding to a single . + /// [Function(nameof(QueueBinaryDataFunction))] public void QueueBinaryDataFunction([QueueTrigger("input-queue-binarydata")] BinaryData message) { _logger.LogInformation(message.ToString()); } - - [Function(nameof(QueueJsonFunction))] - public void QueueJsonFunction([QueueTrigger("input-queue-json")] JsonElement message) - { - _logger.LogInformation(message.ToString()); - } } } \ No newline at end of file diff --git a/samples/WorkerBindingSamples/Table/TableInputBindingSamples.cs b/samples/WorkerBindingSamples/Table/TableInputBindingSamples.cs deleted file mode 100644 index cd7cc27f8..000000000 --- a/samples/WorkerBindingSamples/Table/TableInputBindingSamples.cs +++ /dev/null @@ -1,118 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the MIT License. See License.txt in the project root for license information. - -using System.Net; -using Azure.Data.Tables; -using Microsoft.Azure.Functions.Worker; -using Microsoft.Azure.Functions.Worker.Http; -using Microsoft.Extensions.Logging; - -namespace WorkerBindingSamples.Table -{ - public class TableInputBindingSamples - { - private readonly ILogger _logger; - - public TableInputBindingSamples(ILogger logger) - { - _logger = logger; - } - - [Function(nameof(TableClientFunction))] - public async Task TableClientFunction( - [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, - [TableInput("TableName")] TableClient table) - { - var tableEntity = table.QueryAsync(); - var response = req.CreateResponse(HttpStatusCode.OK); - - await foreach (TableEntity val in tableEntity) - { - val.TryGetValue("Text", out var text); - _logger.LogInformation("Value of text: " + text); - - await response.WriteStringAsync(text?.ToString() ?? ""); - } - - return response; - } - - [Function(nameof(ReadTableDataFunction))] - public async Task ReadTableDataFunction( - [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "items/{partitionKey}/{rowKey}")] HttpRequestData req, - [TableInput("TableName", "{partitionKey}", "{rowKey}")] TableEntity table) - - { - table.TryGetValue("Text", out var text); - var response = req.CreateResponse(HttpStatusCode.OK); - await response.WriteStringAsync(text?.ToString() ?? ""); - return response; - } - - [Function(nameof(ReadTableDataFunctionWithFilter))] - public async Task ReadTableDataFunctionWithFilter( - [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, - [TableInput("TableName", "My Partition", 2, Filter = "RowKey ne 'value'")] IEnumerable table) - - { - List tableList = new(); - var response = req.CreateResponse(HttpStatusCode.OK); - - foreach (TableEntity tableEntity in table) - { - tableEntity.TryGetValue("Text", out var text); - _logger.LogInformation("Value of text: " + text); - tableList.Add(text?.ToString() ?? ""); - } - - await response.WriteStringAsync(string.Join(",", tableList)); - return response; - } - - [Function(nameof(EnumerableFunction))] - public async Task EnumerableFunction( - [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "items/{partitionKey}")] HttpRequestData req, - [TableInput("TableName", "{partitionKey}")] IEnumerable tables) - - { - var response = req.CreateResponse(HttpStatusCode.OK); - List tableList = new(); - - foreach (TableEntity tableEntity in tables) - { - tableEntity.TryGetValue("Text", out var text); - _logger.LogInformation("Value of text: " + text); - tableList.Add((text?.ToString()) ?? ""); - } - - await response.WriteStringAsync(string.Join(",", tableList)); - return response; - } - - [Function(nameof(PocoFunction))] - public async Task PocoFunction( - [HttpTrigger(AuthorizationLevel.Function, "get","post", Route = null)] HttpRequestData req, - [TableInput("TableName")] IEnumerable entities, - FunctionContext executionContext) - { - var response = req.CreateResponse(HttpStatusCode.OK); - List entityList = new(); - - foreach (MyEntity entity in entities) - { - _logger.LogInformation($"Text: {entity.Text}"); - entityList.Add((entity.Text ?? "").ToString()); - } - - await response.WriteStringAsync(string.Join(",", entityList)); - return response; - } - } - - public class MyEntity - { - public string? Text { get; set; } - public string? PartitionKey { get; set; } - public string? RowKey { get; set; } - } -} diff --git a/samples/WorkerBindingSamples/Table/TableSamples.cs b/samples/WorkerBindingSamples/Table/TableSamples.cs new file mode 100644 index 000000000..8eab43106 --- /dev/null +++ b/samples/WorkerBindingSamples/Table/TableSamples.cs @@ -0,0 +1,103 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using Azure.Data.Tables; +using Microsoft.Azure.Functions.Worker; +using Microsoft.Azure.Functions.Worker.Http; +using Microsoft.Extensions.Logging; + +namespace WorkerBindingSamples.Table +{ + /// + /// Samples demonstrating binding to , and types. + /// + public class TableSamples + { + private readonly ILogger _logger; + + public TableSamples(ILogger logger) + { + _logger = logger; + } + + /// + /// This function demonstrates binding to a single . + /// + [Function(nameof(TableClientFunction))] + public async Task TableClientFunction( + [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, + [TableInput("TableName")] TableClient table) + { + var tableEntity = table.QueryAsync(); + + await foreach (TableEntity entity in tableEntity) + { + _logger.LogInformation("PK={pk}, RK={rk}, Text={t}", entity.PartitionKey, entity.RowKey, entity["Text"]); + } + } + + /// + /// This function demonstrates binding to a single , using the + /// and properties. + /// + [Function(nameof(TableEntityFunction))] + public void TableEntityFunction( + [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "items/{partitionKey}/{rowKey}")] HttpRequestData req, + [TableInput("TableName", "{partitionKey}", "{rowKey}")] TableEntity entity) + { + _logger.LogInformation("PK={pk}, RK={rk}, Text={t}", entity.PartitionKey, entity.RowKey, entity["Text"]); + } + + /// + /// This function demonstrates binding to a collection of , using the . + /// Note that when the is not provided, you are able to bind to a collection. + /// + [Function(nameof(TableEntityCollectionFunction))] + public void TableEntityCollectionFunction( + [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "items/{partitionKey}")] HttpRequestData req, + [TableInput("TableName", "{partitionKey}")] IEnumerable entities) + { + foreach (var entity in entities) + { + _logger.LogInformation("PK={pk}, RK={rk}, Text={t}", entity.PartitionKey, entity.RowKey, entity["Text"]); + } + } + + /// + /// This function demonstrates binding to a collection of , using + /// to filter on the row key. This sample also demonstrates using + /// to limit the number of entities returned. + /// + [Function(nameof(TableEntityWithFilterFunction))] + public void TableEntityWithFilterFunction( + [HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, + [TableInput("TableName", "PartitionKey", 2, Filter = "RowKey ne 'value'")] IEnumerable entities) + { + foreach (var entity in entities) + { + _logger.LogInformation("PK={pk}, RK={rk}, Text={t}", entity.PartitionKey, entity.RowKey, entity["Text"]); + } + } + + /// + /// This function demonstrates binding to a collection of + /// + [Function(nameof(TablePocoFunction))] + public void TablePocoFunction( + [HttpTrigger(AuthorizationLevel.Function, "get","post", Route = null)] HttpRequestData req, + [TableInput("TableName")] IEnumerable entities) + { + foreach (var entity in entities) + { + _logger.LogInformation("PK={pk}, RK={rk}, Text={t}", entity.PartitionKey, entity.RowKey, entity.Text); + } + } + } + + public class MyEntity + { + public string? Text { get; set; } + public string? PartitionKey { get; set; } + public string? RowKey { get; set; } + } +} diff --git a/samples/WorkerBindingSamples/local.settings.json b/samples/WorkerBindingSamples/local.settings.json index 0f387030c..7a87bbf28 100644 --- a/samples/WorkerBindingSamples/local.settings.json +++ b/samples/WorkerBindingSamples/local.settings.json @@ -4,6 +4,7 @@ "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated", "AzureWebJobsStorage": "UseDevelopmentStorage=true", "CosmosDBConnection": "", + "EventHubConnection": "", "ServiceBusConnection": "" } } \ No newline at end of file From aa168cf7e633fac98f9d2ee11605f9ea743a89ad Mon Sep 17 00:00:00 2001 From: Lilian Kasem Date: Wed, 28 Jun 2023 09:55:52 -0700 Subject: [PATCH 2/2] update test metadata --- .../functions.metadata | 318 +++++------------- 1 file changed, 92 insertions(+), 226 deletions(-) diff --git a/test/SdkE2ETests/Contents/WorkerBindingSamplesOutput/functions.metadata b/test/SdkE2ETests/Contents/WorkerBindingSamplesOutput/functions.metadata index 32f0addd2..263c8c602 100644 --- a/test/SdkE2ETests/Contents/WorkerBindingSamplesOutput/functions.metadata +++ b/test/SdkE2ETests/Contents/WorkerBindingSamplesOutput/functions.metadata @@ -2,7 +2,7 @@ { "name": "TableClientFunction", "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.Table.TableInputBindingSamples.TableClientFunction", + "entryPoint": "WorkerBindingSamples.Table.TableSamples.TableClientFunction", "language": "dotnet-isolated", "properties": { "IsCodeless": false @@ -27,18 +27,13 @@ "properties": { "supportsDeferredBinding": "True" } - }, - { - "name": "$return", - "type": "http", - "direction": "Out" } ] }, { - "name": "ReadTableDataFunction", + "name": "TableEntityFunction", "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.Table.TableInputBindingSamples.ReadTableDataFunction", + "entryPoint": "WorkerBindingSamples.Table.TableSamples.TableEntityFunction", "language": "dotnet-isolated", "properties": { "IsCodeless": false @@ -57,7 +52,7 @@ "properties": {} }, { - "name": "table", + "name": "entity", "direction": "In", "type": "table", "tableName": "TableName", @@ -66,18 +61,13 @@ "properties": { "supportsDeferredBinding": "True" } - }, - { - "name": "$return", - "type": "http", - "direction": "Out" } ] }, { - "name": "ReadTableDataFunctionWithFilter", + "name": "TableEntityCollectionFunction", "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.Table.TableInputBindingSamples.ReadTableDataFunctionWithFilter", + "entryPoint": "WorkerBindingSamples.Table.TableSamples.TableEntityCollectionFunction", "language": "dotnet-isolated", "properties": { "IsCodeless": false @@ -92,31 +82,25 @@ "get", "post" ], + "route": "items/{partitionKey}", "properties": {} }, { - "name": "table", + "name": "entities", "direction": "In", "type": "table", "tableName": "TableName", - "partitionKey": "My Partition", - "take": 2, - "filter": "RowKey ne 'value'", + "partitionKey": "{partitionKey}", "properties": { "supportsDeferredBinding": "True" } - }, - { - "name": "$return", - "type": "http", - "direction": "Out" } ] }, { - "name": "EnumerableFunction", + "name": "TableEntityWithFilterFunction", "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.Table.TableInputBindingSamples.EnumerableFunction", + "entryPoint": "WorkerBindingSamples.Table.TableSamples.TableEntityWithFilterFunction", "language": "dotnet-isolated", "properties": { "IsCodeless": false @@ -131,30 +115,26 @@ "get", "post" ], - "route": "items/{partitionKey}", "properties": {} }, { - "name": "tables", + "name": "entities", "direction": "In", "type": "table", "tableName": "TableName", - "partitionKey": "{partitionKey}", + "partitionKey": "PartitionKey", + "take": 2, + "filter": "RowKey ne 'value'", "properties": { "supportsDeferredBinding": "True" } - }, - { - "name": "$return", - "type": "http", - "direction": "Out" } ] }, { - "name": "PocoFunction", + "name": "TablePocoFunction", "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.Table.TableInputBindingSamples.PocoFunction", + "entryPoint": "WorkerBindingSamples.Table.TableSamples.TablePocoFunction", "language": "dotnet-isolated", "properties": { "IsCodeless": false @@ -177,175 +157,6 @@ "type": "table", "tableName": "TableName", "properties": {} - }, - { - "name": "$return", - "type": "http", - "direction": "Out" - } - ] - }, - { - "name": "MyEventFunction", - "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.EventGrid.EventGridTriggerBindingSamples.MyEventFunction", - "language": "dotnet-isolated", - "properties": { - "IsCodeless": false - }, - "bindings": [ - { - "name": "input", - "direction": "In", - "type": "eventGridTrigger", - "cardinality": "One", - "properties": {} - } - ] - }, - { - "name": "CloudEventFunction", - "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.EventGrid.EventGridTriggerBindingSamples.CloudEventFunction", - "language": "dotnet-isolated", - "properties": { - "IsCodeless": false - }, - "bindings": [ - { - "name": "input", - "direction": "In", - "type": "eventGridTrigger", - "cardinality": "One", - "properties": {} - } - ] - }, - { - "name": "MultipleCloudEventFunction", - "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.EventGrid.EventGridTriggerBindingSamples.MultipleCloudEventFunction", - "language": "dotnet-isolated", - "properties": { - "IsCodeless": false - }, - "bindings": [ - { - "name": "input", - "direction": "In", - "type": "eventGridTrigger", - "cardinality": "Many", - "properties": {} - } - ] - }, - { - "name": "EventGridEvent", - "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.EventGrid.EventGridTriggerBindingSamples.EventGridEvent", - "language": "dotnet-isolated", - "properties": { - "IsCodeless": false - }, - "bindings": [ - { - "name": "input", - "direction": "In", - "type": "eventGridTrigger", - "cardinality": "One", - "properties": {} - } - ] - }, - { - "name": "EventGridEventArray", - "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.EventGrid.EventGridTriggerBindingSamples.EventGridEventArray", - "language": "dotnet-isolated", - "properties": { - "IsCodeless": false - }, - "bindings": [ - { - "name": "input", - "direction": "In", - "type": "eventGridTrigger", - "cardinality": "Many", - "properties": {} - } - ] - }, - { - "name": "BinaryDataEvent", - "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.EventGrid.EventGridTriggerBindingSamples.BinaryDataEvent", - "language": "dotnet-isolated", - "properties": { - "IsCodeless": false - }, - "bindings": [ - { - "name": "input", - "direction": "In", - "type": "eventGridTrigger", - "cardinality": "One", - "properties": {} - } - ] - }, - { - "name": "BinaryDataArrayEvent", - "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.EventGrid.EventGridTriggerBindingSamples.BinaryDataArrayEvent", - "language": "dotnet-isolated", - "properties": { - "IsCodeless": false - }, - "bindings": [ - { - "name": "input", - "direction": "In", - "type": "eventGridTrigger", - "cardinality": "Many", - "properties": {} - } - ] - }, - { - "name": "StringArrayEvent", - "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.EventGrid.EventGridTriggerBindingSamples.StringArrayEvent", - "language": "dotnet-isolated", - "properties": { - "IsCodeless": false - }, - "bindings": [ - { - "name": "input", - "direction": "In", - "type": "eventGridTrigger", - "cardinality": "Many", - "dataType": "String", - "properties": {} - } - ] - }, - { - "name": "StringEvent", - "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "WorkerBindingSamples.EventGrid.EventGridTriggerBindingSamples.StringEvent", - "language": "dotnet-isolated", - "properties": { - "IsCodeless": false - }, - "bindings": [ - { - "name": "input", - "direction": "In", - "type": "eventGridTrigger", - "dataType": "String", - "cardinality": "One", - "properties": {} } ] }, @@ -1131,11 +942,84 @@ "databaseName": "ToDoItems", "containerName": "TriggerItems", "connection": "CosmosDBConnection", + "leaseContainerName": "leases", "createLeaseContainerIfNotExists": true, "properties": {} } ] }, + { + "name": "CloudEventFunction", + "scriptFile": "WorkerBindingSamples.dll", + "entryPoint": "SampleApp.CloudEventSamples.CloudEventFunction", + "language": "dotnet-isolated", + "properties": { + "IsCodeless": false + }, + "bindings": [ + { + "name": "cloudEvent", + "direction": "In", + "type": "eventGridTrigger", + "cardinality": "One", + "properties": {} + } + ] + }, + { + "name": "CloudEventBatchFunction", + "scriptFile": "WorkerBindingSamples.dll", + "entryPoint": "SampleApp.CloudEventSamples.CloudEventBatchFunction", + "language": "dotnet-isolated", + "properties": { + "IsCodeless": false + }, + "bindings": [ + { + "name": "cloudEvents", + "direction": "In", + "type": "eventGridTrigger", + "cardinality": "Many", + "properties": {} + } + ] + }, + { + "name": "EventGridEventFunction", + "scriptFile": "WorkerBindingSamples.dll", + "entryPoint": "SampleApp.EventGridEventSamples.EventGridEventFunction", + "language": "dotnet-isolated", + "properties": { + "IsCodeless": false + }, + "bindings": [ + { + "name": "eventGridEvent", + "direction": "In", + "type": "eventGridTrigger", + "cardinality": "One", + "properties": {} + } + ] + }, + { + "name": "EventGridEventBatchFunction", + "scriptFile": "WorkerBindingSamples.dll", + "entryPoint": "SampleApp.EventGridEventSamples.EventGridEventBatchFunction", + "language": "dotnet-isolated", + "properties": { + "IsCodeless": false + }, + "bindings": [ + { + "name": "eventGridEvents", + "direction": "In", + "type": "eventGridTrigger", + "cardinality": "Many", + "properties": {} + } + ] + }, { "name": "EventDataFunctions", "scriptFile": "WorkerBindingSamples.dll", @@ -1205,7 +1089,7 @@ { "name": "QueueMessageFunction", "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "SampleApp.QueueTriggerBindingSamples.QueueMessageFunction", + "entryPoint": "SampleApp.QueueSamples.QueueMessageFunction", "language": "dotnet-isolated", "properties": { "IsCodeless": false @@ -1225,7 +1109,7 @@ { "name": "QueueBinaryDataFunction", "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "SampleApp.QueueTriggerBindingSamples.QueueBinaryDataFunction", + "entryPoint": "SampleApp.QueueSamples.QueueBinaryDataFunction", "language": "dotnet-isolated", "properties": { "IsCodeless": false @@ -1242,24 +1126,6 @@ } ] }, - { - "name": "QueueJsonFunction", - "scriptFile": "WorkerBindingSamples.dll", - "entryPoint": "SampleApp.QueueTriggerBindingSamples.QueueJsonFunction", - "language": "dotnet-isolated", - "properties": { - "IsCodeless": false - }, - "bindings": [ - { - "name": "message", - "direction": "In", - "type": "queueTrigger", - "queueName": "input-queue-json", - "properties": {} - } - ] - }, { "name": "ServiceBusReceivedMessageFunction", "scriptFile": "WorkerBindingSamples.dll",