1
0
mirror of https://github.com/bitwarden/server synced 2025-12-28 22:23:30 +00:00

write events to table storage

This commit is contained in:
Kyle Spearrin
2017-12-08 16:03:20 -05:00
parent 8626d7e769
commit 83a7c98fae
5 changed files with 78 additions and 15 deletions

View File

@@ -13,6 +13,7 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
@@ -25,7 +26,6 @@
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup>
@@ -78,6 +78,7 @@
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Spatial, Version=5.8.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\System.Spatial.5.8.3\lib\net40\System.Spatial.dll</HintPath>
@@ -111,6 +112,12 @@
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj">
<Project>{3973d21b-a692-4b60-9b70-3631c057423a}</Project>
<Name>Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\packages\Microsoft.Web.WebJobs.Publish.1.1.0\tools\webjobs.targets" Condition="Exists('..\..\packages\Microsoft.Web.WebJobs.Publish.1.1.0\tools\webjobs.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -1,17 +1,63 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Bit.Core.Models.Data;
using Bit.Core.Services;
using Microsoft.Azure.WebJobs;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace Bit.EventsProcessor
{
public class Functions
{
public async static Task ProcessQueueMessageAsync(
[QueueTrigger("event")] string message, TextWriter logger, CancellationToken token)
private static IEventWriteService _eventWriteService;
static Functions()
{
await logger.WriteLineAsync(message);
var storageConnectionString = ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"];
if(storageConnectionString == null || string.IsNullOrWhiteSpace(storageConnectionString.ConnectionString))
{
return;
}
var repo = new Core.Repositories.TableStorage.EventRepository(storageConnectionString.ConnectionString);
_eventWriteService = new RepositoryEventWriteService(repo);
}
public async static Task ProcessQueueMessageAsync([QueueTrigger("event")] string message,
TextWriter logger, CancellationToken token)
{
if(_eventWriteService == null || message == null || message.Length == 0)
{
return;
}
try
{
var jToken = JToken.Parse(message);
if(jToken is JArray)
{
var entities = jToken.ToObject<IList<EventTableEntity>>();
await _eventWriteService.CreateManyAsync(entities);
}
else if(jToken is JObject)
{
var entity = jToken.ToObject<EventTableEntity>();
await _eventWriteService.CreateAsync(entity);
}
}
catch(JsonReaderException)
{
await logger.WriteLineAsync("JsonReaderException: Unable to parse message.");
}
catch(JsonSerializationException)
{
await logger.WriteLineAsync("JsonSerializationException: Unable to serialize token.");
}
}
}
}