mirror of https://github.com/Squidex/squidex.git
8 changed files with 83 additions and 178 deletions
@ -1,15 +1,12 @@ |
|||
<Project Sdk="Microsoft.NET.Sdk"> |
|||
|
|||
<PropertyGroup> |
|||
<TargetFramework>netstandard1.6</TargetFramework> |
|||
<RootNamespace>Squidex.Infrastructure</RootNamespace> |
|||
</PropertyGroup> |
|||
|
|||
<ItemGroup> |
|||
<PackageReference Include="WindowsAzure.Storage" Version="8.2.0" /> |
|||
</ItemGroup> |
|||
|
|||
<ItemGroup> |
|||
<ProjectReference Include="..\Squidex.Infrastructure\Squidex.Infrastructure.csproj" /> |
|||
</ItemGroup> |
|||
|
|||
</Project> |
|||
@ -1,22 +0,0 @@ |
|||
// ==========================================================================
|
|||
// IStorageAccountManager.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Threading.Tasks; |
|||
using Microsoft.WindowsAzure.Storage.Blob; |
|||
|
|||
namespace Squidex.Infrastructure.Azure.Storage |
|||
{ |
|||
public interface IStorageAccountManager |
|||
{ |
|||
CloudBlobClient CreateCloudBlobClient(); |
|||
|
|||
string GetSharedAccessSignature(); |
|||
|
|||
Task<CloudBlobContainer> GetContainerAsync(string name); |
|||
} |
|||
} |
|||
@ -1,57 +0,0 @@ |
|||
// ==========================================================================
|
|||
// IStorageAccountManager.cs
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex Group
|
|||
// All rights reserved.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.WindowsAzure.Storage; |
|||
using Microsoft.WindowsAzure.Storage.Blob; |
|||
|
|||
namespace Squidex.Infrastructure.Azure.Storage |
|||
{ |
|||
public class StorageAccountManager : IStorageAccountManager |
|||
{ |
|||
private readonly CloudStorageAccount storageAccount; |
|||
|
|||
public StorageAccountManager(string storageAccountConnectionString) |
|||
{ |
|||
try |
|||
{ |
|||
storageAccount = CloudStorageAccount.Parse(storageAccountConnectionString); |
|||
} |
|||
catch (Exception ex) |
|||
when (ex is FormatException || ex is ArgumentException) |
|||
{ |
|||
throw new ConfigurationException("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app settings file."); |
|||
} |
|||
} |
|||
|
|||
public CloudBlobClient CreateCloudBlobClient() |
|||
{ |
|||
return storageAccount.CreateCloudBlobClient(); |
|||
} |
|||
|
|||
public string GetSharedAccessSignature() |
|||
{ |
|||
return storageAccount.GetSharedAccessSignature(new SharedAccessAccountPolicy() |
|||
{ |
|||
SharedAccessStartTime = DateTimeOffset.UtcNow, |
|||
SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddHours(1), |
|||
Permissions = SharedAccessAccountPermissions.Read | SharedAccessAccountPermissions.List |
|||
}); |
|||
} |
|||
|
|||
public async Task<CloudBlobContainer> GetContainerAsync(string name) |
|||
{ |
|||
var blobClient = CreateCloudBlobClient(); |
|||
var container = blobClient.GetContainerReference(name); |
|||
await container.CreateIfNotExistsAsync(); |
|||
|
|||
return container; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue