Browse Source

added azure storage implementation for new IAssetStore methods.

pull/76/head
pushrbx 9 years ago
parent
commit
1c8c43188a
  1. 40
      src/Squidex.Infrastructure.Azure/Storage/AzureBlobAssetStore.cs

40
src/Squidex.Infrastructure.Azure/Storage/AzureBlobAssetStore.cs

@ -9,6 +9,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Squidex.Infrastructure.Assets;
@ -31,6 +32,33 @@ namespace Squidex.Infrastructure.Azure.Storage
this.containerName = containerName;
}
public async Task CopyTemporaryAsync(string name, string id, long version, string suffix)
{
var blobName = GetObjectName(id, version, suffix);
var blobSource = blobContainer.GetBlockBlobReference(name);
var targetTemporaryBlob = blobContainer.GetBlobReference(blobName);
try
{
await targetTemporaryBlob.StartCopyAsync(blobSource.Uri);
while (targetTemporaryBlob.CopyState.Status == CopyStatus.Pending)
{
await Task.Delay(500);
await targetTemporaryBlob.FetchAttributesAsync();
}
if (targetTemporaryBlob.CopyState.Status != CopyStatus.Success)
throw new Exception($"Copy of temporary file failed: {targetTemporaryBlob.CopyState.Status}");
}
catch (StorageException ex)
{
var requestInformation = ex.RequestInformation;
if (requestInformation.HttpStatusCode == 404)
throw new AssetNotFoundException($"Asset {name} not found.", ex);
throw;
}
}
public async Task DownloadAsync(string id, long version, string suffix, Stream stream)
{
var blobName = GetObjectName(id, version, suffix);
@ -42,6 +70,12 @@ namespace Squidex.Infrastructure.Azure.Storage
await blob.DownloadToStreamAsync(stream);
}
public async Task UploadTemporaryAsync(string name, Stream stream)
{
var blob = blobContainer.GetBlockBlobReference(name);
await blob.UploadFromStreamAsync(stream);
}
public async Task UploadAsync(string id, long version, string suffix, Stream stream)
{
var blobName = GetObjectName(id, version, suffix);
@ -54,6 +88,12 @@ namespace Squidex.Infrastructure.Azure.Storage
await blob.SetMetadataAsync();
}
public async Task DeleteTemporaryAsync(string name)
{
var blob = blobContainer.GetBlockBlobReference(name);
await blob.DeleteIfExistsAsync();
}
public void Connect()
{
try

Loading…
Cancel
Save