Skip to content

Commit 0b89300

Browse files
tdavisjrthiennn
authored andcommitted
Added AzureBlobStorage module (#401)
1 parent 3dff461 commit 0b89300

File tree

5 files changed

+114
-1
lines changed

5 files changed

+114
-1
lines changed

SimplCommerce.sln

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.27130.2003
4+
VisualStudioVersion = 15.0.27130.2027
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C9BFDDC4-5671-47A3-B57D-197C2A51FA8A}"
77
EndProject
@@ -92,6 +92,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimplCommerce.Module.Paymen
9292
EndProject
9393
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SimplCommerce.Module.PaymentStripe", "src\Modules\SimplCommerce.Module.PaymentStripe\SimplCommerce.Module.PaymentStripe.csproj", "{91C58341-5EE8-4FF1-9FAB-BED234C3EBE6}"
9494
EndProject
95+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimplCommerce.Module.StorageAzureBlob", "src\Modules\SimplCommerce.Module.StorageAzureBlob\SimplCommerce.Module.StorageAzureBlob.csproj", "{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}"
96+
EndProject
9597
Global
9698
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9799
Debug|Any CPU = Debug|Any CPU
@@ -546,6 +548,18 @@ Global
546548
{91C58341-5EE8-4FF1-9FAB-BED234C3EBE6}.Release|x64.Build.0 = Release|Any CPU
547549
{91C58341-5EE8-4FF1-9FAB-BED234C3EBE6}.Release|x86.ActiveCfg = Release|Any CPU
548550
{91C58341-5EE8-4FF1-9FAB-BED234C3EBE6}.Release|x86.Build.0 = Release|Any CPU
551+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
552+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
553+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Debug|x64.ActiveCfg = Debug|Any CPU
554+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Debug|x64.Build.0 = Debug|Any CPU
555+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Debug|x86.ActiveCfg = Debug|Any CPU
556+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Debug|x86.Build.0 = Debug|Any CPU
557+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
558+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Release|Any CPU.Build.0 = Release|Any CPU
559+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Release|x64.ActiveCfg = Release|Any CPU
560+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Release|x64.Build.0 = Release|Any CPU
561+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Release|x86.ActiveCfg = Release|Any CPU
562+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6}.Release|x86.Build.0 = Release|Any CPU
549563
EndGlobalSection
550564
GlobalSection(SolutionProperties) = preSolution
551565
HideSolutionNode = FALSE
@@ -590,6 +604,7 @@ Global
590604
{A87A5CF6-3FFB-40D0-A82B-0BD29C0F0C65} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
591605
{A43132C2-BD56-4B39-8BDB-280A3230D8C9} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
592606
{91C58341-5EE8-4FF1-9FAB-BED234C3EBE6} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
607+
{21A7421A-DF8B-4E1C-96A8-1FF7FF8EA6F6} = {7EFA2FA7-32DD-4047-B021-50E77A83D714}
593608
EndGlobalSection
594609
GlobalSection(ExtensibilityGlobals) = postSolution
595610
SolutionGuid = {B9D0D8F0-1AB9-44DD-839F-ED8CEE7DDB10}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Microsoft.WindowsAzure.Storage;
3+
using Microsoft.WindowsAzure.Storage.Blob;
4+
using SimplCommerce.Module.Core.Services;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Diagnostics.Contracts;
8+
using System.IO;
9+
using System.Linq;
10+
using System.Text;
11+
using System.Threading.Tasks;
12+
13+
namespace SimplCommerce.Module.StorageAzureBlob
14+
{
15+
public class AzureBlobStorageService : IStorageService
16+
{
17+
private CloudBlobContainer _blobContainer;
18+
19+
public AzureBlobStorageService(IConfiguration configuration)
20+
{
21+
var storageConnectionString = configuration["Azure:Blob:StorageConnectionString"];
22+
var containerName = configuration["Azure:Blob:ContainerName"];
23+
24+
Contract.Requires(string.IsNullOrWhiteSpace(storageConnectionString));
25+
Contract.Requires(string.IsNullOrWhiteSpace(containerName));
26+
27+
var storageAccount = CloudStorageAccount.Parse(storageConnectionString);
28+
29+
var blobClient = storageAccount.CreateCloudBlobClient();
30+
_blobContainer = blobClient.GetContainerReference(containerName);
31+
32+
}
33+
public async Task DeleteMediaAsync(string fileName)
34+
{
35+
var blockBlob = _blobContainer.GetBlockBlobReference(fileName);
36+
await blockBlob.DeleteIfExistsAsync();
37+
}
38+
39+
public string GetMediaUrl(string fileName)
40+
{
41+
return $"{_blobContainer.Uri.AbsoluteUri}/{fileName}";
42+
}
43+
44+
public async Task SaveMediaAsync(Stream mediaBinaryStream, string fileName, string mimeType = null)
45+
{
46+
await _blobContainer.SetPermissionsAsync(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Container });
47+
await _blobContainer.CreateIfNotExistsAsync();
48+
49+
var blockBlob = _blobContainer.GetBlockBlobReference(fileName);
50+
51+
await blockBlob.UploadFromStreamAsync(mediaBinaryStream);
52+
}
53+
54+
}
55+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.AspNetCore.Hosting;
4+
using SimplCommerce.Infrastructure;
5+
using SimplCommerce.Module.Core.Services;
6+
7+
namespace SimplCommerce.Module.StorageAzureBlob
8+
{
9+
public class ModuleInitializer : IModuleInitializer
10+
{
11+
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
12+
{
13+
14+
}
15+
16+
public void ConfigureServices(IServiceCollection serviceCollection)
17+
{
18+
serviceCollection.AddSingleton<IStorageService, AzureBlobStorageService>();
19+
}
20+
}
21+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
<PreserveCompilationContext>false</PreserveCompilationContext>
6+
<EnableDefaultContentItems>false</EnableDefaultContentItems>
7+
<OutputType>Library</OutputType>
8+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<PackageReference Include="WindowsAzure.Storage" Version="9.0.0" />
13+
<ProjectReference Include="..\..\SimplCommerce.Infrastructure\SimplCommerce.Infrastructure.csproj" />
14+
<ProjectReference Include="..\SimplCommerce.Module.Core\SimplCommerce.Module.Core.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "storage-azure-blob",
3+
"fullName": "SimplCommerce.Module.StorageAzureBlob",
4+
"version": "1.0.0"
5+
}

0 commit comments

Comments
 (0)