Browse Source

refined it even moaar.

pull/76/head
pushrbx 9 years ago
parent
commit
4c604ac06c
  1. 20
      src/Squidex.Infrastructure.Azure/Storage/AzureBlobAssetStore.cs
  2. 29
      src/Squidex.Infrastructure.Azure/Storage/AzureStorageException.cs
  3. 2
      src/Squidex.Infrastructure.Azure/Storage/StorageAccountManager.cs
  4. 55
      src/Squidex.Infrastructure.Redis/EventStore/RedisEventStore.cs

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

@ -47,16 +47,7 @@ namespace Squidex.Infrastructure.Azure.Storage
var blobName = GetObjectName(id, version, suffix);
var blob = blobContainer.GetBlockBlobReference(blobName);
if (await blob.ExistsAsync())
{
return;
}
if (!blob.Metadata.ContainsKey(AssetVersion))
blob.Metadata.Add(AssetVersion, version.ToString());
else
blob.Metadata[AssetVersion] = version.ToString();
blob.Metadata[AssetVersion] = version.ToString();
blob.Metadata[AssetId] = id;
await blob.UploadFromStreamAsync(stream);
@ -65,7 +56,14 @@ namespace Squidex.Infrastructure.Azure.Storage
public void Connect()
{
blobContainer = azureStorageAccount.GetContainer(containerName);
try
{
blobContainer = azureStorageAccount.GetContainer(containerName);
}
catch (Exception)
{
throw new ConfigurationException($"Cannot connect to blob container '{containerName}'.");
}
}
private string GetObjectName(string id, long version, string suffix)

29
src/Squidex.Infrastructure.Azure/Storage/AzureStorageException.cs

@ -1,29 +0,0 @@
// ==========================================================================
// AzureStorageException.cs
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex Group
// All rights reserved.
// ==========================================================================
using System;
using Microsoft.WindowsAzure.Storage;
namespace Squidex.Infrastructure.Azure.Storage
{
[Serializable]
public class AzureStorageException : StorageException
{
public AzureStorageException()
{
}
public AzureStorageException(string message) : base(message)
{
}
public AzureStorageException(string message, Exception inner) : base(message, inner)
{
}
}
}

2
src/Squidex.Infrastructure.Azure/Storage/StorageAccountManager.cs

@ -26,7 +26,7 @@ namespace Squidex.Infrastructure.Azure.Storage
catch (Exception ex)
when (ex is FormatException || ex is ArgumentException)
{
throw new AzureStorageException("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app settings file.");
throw new ConfigurationException("Invalid storage account information provided. Please confirm the AccountName and AccountKey are valid in the app settings file.");
}
}

55
src/Squidex.Infrastructure.Redis/EventStore/RedisEventStore.cs

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Squidex.Infrastructure.CQRS.Events;
using StackExchange.Redis;
namespace Squidex.Infrastructure.Redis.EventStore
{
public class RedisEventStore : IEventStore, IExternalSystem
{
private readonly Lazy<IConnectionMultiplexer> redisClient;
public RedisEventStore(Lazy<IConnectionMultiplexer> redis)
{
this.redisClient = redis;
}
public Task<IReadOnlyList<StoredEvent>> GetEventsAsync(string streamName)
{
var db = redisClient.Value.GetDatabase();
throw new NotImplementedException();
}
public Task AppendEventsAsync(Guid commitId, string streamName, int expectedVersion, ICollection<EventData> events)
{
throw new NotImplementedException();
}
public IEventSubscription CreateSubscription(string streamFilter = null, string position = null)
{
throw new NotImplementedException();
}
public void Connect()
{
try
{
redisClient.Value.GetStatus();
var db = redisClient.Value.GetDatabase();
if (!db.HashExists("SquidexEventStore", 0))
{
db.HashSet("SquidexEventStore", new[] { new HashEntry(0, "{event data}") });
}
}
catch (Exception ex)
{
throw new ConfigurationException($"Redis connection failed to connect to database {redisClient.Value.Configuration}", ex);
}
}
}
}
Loading…
Cancel
Save