-
Notifications
You must be signed in to change notification settings - Fork 451
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3fdaad
commit f074597
Showing
19 changed files
with
653 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Storage.Blobs; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Azure.Functions.Worker.Http; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace SampleApp | ||
{ | ||
public class BlobInputBindingSamples | ||
{ | ||
private readonly ILogger<BlobInputBindingSamples> _logger; | ||
|
||
public BlobInputBindingSamples(ILogger<BlobInputBindingSamples> logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
[Function(nameof(BlobInputClientFunction))] | ||
public async Task<HttpResponseData> BlobInputClientFunction( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, | ||
[BlobInput("test-input-sample/sample1.txt", Connection = "AzureWebJobsStorage")] BlobClient client) | ||
{ | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
var downloadResult = await client.DownloadContentAsync(); | ||
await response.Body.WriteAsync(downloadResult.Value.Content); | ||
return response; | ||
} | ||
|
||
[Function(nameof(BlobInputStreamFunction))] | ||
public async Task<HttpResponseData> BlobInputStreamFunction( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, | ||
[BlobInput("test-input-sample/sample1.txt", Connection = "AzureWebJobsStorage")] Stream stream) | ||
{ | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
using var blobStreamReader = new StreamReader(stream); | ||
await response.WriteStringAsync(blobStreamReader.ReadToEnd()); | ||
return response; | ||
} | ||
|
||
[Function(nameof(BlobInputByteArrayFunction))] | ||
public async Task<HttpResponseData> BlobInputByteArrayFunction( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, | ||
[BlobInput("test-input-sample/sample1.txt", Connection = "AzureWebJobsStorage")] Byte[] data) | ||
{ | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
await response.WriteStringAsync(Encoding.Default.GetString(data)); | ||
return response; | ||
} | ||
|
||
[Function(nameof(BlobInputStringFunction))] | ||
public async Task<HttpResponseData> BlobInputStringFunction( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, | ||
[BlobInput("test-input-sample/sample1.txt", Connection = "AzureWebJobsStorage")] string data) | ||
{ | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
await response.WriteStringAsync(data); | ||
return response; | ||
} | ||
|
||
[Function(nameof(BlobInputBookFunction))] | ||
public async Task<HttpResponseData> BlobInputBookFunction( | ||
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequestData req, | ||
[BlobInput("test-input-sample/book.json", Connection = "AzureWebJobsStorage")] Book data) | ||
{ | ||
var response = req.CreateResponse(HttpStatusCode.OK); | ||
await response.WriteStringAsync(data.Name); | ||
return response; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Azure.Storage.Blobs; | ||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace SampleApp | ||
{ | ||
public static class BlobTriggerBindingSamples | ||
{ | ||
[Function(nameof(BlobClientFunction))] | ||
public static async Task BlobClientFunction( | ||
[BlobTrigger("test-input-client/{name}", Connection = "AzureWebJobsStorage")] BlobClient client, | ||
FunctionContext context) | ||
{ | ||
var logger = context.GetLogger(nameof(BlobClientFunction)); | ||
var downloadResult = await client.DownloadContentAsync(); | ||
var content = downloadResult.Value.Content.ToString(); | ||
logger.LogInformation(content); | ||
} | ||
|
||
[Function(nameof(BlobStreamFunction))] | ||
public static void BlobStreamFunction( | ||
[BlobTrigger("test-input-stream/{name}", Connection = "AzureWebJobsStorage")] Stream stream, | ||
FunctionContext context) | ||
{ | ||
var logger = context.GetLogger(nameof(BlobStreamFunction)); | ||
using var blobStreamReader = new StreamReader(stream); | ||
logger.LogInformation(blobStreamReader.ReadToEnd()); | ||
} | ||
|
||
[Function(nameof(BlobByteArrayFunction))] | ||
public static void BlobByteArrayFunction( | ||
[BlobTrigger("test-input-byte/{name}", Connection = "AzureWebJobsStorage")] Byte[] data, | ||
FunctionContext context) | ||
{ | ||
var logger = context.GetLogger(nameof(BlobByteArrayFunction)); | ||
logger.LogInformation(Encoding.Default.GetString(data)); | ||
} | ||
|
||
[Function(nameof(BlobStringFunction))] | ||
public static void BlobStringFunction( | ||
[BlobTrigger("test-input-string/{name}", Connection = "AzureWebJobsStorage")] string data, | ||
FunctionContext context) | ||
{ | ||
var logger = context.GetLogger(nameof(BlobStringFunction)); | ||
logger.LogInformation(data); | ||
} | ||
|
||
[Function(nameof(BlobBookFunction))] | ||
public static void BlobBookFunction( | ||
[BlobTrigger("test-input-book/{name}", Connection = "AzureWebJobsStorage")] Book data, | ||
FunctionContext context) | ||
{ | ||
var logger = context.GetLogger(nameof(BlobBookFunction)); | ||
logger.LogInformation($"{data.Id} - {data.Name}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Azure.Functions.Worker; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace SampleApp | ||
{ | ||
public static class ExpressionFunction | ||
{ | ||
[Function(nameof(ExpressionFunction))] | ||
public static void Run( | ||
[QueueTrigger("test-input-sample", Connection = "AzureWebJobsStorage")] Book book, | ||
[BlobInput("test-input-sample/{id}.txt", Connection = "AzureWebJobsStorage")] string myBlob, | ||
FunctionContext context) | ||
{ | ||
var logger = context.GetLogger(nameof(ExpressionFunction)); | ||
logger.LogInformation(myBlob); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
namespace SampleApp | ||
{ | ||
public class Book | ||
{ | ||
public string Id { get; set; } | ||
public string Name { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<LangVersion>preview</LangVersion> | ||
<AzureFunctionsVersion>v4</AzureFunctionsVersion> | ||
<OutputType>Exe</OutputType> | ||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.11.0-preview2-20221104.9" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="5.0.2-preview1-20221104.9" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Queues" Version="5.0.0" /> | ||
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.8.0-preview3-20221104.9" /> | ||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> | ||
<PackageReference Include="System.Net.NameResolution" Version="4.3.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Update="host.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
<None Update="local.settings.json"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
<CopyToPublishDirectory>Never</CopyToPublishDirectory> | ||
</None> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
|
||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace SampleApp | ||
{ | ||
public class Program | ||
{ | ||
public static void Main() | ||
{ | ||
var host = new HostBuilder() | ||
.ConfigureFunctionsWorkerDefaults() | ||
.Build(); | ||
|
||
host.Run(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"version": "2.0", | ||
"logging": { | ||
"applicationInsights": { | ||
"samplingSettings": { | ||
"isEnabled": true, | ||
"excludedTypes": "Request" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.