Skip to content

Commit ab51f3c

Browse files
authored
Merge pull request Azure#9 from Azure/triggerbinding
Preliminary Design of Trigger Binding
2 parents 2fe4652 + 7eacba4 commit ab51f3c

32 files changed

+1724
-156
lines changed

samples/SqlExtensionSamples/InputBindingSamples/GetProducts.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Http;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Http;
25
using Microsoft.AspNetCore.Mvc;
36
using Microsoft.Azure.WebJobs;
47
using Microsoft.Azure.WebJobs.Extensions.Http;
@@ -17,7 +20,7 @@ public static IActionResult Run(
1720
[Sql("select * from Products where Cost = @Cost",
1821
CommandType = System.Data.CommandType.Text,
1922
Parameters = "@Cost={cost}",
20-
ConnectionStringSetting = "SQLServerAuthentication")]
23+
ConnectionStringSetting = "SqlConnectionString")]
2124
IEnumerable<Product> products)
2225
{
2326
return (ActionResult)new OkObjectResult(products);

samples/SqlExtensionSamples/InputBindingSamples/GetProductsAsyncEnumerable.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Http;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Http;
25
using Microsoft.AspNetCore.Mvc;
36
using Microsoft.Azure.WebJobs;
47
using Microsoft.Azure.WebJobs.Extensions.Http;
@@ -13,14 +16,14 @@ public static class GetProductsAsyncEnumerable
1316
[FunctionName("GetProductsAsyncEnumerable")]
1417
public static async Task<IActionResult> Run(
1518
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "getproducts-async/{cost}")]
16-
HttpRequest req,
19+
HttpRequest req,
1720
[Sql("select * from Products where cost = @Cost",
1821
CommandType = System.Data.CommandType.Text,
1922
Parameters = "@Cost={cost}",
20-
ConnectionStringSetting = "SQLServerAuthentication")]
23+
ConnectionStringSetting = "SqlConnectionString")]
2124
IAsyncEnumerable<Product> products)
2225
{
23-
var enumerator = products.GetAsyncEnumerator();
26+
IAsyncEnumerator<Product> enumerator = products.GetAsyncEnumerator();
2427
var productList = new List<Product>();
2528
while (await enumerator.MoveNextAsync())
2629
{

samples/SqlExtensionSamples/InputBindingSamples/GetProductsNameEmpty.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Http;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Http;
25
using Microsoft.AspNetCore.Mvc;
36
using Microsoft.Azure.WebJobs;
47
using Microsoft.Azure.WebJobs.Extensions.Http;
@@ -17,7 +20,7 @@ public static IActionResult Run(
1720
[Sql("select * from Products where Cost = @Cost and Name = @Name",
1821
CommandType = System.Data.CommandType.Text,
1922
Parameters = "@Cost={cost},@Name=",
20-
ConnectionStringSetting = "SQLServerAuthentication")]
23+
ConnectionStringSetting = "SqlConnectionString")]
2124
IEnumerable<Product> products)
2225
{
2326
return (ActionResult)new OkObjectResult(products);

samples/SqlExtensionSamples/InputBindingSamples/GetProductsNameNull.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Http;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Http;
25
using Microsoft.AspNetCore.Mvc;
36
using Microsoft.Azure.WebJobs;
47
using Microsoft.Azure.WebJobs.Extensions.Http;
@@ -20,7 +23,7 @@ public static IActionResult Run(
2023
[Sql("if @Name is null select * from Products where Name is null else select * from Products where @Name = name",
2124
CommandType = System.Data.CommandType.Text,
2225
Parameters = "@Name={name}",
23-
ConnectionStringSetting = "SQLServerAuthentication")]
26+
ConnectionStringSetting = "SqlConnectionString")]
2427
IEnumerable<Product> products)
2528
{
2629
return (ActionResult)new OkObjectResult(products);

samples/SqlExtensionSamples/InputBindingSamples/GetProductsSqlCommand.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Http;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Http;
25
using Microsoft.AspNetCore.Mvc;
36
using Microsoft.Azure.WebJobs;
47
using Microsoft.Azure.WebJobs.Extensions.Http;
@@ -17,7 +20,7 @@ public static IActionResult Run(
1720
[Sql("select * from Products where cost = @Cost",
1821
CommandType = System.Data.CommandType.Text,
1922
Parameters = "@Cost={cost}",
20-
ConnectionStringSetting = "SQLServerAuthentication")]
23+
ConnectionStringSetting = "SqlConnectionString")]
2124
SqlCommand command)
2225
{
2326
string result = string.Empty;
@@ -28,7 +31,7 @@ public static IActionResult Run(
2831
{
2932
while (reader.Read())
3033
{
31-
result += String.Format("ProductID: {0}, Cost: {1}, Name: {2}\n", reader[0], reader[1], reader[2]);
34+
result += $"ProductID: {reader["ProductID"]}, Name: {reader["Name"]}, Cost: {reader["Cost"]}\n";
3235
}
3336
}
3437
}

samples/SqlExtensionSamples/InputBindingSamples/GetProductsStoredProcedure.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Http;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Http;
25
using Microsoft.AspNetCore.Mvc;
36
using Microsoft.Azure.WebJobs;
47
using Microsoft.Azure.WebJobs.Extensions.Http;
@@ -17,7 +20,7 @@ public static IActionResult Run(
1720
[Sql("SelectProductsCost",
1821
CommandType = System.Data.CommandType.StoredProcedure,
1922
Parameters = "@Cost={cost}",
20-
ConnectionStringSetting = "SQLServerAuthentication")]
23+
ConnectionStringSetting = "SqlConnectionString")]
2124
IEnumerable<Product> products)
2225
{
2326
return (ActionResult)new OkObjectResult(products);

samples/SqlExtensionSamples/InputBindingSamples/GetProductsString.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Http;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Http;
25
using Microsoft.AspNetCore.Mvc;
36
using Microsoft.Azure.WebJobs;
47
using Microsoft.Azure.WebJobs.Extensions.Http;
@@ -14,7 +17,7 @@ public static IActionResult Run(
1417
[Sql("select * from Products where cost = @Cost",
1518
CommandType = System.Data.CommandType.Text,
1619
Parameters = "@Cost={cost}",
17-
ConnectionStringSetting = "SQLServerAuthentication")]
20+
ConnectionStringSetting = "SqlConnectionString")]
1821
string products)
1922
{
2023
// Products is a JSON representation of the returned rows. For example, if there are two returned rows,

samples/SqlExtensionSamples/OutputBindingSamples/AddProduct.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
14
using Microsoft.AspNetCore.Mvc;
25
using Microsoft.Azure.WebJobs;
36
using Microsoft.Azure.WebJobs.Extensions.Http;
@@ -11,9 +14,9 @@ public static class AddProduct
1114
{
1215
[FunctionName("AddProduct")]
1316
public static IActionResult Run(
14-
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addproduct")]
17+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addproduct")]
1518
HttpRequest req,
16-
[Sql("Products", ConnectionStringSetting = "SQLServerAuthentication")] out Product product)
19+
[Sql("Products", ConnectionStringSetting = "SqlConnectionString")] out Product product)
1720
{
1821
product = new Product
1922
{

samples/SqlExtensionSamples/OutputBindingSamples/AddProductsArray.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
using Microsoft.AspNetCore.Mvc;
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Mvc;
25
using Microsoft.Azure.WebJobs;
36
using Microsoft.Azure.WebJobs.Extensions.Http;
47
using Microsoft.AspNetCore.Http;
@@ -10,24 +13,28 @@ public static class AddProductsArray
1013
{
1114
[FunctionName("AddProductsArray")]
1215
public static IActionResult Run(
13-
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addproducts-array")]
16+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addproducts-array")]
1417
HttpRequest req,
15-
[Sql("dbo.Products", ConnectionStringSetting = "SQLServerAuthentication")] out Product[] output)
18+
[Sql("dbo.Products", ConnectionStringSetting = "SqlConnectionString")] out Product[] output)
1619
{
1720
// Suppose that the ProductID column is the primary key in the Products table, and the
1821
// table already contains a row with ProductID = 1. In that case, the row will be updated
1922
// instead of inserted to have values Name = "Cup" and Cost = 2.
20-
output = new Product[2];
21-
var product = new Product();
22-
product.ProductID = 1;
23-
product.Name = "Cup";
24-
product.Cost = 2;
25-
output[0] = product;
26-
product = new Product();
27-
product.ProductID = 2;
28-
product.Name = "Glasses";
29-
product.Cost = 12;
30-
output[1] = product;
23+
output = new[]
24+
{
25+
new Product
26+
{
27+
ProductID = 1,
28+
Name = "Cup",
29+
Cost = 2
30+
},
31+
new Product
32+
{
33+
ProductID = 2,
34+
Name = "Glasses",
35+
Cost = 12
36+
}
37+
};
3138
return new CreatedResult($"/api/addproducts-array", output);
3239
}
3340
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using Microsoft.AspNetCore.Mvc;
5+
using Microsoft.Azure.WebJobs;
6+
using Microsoft.Azure.WebJobs.Extensions.Http;
7+
using Microsoft.AspNetCore.Http;
8+
using static SqlExtensionSamples.ProductUtilities;
9+
using System.Threading.Tasks;
10+
using System.Collections.Generic;
11+
12+
namespace SqlExtensionSamples
13+
{
14+
public static class AddProductsAsyncCollector
15+
{
16+
[FunctionName("AddProductsAsyncCollector")]
17+
public static async Task<IActionResult> Run(
18+
[HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "addproducts-asynccollector")]
19+
HttpRequest req,
20+
[Sql("Products", ConnectionStringSetting = "SqlConnectionString")] IAsyncCollector<Product> products)
21+
{
22+
List<Product> newProducts = GetNewProducts(5000);
23+
foreach (var product in newProducts)
24+
{
25+
await products.AddAsync(product);
26+
}
27+
// Rows are upserted here
28+
await products.FlushAsync();
29+
30+
newProducts = GetNewProducts(5000);
31+
foreach (var product in newProducts)
32+
{
33+
await products.AddAsync(product);
34+
}
35+
return new CreatedResult($"/api/addproducts-collector", "done");
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)