Skip to content

Commit 1bbaa54

Browse files
committed
Added ProcessFile.cs to handle blob events in Azure Storage.
1 parent efff872 commit 1bbaa54

File tree

5 files changed

+121
-0
lines changed

5 files changed

+121
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.IO;
2+
using System.Threading.Tasks;
3+
using Microsoft.Azure.Functions.Worker;
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace azure_project_generator
7+
{
8+
public class ProcessFile
9+
{
10+
private readonly ILogger<ProcessFile> _logger;
11+
12+
public ProcessFile(ILogger<ProcessFile> logger)
13+
{
14+
_logger = logger;
15+
}
16+
17+
[Function(nameof(ProcessFile))]
18+
public async Task Run([BlobTrigger("raw/{name}", Connection = "AzureWebJobsStorage")] Stream stream, string name)
19+
{
20+
using var blobStreamReader = new StreamReader(stream);
21+
var content = await blobStreamReader.ReadToEndAsync();
22+
_logger.LogInformation($"C# Blob trigger function Processed blob\n Name: {name} \n Data: {content}");
23+
}
24+
}
25+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"resourceGroupName": {
6+
"type": "string",
7+
"defaultValue": "azureprojectgenerator-rg",
8+
"metadata": {
9+
"_parameterType": "resourceGroup",
10+
"description": "Name of the resource group for the resource. It is recommended to put resources under same resource group for better tracking."
11+
}
12+
},
13+
"resourceGroupLocation": {
14+
"type": "string",
15+
"defaultValue": "eastus",
16+
"metadata": {
17+
"_parameterType": "location",
18+
"description": "Location of the resource group. Resource groups could have different location than resources."
19+
}
20+
},
21+
"resourceLocation": {
22+
"type": "string",
23+
"defaultValue": "[parameters('resourceGroupLocation')]",
24+
"metadata": {
25+
"_parameterType": "location",
26+
"description": "Location of the resource. By default use resource group's location, unless the resource provider is not supported there."
27+
}
28+
}
29+
},
30+
"resources": [
31+
{
32+
"type": "Microsoft.Resources/resourceGroups",
33+
"name": "[parameters('resourceGroupName')]",
34+
"location": "[parameters('resourceGroupLocation')]",
35+
"apiVersion": "2019-10-01"
36+
},
37+
{
38+
"type": "Microsoft.Resources/deployments",
39+
"name": "[concat(parameters('resourceGroupName'), 'Deployment', uniqueString(concat('azureprojectgenstor', subscription().subscriptionId)))]",
40+
"resourceGroup": "[parameters('resourceGroupName')]",
41+
"apiVersion": "2019-10-01",
42+
"dependsOn": [
43+
"[parameters('resourceGroupName')]"
44+
],
45+
"properties": {
46+
"mode": "Incremental",
47+
"template": {
48+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
49+
"contentVersion": "1.0.0.0",
50+
"resources": [
51+
{
52+
"sku": {
53+
"name": "Standard_RAGRS",
54+
"tier": "Standard"
55+
},
56+
"kind": "StorageV2",
57+
"name": "azureprojectgenstor",
58+
"type": "Microsoft.Storage/storageAccounts",
59+
"location": "[parameters('resourceLocation')]",
60+
"apiVersion": "2017-10-01"
61+
}
62+
]
63+
}
64+
}
65+
}
66+
],
67+
"metadata": {
68+
"_dependencyType": "storage.azure"
69+
}
70+
}

azure-project-generator/Properties/serviceDependencies.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
"storage1": {
77
"type": "storage",
88
"connectionId": "AzureWebJobsStorage"
9+
},
10+
"secrets1": {
11+
"type": "secrets"
12+
},
13+
"storage2": {
14+
"type": "storage",
15+
"connectionId": "azurestorage",
16+
"dynamicId": null
917
}
1018
}
1119
}

azure-project-generator/Properties/serviceDependencies.local.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,17 @@
66
"storage1": {
77
"type": "storage.emulator",
88
"connectionId": "AzureWebJobsStorage"
9+
},
10+
"secrets1": {
11+
"type": "secrets.user"
12+
},
13+
"storage2": {
14+
"serviceConnectorResourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/Microsoft.ServiceLinker/locations/eastus/connectors/azurestorage_B223BFB07A",
15+
"secretStore": "LocalSecretsFile",
16+
"resourceId": "/subscriptions/[parameters('subscriptionId')]/resourceGroups/[parameters('resourceGroupName')]/providers/Microsoft.Storage/storageAccounts/azureprojectgenstor",
17+
"type": "storage.azure",
18+
"connectionId": "azurestorage",
19+
"dynamicId": null
920
}
1021
}
1122
}

azure-project-generator/azure-project-generator.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Nullable>enable</Nullable>
88
<RootNamespace>azure_project_generator</RootNamespace>
9+
<UserSecretsId>1d7c9e7d-f7ff-4f28-a6f1-943f954af989</UserSecretsId>
910
</PropertyGroup>
1011
<ItemGroup>
12+
<PackageReference Include="Azure.Storage.Blobs" Version="12.20.0" />
13+
<PackageReference Include="Azure.Storage.Files.Shares" Version="12.18.0" />
14+
<PackageReference Include="Azure.Storage.Queues" Version="12.18.0" />
1115
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
1216
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
17+
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage.Blobs" Version="6.0.0" />
1318
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.2" />
1419
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
1520
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.0.0" />
21+
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.3" />
22+
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
1623
</ItemGroup>
1724
<ItemGroup>
1825
<None Update="host.json">

0 commit comments

Comments
 (0)