-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add connection string-based implementation of Azure Blob Storage
- Loading branch information
Showing
8 changed files
with
93 additions
and
14 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
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 |
---|---|---|
@@ -1,25 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using AzureIdentityLivestream.Web.Services; | ||
using Microsoft.AspNetCore.Mvc.RazorPages; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace AzureIdentityLivestream.Web.Pages | ||
{ | ||
public class IndexModel : PageModel | ||
{ | ||
private readonly ILogger<IndexModel> _logger; | ||
private readonly IPersonProvider _personProvider; | ||
|
||
public IndexModel(ILogger<IndexModel> logger) | ||
public IndexModel(IPersonProvider personProvider) | ||
{ | ||
_logger = logger; | ||
_personProvider = personProvider; | ||
} | ||
|
||
public void OnGet() | ||
public async Task OnGet() | ||
{ | ||
|
||
People = await _personProvider.GetPeople(); | ||
PersonProviderTypeName = _personProvider.GetType().Name; | ||
} | ||
|
||
public IEnumerable<Person> People { get; set; } | ||
public string PersonProviderTypeName { get; set; } | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/AzureIdentityLivestream.Web/Services/AzureBlobStorage/AzureBlobStoragePersonProvider.cs
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,38 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Azure.Storage.Blobs; | ||
|
||
namespace AzureIdentityLivestream.Web.Services.AzureBlobStorage | ||
{ | ||
public class AzureBlobStoragePersonProvider : IPersonProvider | ||
{ | ||
private readonly BlobServiceClient _blobServiceClient; | ||
|
||
public AzureBlobStoragePersonProvider(BlobServiceClient blobServiceClient) | ||
{ | ||
_blobServiceClient = blobServiceClient; | ||
} | ||
|
||
public async Task<IEnumerable<Person>> GetPeople() | ||
{ | ||
List<Person> people = new(); | ||
|
||
var containerClient = _blobServiceClient.GetBlobContainerClient("people"); | ||
var blobs = containerClient.GetBlobsAsync(); | ||
await foreach (var blob in blobs) | ||
{ | ||
var blobClient = containerClient.GetBlobClient(blob.Name); | ||
|
||
await using var personStream = new MemoryStream(); | ||
var blobDownloadInfo = await blobClient.DownloadAsync(); | ||
var person = await JsonSerializer.DeserializeAsync<Person>(blobDownloadInfo.Value.Content); | ||
|
||
people.Add(person); | ||
} | ||
|
||
return people; | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/AzureIdentityLivestream.Web/Services/IPersonProvider.cs
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,10 @@ | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
|
||
namespace AzureIdentityLivestream.Web.Services | ||
{ | ||
public interface IPersonProvider | ||
{ | ||
Task<IEnumerable<Person>> GetPeople(); | ||
} | ||
} |
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,4 @@ | ||
namespace AzureIdentityLivestream.Web.Services | ||
{ | ||
public record Person(string FirstName, string LastName, int Age); | ||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"StorageConnectionString": "UseDevelopmentStorage=true", | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
|