Files
server/src/Core/Services/Implementations/AzureQueueEventWriteService.cs

47 lines
1.5 KiB
C#
Raw Normal View History

2017-12-04 09:58:07 -05:00
using System.Threading.Tasks;
using Bit.Core.Repositories;
using System.Collections.Generic;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Queue;
using Newtonsoft.Json;
using Bit.Core.Models.Data;
2017-12-04 09:58:07 -05:00
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)
{
2017-12-27 22:39:14 -05:00
var storageAccount = CloudStorageAccount.Parse(globalSettings.Events.ConnectionString);
2017-12-04 09:58:07 -05:00
var queueClient = storageAccount.CreateCloudQueueClient();
_queue = queueClient.GetQueueReference("event");
_globalSettings = globalSettings;
}
2017-12-08 23:09:50 -05:00
public async Task CreateAsync(IEvent e)
2017-12-04 09:58:07 -05:00
{
2017-12-08 23:09:50 -05:00
var json = JsonConvert.SerializeObject(e, _jsonSettings);
2017-12-04 09:58:07 -05:00
var message = new CloudQueueMessage(json);
await _queue.AddMessageAsync(message);
}
2017-12-08 23:09:50 -05:00
public async Task CreateManyAsync(IList<IEvent> e)
2017-12-04 09:58:07 -05:00
{
2017-12-08 23:09:50 -05:00
var json = JsonConvert.SerializeObject(e, _jsonSettings);
2017-12-04 09:58:07 -05:00
var message = new CloudQueueMessage(json);
await _queue.AddMessageAsync(message);
}
}
}