1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-04 01:22:50 -05:00

event write services

This commit is contained in:
Kyle Spearrin
2017-12-04 09:58:07 -05:00
parent bcd8a06994
commit 8a88a36140
5 changed files with 101 additions and 10 deletions

View File

@ -0,0 +1,46 @@
using System.Threading.Tasks;
using Bit.Core.Repositories;
using System.Collections.Generic;
using Microsoft.WindowsAzure.Storage.Table;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
using Newtonsoft.Json;
namespace Bit.Core.Services
{
public class AzureQueueEventWriteService : IEventWriteService
{
private readonly CloudQueue _queue;
private readonly GlobalSettings _globalSettings;
private JsonSerializerSettings _jsonSettings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
};
public AzureQueueEventWriteService(
IEventRepository eventRepository,
GlobalSettings globalSettings)
{
var storageAccount = CloudStorageAccount.Parse(globalSettings.Storage.ConnectionString);
var queueClient = storageAccount.CreateCloudQueueClient();
_queue = queueClient.GetQueueReference("event");
_globalSettings = globalSettings;
}
public async Task CreateAsync(ITableEntity entity)
{
var json = JsonConvert.SerializeObject(entity, _jsonSettings);
var message = new CloudQueueMessage(json);
await _queue.AddMessageAsync(message);
}
public async Task CreateManyAsync(IList<ITableEntity> entities)
{
var json = JsonConvert.SerializeObject(entities, _jsonSettings);
var message = new CloudQueueMessage(json);
await _queue.AddMessageAsync(message);
}
}
}